@xo-union/util-snippet-generator
Advanced tools
Comparing version
@@ -1,45 +0,34 @@ | ||
'use strict'; | ||
import _Object$keys from "@babel/runtime-corejs3/core-js/object/keys"; | ||
import minifier from "html-minifier"; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
const createSnippetGenerator = (template, defaultVariableMap) => ({ | ||
variables, | ||
minify = false | ||
} = {}) => { | ||
const finalVariables = { ...defaultVariableMap, | ||
...variables | ||
}; | ||
const code = template.replace(/\{\{([A-Z_]+)\}\}/g, (match, variable) => { | ||
const ref = finalVariables[variable]; | ||
var _defineProperty = _interopDefault(require('@babel/runtime/helpers/defineProperty')); | ||
var minifier = _interopDefault(require('html-minifier')); | ||
if (typeof ref === 'undefined') { | ||
throw new Error(`Cannot find ${variable} in given variables: ${_Object$keys(finalVariables)}`); | ||
} | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
return ref; | ||
}); | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
var createSnippetGenerator = function createSnippetGenerator(template, defaultVariableMap) { | ||
return function () { | ||
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}, | ||
variables = _ref.variables, | ||
_ref$minify = _ref.minify, | ||
minify = _ref$minify === void 0 ? false : _ref$minify; | ||
var finalVariables = _objectSpread({}, defaultVariableMap, {}, variables); | ||
var code = template.replace(/\{\{([A-Z_]+)\}\}/g, function (match, variable) { | ||
var ref = finalVariables[variable]; | ||
if (typeof ref === 'undefined') { | ||
throw new Error("Cannot find ".concat(variable, " in given variables: ").concat(Object.keys(finalVariables))); | ||
} | ||
return ref; | ||
if (minify) { | ||
return minifier.minify(code, { | ||
minifyJS: true, | ||
minifyCSS: true, | ||
collapseWhitespace: true, | ||
removeComments: true, | ||
preserveLineBreaks: true | ||
}); | ||
} | ||
if (minify) { | ||
return minifier.minify(code, { | ||
minifyJS: true, | ||
minifyCSS: true, | ||
collapseWhitespace: true, | ||
removeComments: true, | ||
preserveLineBreaks: true | ||
}); | ||
} | ||
return code; | ||
}; | ||
return code; | ||
}; | ||
module.exports = createSnippetGenerator; | ||
export default createSnippetGenerator; |
{ | ||
"name": "@xo-union/util-snippet-generator", | ||
"version": "1.1.1-canary-e301615d.0", | ||
"main": "lib/index.js", | ||
"version": "1.2.0", | ||
"main": "lib/index.cjs.js", | ||
"module": "lib/index.js", | ||
"scripts": { | ||
"build.pkg": "union-packager-build --target node", | ||
"validate.pkg": "union-pkg-validator" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime-corejs3": "^7.10.4", | ||
"html-minifier": "^3.5.15" | ||
}, | ||
"devDependencies": { | ||
"@xo-union/packager": "^4.0.0", | ||
"@xo-union/pkg-validator": "^2.0.0" | ||
}, | ||
"files": [ | ||
@@ -11,7 +24,3 @@ "lib/*" | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.0.0", | ||
"html-minifier": "^3.5.15" | ||
}, | ||
"gitHead": "837995900ed6d8c0202f3094945aaf0100436092" | ||
"gitHead": "243b70fe4cd4f9249e2470c6b11beb784a3c1a6d" | ||
} |
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
12696
1.13%4
33.33%62
77.14%1
-50%2
Infinity%+ Added
+ Added
- Removed
- Removed