summaryrefslogtreecommitdiff
path: root/node_modules/gray-matter/lib/engines.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/gray-matter/lib/engines.js')
-rw-r--r--node_modules/gray-matter/lib/engines.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/node_modules/gray-matter/lib/engines.js b/node_modules/gray-matter/lib/engines.js
new file mode 100644
index 0000000..38f993d
--- /dev/null
+++ b/node_modules/gray-matter/lib/engines.js
@@ -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');
+ }
+};