mirror of
https://github.com/fooflington/selfdefined.git
synced 2025-06-12 21:51:40 +00:00
update
This commit is contained in:
54
node_modules/gray-matter/lib/engines.js
generated
vendored
Normal file
54
node_modules/gray-matter/lib/engines.js
generated
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
'use strict';
|
||||
|
||||
const yaml = require('js-yaml');
|
||||
|
||||
/**
|
||||
* Default engines
|
||||
*/
|
||||
|
||||
const engines = exports = module.exports;
|
||||
|
||||
/**
|
||||
* YAML
|
||||
*/
|
||||
|
||||
engines.yaml = {
|
||||
parse: yaml.safeLoad.bind(yaml),
|
||||
stringify: yaml.safeDump.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) {
|
||||
/* eslint no-eval: 0 */
|
||||
try {
|
||||
if (wrap !== false) {
|
||||
str = '(function() {\nreturn ' + str.trim() + ';\n}());';
|
||||
}
|
||||
return eval(str) || {};
|
||||
} catch (err) {
|
||||
if (wrap !== false && /(unexpected|identifier)/i.test(err.message)) {
|
||||
return parse(str, options, false);
|
||||
}
|
||||
throw new SyntaxError(err);
|
||||
}
|
||||
},
|
||||
stringify: function() {
|
||||
throw new Error('stringifying JavaScript is not supported');
|
||||
}
|
||||
};
|
Reference in New Issue
Block a user