All Projects → dworthen → Js Yaml Front Matter

dworthen / Js Yaml Front Matter

Licence: mit
Parses yaml or json from the beginning of a string or file

Programming Languages

javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to Js Yaml Front Matter

Datafiles
A file-based ORM for Python dataclasses.
Stars: ✭ 113 (-31.52%)
Mutual labels:  json, yaml
Rq
Record Query - A tool for doing record analysis and transformation
Stars: ✭ 1,808 (+995.76%)
Mutual labels:  json, yaml
Just Dashboard
📊 📋 Dashboards using YAML or JSON files
Stars: ✭ 1,511 (+815.76%)
Mutual labels:  json, yaml
Circe Yaml
YAML parser for circe using SnakeYAML
Stars: ✭ 102 (-38.18%)
Mutual labels:  json, yaml
Gelatin
Transform text files to XML, JSON, or YAML
Stars: ✭ 150 (-9.09%)
Mutual labels:  json, yaml
Yq
Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents
Stars: ✭ 1,688 (+923.03%)
Mutual labels:  json, yaml
Oq
A performant, and portable jq wrapper to facilitate the consumption and output of formats other than JSON; using jq filters to transform the data.
Stars: ✭ 132 (-20%)
Mutual labels:  json, yaml
Night Config
Powerful java configuration library for toml, yaml, hocon, json and in-memory configurations
Stars: ✭ 93 (-43.64%)
Mutual labels:  json, yaml
Configurate
A simple configuration library for Java applications providing a node structure, a variety of formats, and tools for transformation
Stars: ✭ 148 (-10.3%)
Mutual labels:  json, yaml
Fig
A minimalist Go configuration library
Stars: ✭ 142 (-13.94%)
Mutual labels:  json, yaml
Kaizen Openapi Editor
Eclipse Editor for the Swagger-OpenAPI Description Language
Stars: ✭ 97 (-41.21%)
Mutual labels:  json, yaml
Feedparser
feedparser gem - (universal) web feed parser and normalizer (XML w/ Atom or RSS, JSON Feed, HTML w/ Microformats e.g. h-entry/h-feed or Feed.HTML, Feed.TXT w/ YAML, JSON or INI & Markdown, etc.)
Stars: ✭ 156 (-5.45%)
Mutual labels:  json, yaml
Swurg
Parse OpenAPI documents into Burp Suite for automating OpenAPI-based APIs security assessments (approved by PortSwigger for inclusion in their official BApp Store).
Stars: ✭ 94 (-43.03%)
Mutual labels:  json, yaml
Prettier
Prettier is an opinionated code formatter.
Stars: ✭ 41,411 (+24997.58%)
Mutual labels:  json, yaml
Swagger Merger
🔗 Merge multiple swagger files into a swagger file, support JSON/YAML.
Stars: ✭ 94 (-43.03%)
Mutual labels:  json, yaml
Config Lint
Command line tool to validate configuration files
Stars: ✭ 118 (-28.48%)
Mutual labels:  json, yaml
Python Training For Network Engineers
Python hands-on training for network engineers. How to automate Junos with Python
Stars: ✭ 92 (-44.24%)
Mutual labels:  json, yaml
Metayaml
A powerful schema validator!
Stars: ✭ 92 (-44.24%)
Mutual labels:  json, yaml
Cfgdiff
diff(1) all your configs
Stars: ✭ 138 (-16.36%)
Mutual labels:  json, yaml
Dhallj
Dhall for Java
Stars: ✭ 154 (-6.67%)
Mutual labels:  json, yaml

Yaml Front Matter

Parses yaml or json at the front of a string. Places the parsed content, plus the rest of the string content, into an object literal.

Online Demo.

Breaking Changes

This readme is for the 4.x release, which introduces breaking changes. View the changelog for more information.

3.x readme

Example

This

---
name: Derek Worthen
age: 127
contact:
  email: [email protected]
  address: some location
pets:
  - cat
  - dog
  - bat
match: !!js/regexp /pattern/gim
run: !!js/function function() { }
---
Some Other content
var fs = require('fs');
var yamlFront = require('yaml-front-matter');

fs.readFile('./some/file.txt', 'utf8', function(fileContents) {
    console.log(yamlFront.loadFront(fileContents));
});

outputs

{ 
    name: 'Derek Worthen',
    age: 127,
    contact: { email: '[email protected]', address: 'some location' },
    pets: [ 'cat', 'dog', 'bat' ],
    match: /pattern/gim,
    run: [Function],
    __content: '\nSome Other Content' 
}

May also use JSON

---
{
    "name": "Derek Worthen",
    "age": "young",
    "anArray": ["one","two"],
    "subObj":{"field1": "one"}
}
---
Some content

NOTE: The --- are required to denote the start and end of front matter. There must be a newline after the opening --- and a newline preceding the closing ---.

Install

npm

$ npm install yaml-front-matter

Use the -g flag if you plan on using the command line tool.

$ npm install yaml-front-matter -g

Node or client with module bundler (webpack or browsify)

var yamlFront = require('yaml-front-matter');

Browser Bundle

The dist/yamlFront.js client script will expose the yaml-front-matter library as a global, yamlFront. The client script for js-yaml is also required. May need to load espirma for some use cases. See js-yaml for more information.

<script src="https://unpkg.com/[email protected]/dist/js-yaml.js"></script>
<script src="yamlFront.js"></script>
<script>
  // parse front matter with yamlFront.loadFront(String);
</script>

Note: yaml-front-matter is delivered as a umd package so it should work within commonjs, amd and browser (as a global) environments.

Running Browser Example

$ npm install --dev && npm start

Then visit localhost:8080.

Building from source

Outputs build files to dist/.

$ npm install --dev && npm run build

Running Tests

npm install --dev && npm test

Command Line

Usage: yaml-front-matter [options] <yaml-front-matter content>

Options:

-h, --help            output usage information
-v, --version         output the version number
-c, --content [name]  set the property name for the files contents [__content]
--pretty              formats json output with spaces. 

Note The cli uses safeLoadFront and therefore will not parse yaml containing regexps, functions or undefined values.

Example

# Piping content from one file, through yaml parser and into another file
cat ./some/file.txt | yaml-front-matter > output.txt

JS-YAML

Yaml front matter wraps js-yaml to support parsing yaml front-matter.

API

loadFront(string, [options])

var input = [
        '---\npost: title one\n',
        'anArray:\n - one\n - two\n',
        'subObject:\n prop1: cool\n prop2: two',
        '\nreg: !!js/regexp /pattern/gim',
        '\nfun: !!js/function function() {  }\n---\n',
        'content\nmore'
    ].join('');

var results = yamlFront.loadFront(input);
console.log(results);

outputs

{ post: 'title one',
  anArray: [ 'one', 'two' ],
  subObject: { obj1: 'cool', obj2: 'two' },
  reg: /pattern/gim,
  fun: [Function],
  __content: '\ncontent\nmore' }

Front-matter is optional.

yamlFront.loadFront('Hello World');
// => { __content: "Hello World!" }

Content is optional

yamlFront.loadFront('');
// => { __content: '' }

safeLoadFront(string, [options])

Same api as loadFront except it does not support regexps, functions or undefined. See js-yaml for more information.

Options

The options object supports the same options available to js-yaml and adds support for an additional key.

  • options.contentKeyName: Specify the object key where to store content not parsed by yaml-front-matter. defaults to __content.
yamlFront.loadFront('Hello World', {
    contentKeyName: 'fileContents' 
});
// => { fileContents: "Hello World" }
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].