@tech_query/node-toolkit
Advanced tools
+3
-0
@@ -8,2 +8,5 @@ { | ||
| "option": { | ||
| "accessor": { | ||
| "access": ["public", "protected"] | ||
| }, | ||
| "test": { | ||
@@ -10,0 +13,0 @@ "source": "./test", |
+42
-11
@@ -6,15 +6,37 @@ "use strict"; | ||
| }); | ||
| var _exportNames = { | ||
| toES_5: true, | ||
| toRegExp: true, | ||
| prettify: true, | ||
| uglify: true, | ||
| cache: true | ||
| }; | ||
| Object.defineProperty(exports, "toRegExp", { | ||
| enumerable: true, | ||
| get: function get() { | ||
| return _language.toRegExp; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "prettify", { | ||
| enumerable: true, | ||
| get: function get() { | ||
| return _language.prettify; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "uglify", { | ||
| enumerable: true, | ||
| get: function get() { | ||
| return _language.uglify; | ||
| } | ||
| }); | ||
| Object.defineProperty(exports, "cache", { | ||
| enumerable: true, | ||
| get: function get() { | ||
| return _language.cache; | ||
| } | ||
| }); | ||
| exports.toES_5 = void 0; | ||
| var _language = require("./language"); | ||
| Object.keys(_language).forEach(function (key) { | ||
| if (key === "default" || key === "__esModule") return; | ||
| Object.defineProperty(exports, key, { | ||
| enumerable: true, | ||
| get: function get() { | ||
| return _language[key]; | ||
| } | ||
| }); | ||
| }); | ||
| var _module = require("./module"); | ||
@@ -24,2 +46,3 @@ | ||
| if (key === "default" || key === "__esModule") return; | ||
| if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
| Object.defineProperty(exports, key, { | ||
@@ -37,2 +60,3 @@ enumerable: true, | ||
| if (key === "default" || key === "__esModule") return; | ||
| if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
| Object.defineProperty(exports, key, { | ||
@@ -50,2 +74,3 @@ enumerable: true, | ||
| if (key === "default" || key === "__esModule") return; | ||
| if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
| Object.defineProperty(exports, key, { | ||
@@ -57,2 +82,8 @@ enumerable: true, | ||
| }); | ||
| }); | ||
| }); | ||
| /** | ||
| * @private | ||
| */ | ||
| var toES_5 = (0, _language.cache)(_language.toES_5); | ||
| exports.toES_5 = toES_5; |
+116
-1
| "use strict"; | ||
| var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
| Object.defineProperty(exports, "__esModule", { | ||
@@ -7,6 +9,19 @@ value: true | ||
| exports.toRegExp = toRegExp; | ||
| exports.prettify = prettify; | ||
| exports.toES_5 = toES_5; | ||
| exports.uglify = uglify; | ||
| exports.cache = cache; | ||
| var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray")); | ||
| var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
| var _core = require("@babel/core"); | ||
| var _prettier = require("prettier"); | ||
| var _uglifyJs = require("uglify-js"); | ||
| var _assert = require("assert"); | ||
| /** | ||
@@ -22,2 +37,16 @@ * @param {string} raw - RegExp literal string | ||
| /** | ||
| * @param {String} source - JS source code | ||
| * | ||
| * @return {String} Prettified JS code | ||
| */ | ||
| function prettify(source) { | ||
| return (0, _prettier.format)(source, { | ||
| parser: 'babylon', | ||
| tabWidth: 4, | ||
| singleQuote: true | ||
| }).trim(); | ||
| } | ||
| /** | ||
| * @param {string} code - ES 6+ source code | ||
@@ -44,3 +73,89 @@ * @param {?string} fileName - Full name of this JS file | ||
| if (!onlyModule) option.presets = ['@babel/preset-env']; | ||
| return (0, _core.transform)(code, option).code.replace(/^(?:'|")use strict(?:'|");\n+/, ''); | ||
| return prettify((0, _core.transform)(code, option).code.replace(/^(?:'|")use strict(?:'|");\n+/, '')); | ||
| } | ||
| /** | ||
| * @param {String} source - JS source code | ||
| * @param {String} filename - Name of this JS source file | ||
| * | ||
| * @return {Object} | ||
| * @property {String} code | ||
| * @property {String} map | ||
| */ | ||
| function uglify(source, filename) { | ||
| var _minify = (0, _uglifyJs.minify)((0, _defineProperty2.default)({}, filename, source), { | ||
| mangle: { | ||
| keep_fnames: true | ||
| }, | ||
| output: { | ||
| comments: 'some' | ||
| }, | ||
| ie8: true, | ||
| sourceMap: { | ||
| filename: filename, | ||
| url: "".concat(filename, ".map") | ||
| }, | ||
| warnings: 'verbose' | ||
| }), | ||
| error = _minify.error, | ||
| code = _minify.code, | ||
| map = _minify.map; | ||
| if (error) throw error; | ||
| return { | ||
| code: code, | ||
| map: map | ||
| }; | ||
| } | ||
| /** | ||
| * @param {Function} func - Original function | ||
| * | ||
| * @return {Function} Wrapped function with result cache | ||
| */ | ||
| function cache(func) { | ||
| var result = new Map(); | ||
| return function () { | ||
| for (var _len = arguments.length, parameter = new Array(_len), _key = 0; _key < _len; _key++) { | ||
| parameter[_key] = arguments[_key]; | ||
| } | ||
| var _iteratorNormalCompletion = true; | ||
| var _didIteratorError = false; | ||
| var _iteratorError = undefined; | ||
| try { | ||
| for (var _iterator = result[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
| var _step$value = (0, _slicedToArray2.default)(_step.value, 2), | ||
| input = _step$value[0], | ||
| _output = _step$value[1]; | ||
| try { | ||
| (0, _assert.deepStrictEqual)(input, parameter); | ||
| return _output; | ||
| } catch (error) { | ||
| /**/ | ||
| } | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally { | ||
| try { | ||
| if (!_iteratorNormalCompletion && _iterator.return != null) { | ||
| _iterator.return(); | ||
| } | ||
| } finally { | ||
| if (_didIteratorError) { | ||
| throw _iteratorError; | ||
| } | ||
| } | ||
| } | ||
| var output = func.apply(this, parameter); | ||
| result.set(parameter, output); | ||
| return output; | ||
| }; | ||
| } |
+19
-12
| { | ||
| "name": "@tech_query/node-toolkit", | ||
| "version": "0.6.2", | ||
| "version": "0.7.1", | ||
| "description": "Toolkit for Node.JS packages", | ||
@@ -44,16 +44,21 @@ "keywords": [ | ||
| "dependencies": { | ||
| "@babel/core": "^7.1.0", | ||
| "@babel/core": "^7.1.2", | ||
| "@babel/plugin-transform-modules-commonjs": "^7.1.0", | ||
| "@babel/polyfill": "^7.0.0", | ||
| "@babel/preset-env": "^7.1.0", | ||
| "@babel/runtime": "^7.0.0", | ||
| "file-type": "^9.0.0", | ||
| "mime": "^2.3.1" | ||
| "@babel/runtime": "^7.1.2", | ||
| "file-type": "^10.0.0", | ||
| "mime": "^2.3.1", | ||
| "prettier": "^1.14.3", | ||
| "uglify-js": "^3.4.9" | ||
| }, | ||
| "peerDependencies": { | ||
| "@babel/polyfill": "^7.0.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@babel/cli": "^7.1.0", | ||
| "@babel/cli": "^7.1.2", | ||
| "@babel/plugin-transform-runtime": "^7.1.0", | ||
| "@babel/polyfill": "^7.0.0", | ||
| "@babel/register": "^7.0.0", | ||
| "babel-eslint": "^9.0.0", | ||
| "babel-plugin-dynamic-import-node": "^2.1.0", | ||
| "babel-eslint": "^10.0.1", | ||
| "babel-plugin-dynamic-import-node": "^2.2.0", | ||
| "esdoc": "^1.1.0", | ||
@@ -63,8 +68,10 @@ "esdoc-ecmascript-proposal-plugin": "^1.0.0", | ||
| "esdoc-standard-plugin": "^1.0.0", | ||
| "eslint": "^5.6.0", | ||
| "husky": "^1.0.1", | ||
| "eslint": "^5.6.1", | ||
| "husky": "^1.1.1", | ||
| "mocha": "^5.2.0", | ||
| "opn-cli": "^3.1.0", | ||
| "should": "^13.2.3", | ||
| "should-http": "^0.1.1" | ||
| "should-http": "^0.1.1", | ||
| "should-sinon": "0.0.6", | ||
| "sinon": "^6.3.5" | ||
| }, | ||
@@ -71,0 +78,0 @@ "babel": { |
+6
-0
@@ -16,1 +16,7 @@ # Node.JS toolkit | ||
| - [API document](https://techquery.github.io/node-toolkit/identifiers.html) | ||
| ## Typical cases | ||
| https://www.npmjs.com/package/@tech_query/node-toolkit?activeTab=dependents |
+8
-1
@@ -1,3 +0,10 @@ | ||
| export * from './language'; | ||
| export { toRegExp, prettify, uglify, cache } from './language'; | ||
| import { toES_5 as compile, cache } from './language'; | ||
| /** | ||
| * @private | ||
| */ | ||
| export const toES_5 = cache( compile ); | ||
| export * from './module'; | ||
@@ -4,0 +11,0 @@ |
+83
-2
| import { transform } from '@babel/core'; | ||
| import { format } from 'prettier'; | ||
| import { minify } from 'uglify-js'; | ||
| import { deepStrictEqual } from 'assert'; | ||
| /** | ||
@@ -18,2 +24,17 @@ * @param {string} raw - RegExp literal string | ||
| /** | ||
| * @param {String} source - JS source code | ||
| * | ||
| * @return {String} Prettified JS code | ||
| */ | ||
| export function prettify(source) { | ||
| return format(source, { | ||
| parser: 'babylon', | ||
| tabWidth: 4, | ||
| singleQuote: true | ||
| }).trim(); | ||
| } | ||
| /** | ||
| * @param {string} code - ES 6+ source code | ||
@@ -46,5 +67,65 @@ * @param {?string} fileName - Full name of this JS file | ||
| return transform(code, option).code.replace( | ||
| /^(?:'|")use strict(?:'|");\n+/, '' | ||
| return prettify( | ||
| transform(code, option).code.replace( | ||
| /^(?:'|")use strict(?:'|");\n+/, '' | ||
| ) | ||
| ); | ||
| } | ||
| /** | ||
| * @param {String} source - JS source code | ||
| * @param {String} filename - Name of this JS source file | ||
| * | ||
| * @return {Object} | ||
| * @property {String} code | ||
| * @property {String} map | ||
| */ | ||
| export function uglify(source, filename) { | ||
| const {error, code, map} = minify({ | ||
| [filename]: source | ||
| }, { | ||
| mangle: { | ||
| keep_fnames: true | ||
| }, | ||
| output: { | ||
| comments: 'some' | ||
| }, | ||
| ie8: true, | ||
| sourceMap: { | ||
| filename, url: `${filename}.map` | ||
| }, | ||
| warnings: 'verbose' | ||
| }); | ||
| if ( error ) throw error; | ||
| return {code, map}; | ||
| } | ||
| /** | ||
| * @param {Function} func - Original function | ||
| * | ||
| * @return {Function} Wrapped function with result cache | ||
| */ | ||
| export function cache(func) { | ||
| const result = new Map(); | ||
| return function (...parameter) { | ||
| for (let [input, output] of result) try { | ||
| deepStrictEqual(input, parameter); return output; | ||
| } catch (error) {/**/} | ||
| const output = func.apply(this, parameter); | ||
| result.set(parameter, output); | ||
| return output; | ||
| }; | ||
| } |
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
35202
18.71%825
31.37%22
37.5%9
28.57%18
20%+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
Updated
Updated
Updated