| /** | ||
| * 将 JSON 第一级字段导出为变量 | ||
| * | ||
| * @param {string} content 文本内容 | ||
| * @param {Object} attrs 属性 | ||
| * @param {Object} scope 作用域 | ||
| * @param {Function} scope.execExport 导出数据 | ||
| * @example extract base | ||
| ```input | ||
| <~jdists encoding="extract"~> | ||
| { | ||
| "name": "extract", | ||
| "version": "0.0.1", | ||
| "private": true, | ||
| "author": { | ||
| "name": "zswang", | ||
| "url": "http://weibo.com/zswang" | ||
| } | ||
| } | ||
| <~/jdists~> | ||
| <~jdists import="#name" /~> | ||
| <~jdists import="#version" /~> | ||
| <~jdists import="#private" /~> | ||
| <~jdists import="#author" /~> | ||
| ``` | ||
| ```output | ||
| extract | ||
| 0.0.1 | ||
| true | ||
| {"name":"zswang","url":"http://weibo.com/zswang"} | ||
| ``` | ||
| */ | ||
| module.exports = function processor(content, attrs, scope) { | ||
| if (!content) { | ||
| return ''; | ||
| } | ||
| var data = new Function( | ||
| 'return (' + content + ');' | ||
| )(); | ||
| Object.keys(data).forEach(function (key) { | ||
| scope.execExport('#' + key, data[key]); | ||
| }); | ||
| return ''; | ||
| }; |
+3
-2
@@ -7,4 +7,4 @@ /** | ||
| * zswang (http://weibo.com/zswang) | ||
| * @version 2.0.0 | ||
| * @date 2016-11-14 | ||
| * @version 2.0.1 | ||
| * @date 2016-11-25 | ||
| */ | ||
@@ -17,2 +17,3 @@ var fs = require('fs'); | ||
| "ejs": require('../processor/processor-ejs'), | ||
| "extract": require('../processor/processor-extract'), | ||
| "fndep": require('../processor/processor-fndep'), | ||
@@ -19,0 +20,0 @@ "glob": require('../processor/processor-glob'), |
+7
-2
@@ -7,4 +7,4 @@ /** | ||
| * zswang (http://weibo.com/zswang) | ||
| * @version 2.0.0 | ||
| * @date 2016-11-14 | ||
| * @version 2.0.1 | ||
| * @date 2016-11-25 | ||
| */ | ||
@@ -723,2 +723,7 @@ var colors = require('colors'); | ||
| } | ||
| if (typeof value === 'object') { | ||
| value = JSON.stringify(value); | ||
| } else { | ||
| value = String(value); | ||
| } | ||
| node.content = value; | ||
@@ -725,0 +730,0 @@ if (node.attrs.export && node.attrs.export !== '&') { |
+2
-2
| { | ||
| "name": "jdists", | ||
| "version": "2.0.0", | ||
| "version": "2.0.1", | ||
| "description": "Code block processing tools", | ||
@@ -65,3 +65,3 @@ "main": "lib/jdists.js", | ||
| "mocha": "mocha", | ||
| "lint": "jshint src/*.js src/**/*.js processor/*.js processor-extend/*.js" | ||
| "lint": "jshint src/*.js processor/*.js processor-extend/*.js" | ||
| }, | ||
@@ -68,0 +68,0 @@ "files": [ |
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
76262
1.78%49
2.08%2035
2.47%6
-14.29%13
8.33%