Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jsantell/node-json-front-matter
Extract JSON front matter from strings and files
https://github.com/jsantell/node-json-front-matter
Last synced: 3 months ago
JSON representation
Extract JSON front matter from strings and files
- Host: GitHub
- URL: https://github.com/jsantell/node-json-front-matter
- Owner: jsantell
- License: mit
- Created: 2012-07-01T16:58:04.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2015-01-24T12:26:57.000Z (about 10 years ago)
- Last Synced: 2024-11-01T00:51:28.883Z (3 months ago)
- Language: JavaScript
- Homepage: https://npmjs.org/package/json-front-matter
- Size: 166 KB
- Stars: 20
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
json-front-matter
======[![Build Status](http://img.shields.io/travis/jsantell/node-json-front-matter.svg?style=flat-square)](https://travis-ci.org/jsantell/node-json-front-matter)
[![Build Status](http://img.shields.io/npm/v/json-front-matter.svg?style=flat-square)](https://www.npmjs.org/package/json-front-matter)Extract JSON front matter from strings and files in the style of [Jekyll's YAML Front Matter](https://github.com/mojombo/jekyll/wiki/YAML-Front-Matter).
### Installing
* `npm install json-front-matter`
### Methods
* `parse( s )` Parses string `s`, returning an object with properties `attributes`, containing the JSON front matter, and `body` containing the rest.
* `parseFile( path, callback( err, data ))` Parses file at `path`, calling the callback upon completion with `data` object containing `attributes` and `body`, like the string parse method.### Usage
```javascript
var fm = require('json-front-matter');var string = '{{{ "title" : "some title", "array" : [ 1, 2, 3 ] }}} bodybodybody';
var out = fm.parse( string );console.log( out.body ) // 'bodybodybody'
console.log( out.attributes.title ) // 'some title'
console.log( out.attributes.array ) // [ 1, 2, 3 ]
```### File Example
See [./tests/data/test.md](https://raw.github.com/jsantell/node-json-front-matter/master/tests/data/test.md) for example of JSON Front Matter in a markdown file. The outer JSON is encapsulated via triple curly brackets. `{{{ "tags" : [ 'rock', 'paper', 'scissors' ] }}}`
### Testing
Run `node tests/runTests.js` from project root -- testing uses `nodeunit`
### License
MIT License, Copyright (c) 2012 Jordan Santell