gray-matter
Version:
A simple to use YAML, JSON or Coffee Front-Matter parsing and extraction library, with options to set custom delimiters.
33 lines (25 loc) • 599 B
JavaScript
/**
* Gray Matter
* Copyright (c) 2014 Jon Schlinkert, Brian Woodward, contributors.
* Licensed under the MIT license.
*/
;
// node_modules
var YAML = require('js-yaml');
var coffee = require('coffee-script');
// The module to export
var parse = module.exports = {};
parse.yaml = function(src) {
return YAML.load(src);
};
parse.json = function(src) {
return JSON.parse(src);
};
parse.coffee = function(src, options) {
options = options || {};
try {
return coffee['eval'](src, options);
} catch (e) {
console.warn('Could not parse coffee-script:', e);
}
};