@11ty/gray-matter
Version:
Parse front-matter from a string or file. Fast, reliable and easy to use. Parses YAML front matter by default, but also has support for YAML, JSON, TOML Front-Matter, with options to set custom delimiters. Used by metalsmith, assemble, verb and many other
44 lines (34 loc) • 822 B
JavaScript
;
const yaml = require('js-yaml');
/**
* Default engines
*/
const engines = exports = module.exports;
/**
* YAML
*/
engines.yaml = {
parse: yaml.load.bind(yaml),
stringify: yaml.dump.bind(yaml)
};
/**
* JSON
*/
engines.json = {
parse: JSON.parse.bind(JSON),
stringify: function(obj, options) {
const opts = Object.assign({replacer: null, space: 2}, options);
return JSON.stringify(obj, opts.replacer, opts.space);
}
};
/**
* JavaScript
*/
engines.javascript = {
parse: function parse(str, options, wrap) {
throw new Error('Parsing JavaScript in front matter is no longer supported internally in `@11ty/gray-matter`. Support is added upstream in `@11ty/eleventy`.');
},
stringify: function() {
throw new Error('stringifying JavaScript is not supported');
}
};