Break up JSON from content in a JSON-first file
npm install json-content-demuxBreak up JSON from content in a JSON-first file
npm install json-content-demux``javascript
// muxed.md
{
"title": "This is some muxed JSON and content",
"options": {
"Hello": "World!"
}
}
Here is some content
Om nom nom
// app.js
var jsonContentDemux = require('json-content-demux'),
muxedContent = fs.readFileSync('muxed.md', 'utf8'),
demuxedObj = jsonContentDemux(muxedStr);
demuxedObj.json; // {"title":"This is some muxed...","options"}
demuxedObj.content; // "Here is some content\nOm nom nom"
`
js
/**
* @param {String} muxStr Muxed content to break up
* @returns {Object} retObj
* @returns {Object} retObj.json JSON found at the head of the content
* @returns {String} retObj.content Content found in the body
*/
`At some point, the scope may increasee to encapsulate any markup language as well as multiple sets of delimited items.
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint via npm run lint and test via npm test`.[twolfson-projects]: http://twolfson.com/projects
[twolfson-support-me]: http://twolfson.com/support-me