Neolithic Psychedelic Mushrooms
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    json-front-matterpublic

    json-front-matter

    Build Status Build Status

    Extract JSON front matter from strings and files in the style of Jekyll's 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

    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 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

    install

    npm i json-front-matter

    Downloadsweekly downloads

    126

    version

    1.0.0

    license

    MIT

    repository

    githubgithub

    last publish

    collaborators

    • avatar