@dmail/uneval
Advanced tools
Comparing version 4.8.0 to 4.9.0
@@ -1,350 +0,591 @@ | ||
System.register([], function (e, n) { | ||
"use strict"; | ||
System.register([], function (exports, module) { | ||
'use strict'; | ||
return { | ||
execute: function () { | ||
function n(e) { | ||
return (n = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (e) { | ||
return typeof e; | ||
} : function (e) { | ||
return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e; | ||
})(e); | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
} | ||
function t(e, n, t) { | ||
return n in e ? Object.defineProperty(e, n, { | ||
value: t, | ||
enumerable: !0, | ||
configurable: !0, | ||
writable: !0 | ||
}) : e[n] = t, e; | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function r(e) { | ||
for (var n = 1; n < arguments.length; n++) { | ||
var r = null != arguments[n] ? arguments[n] : {}, | ||
o = Object.keys(r); | ||
"function" == typeof Object.getOwnPropertySymbols && (o = o.concat(Object.getOwnPropertySymbols(r).filter(function (e) { | ||
return Object.getOwnPropertyDescriptor(r, e).enumerable; | ||
}))), o.forEach(function (n) { | ||
t(e, n, r[n]); | ||
function _objectSpread(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
var ownKeys = Object.keys(source); | ||
if (typeof Object.getOwnPropertySymbols === 'function') { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
} | ||
ownKeys.forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} | ||
return e; | ||
return target; | ||
} | ||
var o = Object.prototype.toString, | ||
c = function (e) { | ||
if ("object" === n(e) && null === Object.getPrototypeOf(e)) return "Object"; | ||
var t = o.call(e).slice("[object ".length, -1); | ||
var valueToType = function valueToType(value) { | ||
var primitiveType = valueToPrimitiveType(value); | ||
if ("Object" === t) { | ||
var r = e.constructor.name; | ||
if ("Object" !== r) return r; | ||
if (primitiveType === "function") { | ||
return { | ||
compositeType: "Function" | ||
}; | ||
} | ||
return t; | ||
}, | ||
i = function (e) { | ||
return null === e ? "null" : void 0 === e ? "undefined" : n(e); | ||
}, | ||
a = function (e, n) { | ||
var t = n.depth, | ||
r = n.indentUsingTab, | ||
o = n.indentSize; | ||
return "".concat(u({ | ||
count: t + 1, | ||
useTabs: r, | ||
size: o | ||
})).concat(e); | ||
}, | ||
u = function (e) { | ||
var n = e.count, | ||
t = e.useTabs, | ||
r = e.size; | ||
return t ? "\n" + "\t".repeat(n) : "\n" + " ".repeat(n * r); | ||
}, | ||
s = function (e, n) { | ||
var t = n.depth, | ||
r = n.indentUsingTab, | ||
o = n.indentSize; | ||
return "".concat(a(e, { | ||
depth: t, | ||
indentUsingTab: r, | ||
indentSize: o | ||
})).concat(function (e) { | ||
var n = e.depth, | ||
t = e.indentUsingTab, | ||
r = e.indentSize; | ||
return u({ | ||
count: n, | ||
useTabs: t, | ||
size: r | ||
}); | ||
}({ | ||
depth: t, | ||
indentUsingTab: r, | ||
indentSize: o | ||
if (primitiveType === "object") { | ||
var compositeType = valueToCompositeType(value); | ||
return { | ||
compositeType: compositeType | ||
}; | ||
} | ||
return { | ||
primitiveType: primitiveType | ||
}; | ||
}; | ||
var toString = Object.prototype.toString; | ||
var valueToCompositeType = function valueToCompositeType(object) { | ||
if (_typeof(object) === "object" && Object.getPrototypeOf(object) === null) return "Object"; | ||
var toStringResult = toString.call(object); // returns format is '[object ${tagName}]'; | ||
// and we want ${tagName} | ||
var tagName = toStringResult.slice("[object ".length, -1); | ||
if (tagName === "Object") { | ||
var objectConstructorName = object.constructor.name; | ||
if (objectConstructorName !== "Object") { | ||
return objectConstructorName; | ||
} | ||
} | ||
return tagName; | ||
}; | ||
var valueToPrimitiveType = function valueToPrimitiveType(value) { | ||
if (value === null) { | ||
return "null"; | ||
} | ||
if (value === undefined) { | ||
return "undefined"; | ||
} | ||
return _typeof(value); | ||
}; // const type = getCompositeType(value) | ||
// if (type in mapping) { | ||
// return mapping[type](value, options) | ||
// } | ||
// return unevalConstructor(`${type}(${unevalObject(value, options)})`, { | ||
// ...options, | ||
// parenthesis: false, | ||
// }) | ||
var unevalBoolean = function unevalBoolean(value) { | ||
return value.toString(); | ||
}; | ||
var unevalNull = function unevalNull() { | ||
return "null"; | ||
}; | ||
var unevalNumber = function unevalNumber(value) { | ||
return Object.is(value, -0) ? "-0" : value.toString(); | ||
}; // https://github.com/joliss/js-string-escape/blob/master/index.js | ||
// http://javascript.crockford.com/remedial.html | ||
var quote = function quote(value) { | ||
var string = String(value); | ||
var i = 0; | ||
var j = string.length; | ||
var escapedString = ""; | ||
while (i < j) { | ||
var char = string[i]; | ||
var escapedChar = void 0; | ||
if (char === '"' || char === "'" || char === "\\") { | ||
escapedChar = "\\".concat(char); | ||
} else if (char === "\n") { | ||
escapedChar = "\\n"; | ||
} else if (char === "\r") { | ||
escapedChar = "\\r"; | ||
} else if (char === "\u2028") { | ||
escapedChar = "\\u2028"; | ||
} else if (char === "\u2029") { | ||
escapedChar = "\\u2029"; | ||
} else { | ||
escapedChar = char; | ||
} | ||
escapedString += escapedChar; | ||
i++; | ||
} | ||
return escapedString; | ||
}; | ||
var preNewLineAndIndentation = function preNewLineAndIndentation(value, _ref) { | ||
var depth = _ref.depth, | ||
indentUsingTab = _ref.indentUsingTab, | ||
indentSize = _ref.indentSize; | ||
return "".concat(newLineAndIndent({ | ||
count: depth + 1, | ||
useTabs: indentUsingTab, | ||
size: indentSize | ||
})).concat(value); | ||
}; | ||
var postNewLineAndIndentation = function postNewLineAndIndentation(_ref2) { | ||
var depth = _ref2.depth, | ||
indentUsingTab = _ref2.indentUsingTab, | ||
indentSize = _ref2.indentSize; | ||
return newLineAndIndent({ | ||
count: depth, | ||
useTabs: indentUsingTab, | ||
size: indentSize | ||
}); | ||
}; | ||
var newLineAndIndent = function newLineAndIndent(_ref3) { | ||
var count = _ref3.count, | ||
useTabs = _ref3.useTabs, | ||
size = _ref3.size; | ||
if (useTabs) { | ||
// eslint-disable-next-line prefer-template | ||
return "\n" + "\t".repeat(count); | ||
} // eslint-disable-next-line prefer-template | ||
return "\n" + " ".repeat(count * size); | ||
}; | ||
var wrapNewLineAndIndentation = function wrapNewLineAndIndentation(value, _ref4) { | ||
var depth = _ref4.depth, | ||
indentUsingTab = _ref4.indentUsingTab, | ||
indentSize = _ref4.indentSize; | ||
return "".concat(preNewLineAndIndentation(value, { | ||
depth: depth, | ||
indentUsingTab: indentUsingTab, | ||
indentSize: indentSize | ||
})).concat(postNewLineAndIndentation({ | ||
depth: depth, | ||
indentUsingTab: indentUsingTab, | ||
indentSize: indentSize | ||
})); | ||
}, | ||
d = { | ||
boolean: function (e) { | ||
return e.toString(); | ||
}, | ||
null: function () { | ||
return "null"; | ||
}, | ||
number: function (e) { | ||
return Object.is(e, -0) ? "-0" : e.toString(); | ||
}, | ||
string: function (e, n) { | ||
var t = n.singleQuote, | ||
r = function (e) { | ||
for (var n = String(e), t = 0, r = n.length, o = ""; t < r;) { | ||
var c = n[t]; | ||
o += '"' === c || "'" === c || "\\" === c ? "\\".concat(c) : "\n" === c ? "\\n" : "\r" === c ? "\\r" : "\u2028" === c ? "\\u2028" : "\u2029" === c ? "\\u2029" : c, t++; | ||
}; | ||
var unevalString = function unevalString(value, _ref) { | ||
var singleQuote = _ref.singleQuote; | ||
var quotedValue = quote(value); | ||
return singleQuote ? "'".concat(quotedValue, "'") : "\"".concat(quotedValue, "\""); | ||
}; | ||
var unevalSymbol = function unevalSymbol(value, _ref) { | ||
var nestedUneval = _ref.nestedUneval, | ||
parenthesis = _ref.parenthesis; | ||
var toStringResult = value.toString(); | ||
var openingParenthesisIndex = toStringResult.indexOf("("); | ||
var closingParenthesisIndex = toStringResult.indexOf(")"); | ||
var symbolDescription = toStringResult.slice(openingParenthesisIndex + 1, closingParenthesisIndex); | ||
var symbolDescriptionSource = symbolDescription ? nestedUneval(symbolDescription) : ""; | ||
var symbolSource = "Symbol(".concat(symbolDescriptionSource, ")"); | ||
if (parenthesis) { | ||
return "".concat(symbolSource); | ||
} | ||
return symbolSource; | ||
}; | ||
var unevalUndefined = function unevalUndefined() { | ||
return "undefined"; | ||
}; | ||
var primitiveMap = { | ||
boolean: unevalBoolean, | ||
null: unevalNull, | ||
number: unevalNumber, | ||
string: unevalString, | ||
symbol: unevalSymbol, | ||
undefined: unevalUndefined | ||
}; | ||
var unevalConstructor = function unevalConstructor(value, _ref) { | ||
var parenthesis = _ref.parenthesis, | ||
useNew = _ref.useNew; | ||
var formattedString = value; | ||
if (parenthesis) { | ||
formattedString = "(".concat(value, ")"); | ||
} | ||
if (useNew) { | ||
formattedString = "new ".concat(formattedString); | ||
} | ||
return formattedString; | ||
}; | ||
var unevalArray = function unevalArray(value, _ref) { | ||
var _ref$seen = _ref.seen, | ||
seen = _ref$seen === void 0 ? [] : _ref$seen, | ||
nestedUneval = _ref.nestedUneval, | ||
compact = _ref.compact, | ||
depth = _ref.depth, | ||
indentUsingTab = _ref.indentUsingTab, | ||
indentSize = _ref.indentSize, | ||
parenthesis = _ref.parenthesis, | ||
useNew = _ref.useNew; | ||
if (seen.indexOf(value) > -1) { | ||
return "Symbol.for('circular')"; | ||
} | ||
seen.push(value); | ||
var valuesSource = ""; | ||
var i = 0; | ||
var j = value.length; | ||
while (i < j) { | ||
var valueSource = value.hasOwnProperty(i) ? nestedUneval(value[i], { | ||
seen: seen | ||
}) : ""; | ||
if (compact) { | ||
if (i === 0) { | ||
valuesSource += valueSource; | ||
} else if (valueSource) { | ||
valuesSource += ", ".concat(valueSource); | ||
} else { | ||
valuesSource += ","; | ||
} | ||
} else if (i === 0) { | ||
valuesSource += valueSource; | ||
} else { | ||
valuesSource += ",".concat(preNewLineAndIndentation(valueSource, { | ||
depth: depth, | ||
indentUsingTab: indentUsingTab, | ||
indentSize: indentSize | ||
})); | ||
} | ||
return o; | ||
}(e); | ||
i++; | ||
} | ||
return t ? "'".concat(r, "'") : '"'.concat(r, '"'); | ||
}, | ||
symbol: function (e, n) { | ||
var t = n.nestedUneval, | ||
r = n.parenthesis, | ||
o = e.toString(), | ||
c = o.indexOf("("), | ||
i = o.indexOf(")"), | ||
a = o.slice(c + 1, i), | ||
u = a ? t(a) : "", | ||
s = "Symbol(".concat(u, ")"); | ||
return r ? "".concat(s) : s; | ||
}, | ||
undefined: function () { | ||
return "undefined"; | ||
var arraySource; | ||
if (valuesSource.length) { | ||
if (compact) { | ||
arraySource = "".concat(valuesSource); | ||
} else { | ||
arraySource = wrapNewLineAndIndentation(valuesSource, { | ||
depth: depth, | ||
indentUsingTab: indentUsingTab, | ||
indentSize: indentSize | ||
}); | ||
} | ||
} else { | ||
arraySource = ""; | ||
} | ||
}, | ||
p = function (e, n) { | ||
var t = n.parenthesis, | ||
r = n.useNew, | ||
o = e; | ||
return t && (o = "(".concat(e, ")")), r && (o = "new ".concat(o)), o; | ||
}, | ||
f = function (e, n) { | ||
var t = n.nestedUneval, | ||
r = n.seen, | ||
o = void 0 === r ? [] : r, | ||
c = n.compact, | ||
i = n.depth, | ||
u = n.indentUsingTab, | ||
d = n.indentSize, | ||
f = n.objectConstructor, | ||
l = n.parenthesis, | ||
v = n.useNew; | ||
if (o.indexOf(e) > -1) return "Symbol.for('circular')"; | ||
o.push(e); | ||
for (var b, h = "", g = Object.getOwnPropertyNames(e), y = 0, m = g.length; y < m;) { | ||
var S = g[y], | ||
O = parseInt(S, 10), | ||
w = t(Number.isInteger(O) ? O : S), | ||
U = t(e[S], { | ||
seen: o | ||
arraySource = "[".concat(arraySource, "]"); | ||
return unevalConstructor(arraySource, { | ||
parenthesis: parenthesis, | ||
useNew: useNew | ||
}); | ||
}; | ||
var unevalObject = function unevalObject(value, _ref) { | ||
var nestedUneval = _ref.nestedUneval, | ||
_ref$seen = _ref.seen, | ||
seen = _ref$seen === void 0 ? [] : _ref$seen, | ||
compact = _ref.compact, | ||
depth = _ref.depth, | ||
indentUsingTab = _ref.indentUsingTab, | ||
indentSize = _ref.indentSize, | ||
objectConstructor = _ref.objectConstructor, | ||
parenthesis = _ref.parenthesis, | ||
useNew = _ref.useNew; | ||
if (seen.indexOf(value) > -1) { | ||
return "Symbol.for('circular')"; | ||
} | ||
seen.push(value); | ||
var propertiesSource = ""; | ||
var propertyNames = Object.getOwnPropertyNames(value); | ||
var i = 0; | ||
var j = propertyNames.length; | ||
while (i < j) { | ||
var propertyName = propertyNames[i]; | ||
var propertyNameAsNumber = parseInt(propertyName, 10); | ||
var propertyNameSource = nestedUneval(Number.isInteger(propertyNameAsNumber) ? propertyNameAsNumber : propertyName); | ||
var propertyValueSource = nestedUneval(value[propertyName], { | ||
seen: seen | ||
}); | ||
h += c ? 0 === y ? "".concat(w, ": ").concat(U) : ", ".concat(w, ": ").concat(U) : 0 === y ? "".concat(w, ": ").concat(U) : ",".concat(a("".concat(w, ": ").concat(U), { | ||
depth: i, | ||
indentUsingTab: u, | ||
indentSize: d | ||
})), y++; | ||
if (compact) { | ||
if (i === 0) { | ||
propertiesSource += "".concat(propertyNameSource, ": ").concat(propertyValueSource); | ||
} else { | ||
propertiesSource += ", ".concat(propertyNameSource, ": ").concat(propertyValueSource); | ||
} | ||
} else if (i === 0) { | ||
propertiesSource += "".concat(propertyNameSource, ": ").concat(propertyValueSource); | ||
} else { | ||
propertiesSource += ",".concat(preNewLineAndIndentation("".concat(propertyNameSource, ": ").concat(propertyValueSource), { | ||
depth: depth, | ||
indentUsingTab: indentUsingTab, | ||
indentSize: indentSize | ||
})); | ||
} | ||
i++; | ||
} | ||
return b = h.length ? "".concat(c ? h : s(h, { | ||
depth: i, | ||
indentUsingTab: u, | ||
indentSize: d | ||
})) : "", b = f ? "Object({".concat(b, "})") : "{".concat(b, "}"), p(b, { | ||
parenthesis: l, | ||
useNew: v | ||
var objectSource; | ||
if (propertiesSource.length) { | ||
if (compact) { | ||
objectSource = "".concat(propertiesSource); | ||
} else { | ||
objectSource = "".concat(wrapNewLineAndIndentation(propertiesSource, { | ||
depth: depth, | ||
indentUsingTab: indentUsingTab, | ||
indentSize: indentSize | ||
})); | ||
} | ||
} else { | ||
objectSource = ""; | ||
} | ||
if (objectConstructor) { | ||
objectSource = "Object({".concat(objectSource, "})"); | ||
} else { | ||
objectSource = "{".concat(objectSource, "}"); | ||
} | ||
return unevalConstructor(objectSource, { | ||
parenthesis: parenthesis, | ||
useNew: useNew | ||
}); | ||
}, | ||
l = function (e) { | ||
var n = e.error, | ||
t = e.errorSource, | ||
r = e.nestedUneval, | ||
o = Object.getOwnPropertyNames(n).filter(function (e) { | ||
return "message" !== e; | ||
}).map(function (e) { | ||
var t = Object.getOwnPropertyDescriptor(n, e); | ||
return "Object.defineProperty(error, ".concat(r(e), ", ").concat(r(t), ")"); | ||
}; | ||
var unevalFunction = function unevalFunction(value, _ref) { | ||
var showFunctionBody = _ref.showFunctionBody, | ||
parenthesis = _ref.parenthesis, | ||
depth = _ref.depth; | ||
var functionSource; | ||
if (showFunctionBody) { | ||
functionSource = value.toString(); | ||
} else { | ||
var isArrowFunction = value.prototype === undefined; | ||
var head = isArrowFunction ? "() =>" : "function ".concat(depth === 0 ? value.name : "", "()"); | ||
functionSource = "".concat(head, " {/* hidden */}"); | ||
} | ||
if (parenthesis) { | ||
return "(".concat(functionSource, ")"); | ||
} | ||
return functionSource; | ||
}; | ||
var unevalDate = function unevalDate(value, _ref) { | ||
var nestedUneval = _ref.nestedUneval, | ||
useNew = _ref.useNew, | ||
parenthesis = _ref.parenthesis; | ||
var dateSource = nestedUneval(value.valueOf()); | ||
return unevalConstructor("Date(".concat(dateSource, ")"), { | ||
useNew: useNew, | ||
parenthesis: parenthesis | ||
}); | ||
return "(function (error) {\n ".concat(o.join("\n "), "\n return error\n})(").concat(t, ")"); | ||
}, | ||
v = function (e) { | ||
var n = e.name; | ||
return b.includes(n) ? n : "Error"; | ||
}, | ||
b = ["EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError"], | ||
h = { | ||
Array: function (e, n) { | ||
var t = n.seen, | ||
r = void 0 === t ? [] : t, | ||
o = n.nestedUneval, | ||
c = n.compact, | ||
i = n.depth, | ||
u = n.indentUsingTab, | ||
d = n.indentSize, | ||
f = n.parenthesis, | ||
l = n.useNew; | ||
if (r.indexOf(e) > -1) return "Symbol.for('circular')"; | ||
r.push(e); | ||
}; | ||
for (var v, b = "", h = 0, g = e.length; h < g;) { | ||
var y = e.hasOwnProperty(h) ? o(e[h], { | ||
seen: r | ||
}) : ""; | ||
b += c ? 0 === h ? y : y ? ", ".concat(y) : "," : 0 === h ? y : ",".concat(a(y, { | ||
depth: i, | ||
indentUsingTab: u, | ||
indentSize: d | ||
})), h++; | ||
} | ||
var unevalNumberObject = function unevalNumberObject(value, _ref) { | ||
var nestedUneval = _ref.nestedUneval, | ||
useNew = _ref.useNew, | ||
parenthesis = _ref.parenthesis; | ||
var numberSource = nestedUneval(value.valueOf()); | ||
return unevalConstructor("Number(".concat(numberSource, ")"), { | ||
useNew: useNew, | ||
parenthesis: parenthesis | ||
}); | ||
}; | ||
return v = b.length ? c ? "".concat(b) : s(b, { | ||
depth: i, | ||
indentUsingTab: u, | ||
indentSize: d | ||
}) : "", v = "[".concat(v, "]"), p(v, { | ||
parenthesis: f, | ||
useNew: l | ||
var unevalStringObject = function unevalStringObject(value, _ref) { | ||
var nestedUneval = _ref.nestedUneval, | ||
useNew = _ref.useNew, | ||
parenthesis = _ref.parenthesis; | ||
var stringSource = nestedUneval(value.valueOf()); | ||
return unevalConstructor("String(".concat(stringSource, ")"), { | ||
useNew: useNew, | ||
parenthesis: parenthesis | ||
}); | ||
}; | ||
var unevalBooleanObject = function unevalBooleanObject(value, _ref) { | ||
var nestedUneval = _ref.nestedUneval, | ||
useNew = _ref.useNew, | ||
parenthesis = _ref.parenthesis; | ||
var booleanSource = nestedUneval(value.valueOf()); | ||
return unevalConstructor("Boolean(".concat(booleanSource, ")"), { | ||
useNew: useNew, | ||
parenthesis: parenthesis | ||
}); | ||
}; | ||
var unevalError = function unevalError(error, _ref) { | ||
var nestedUneval = _ref.nestedUneval, | ||
useNew = _ref.useNew, | ||
parenthesis = _ref.parenthesis, | ||
accurateErrorProperties = _ref.accurateErrorProperties; | ||
var messageSource = nestedUneval(error.message); | ||
var errorSource = unevalConstructor("".concat(errorToConstructorName(error), "(").concat(messageSource, ")"), { | ||
useNew: useNew, | ||
parenthesis: parenthesis | ||
}); | ||
if (accurateErrorProperties) { | ||
return makeErrorSourceAccurate({ | ||
error: error, | ||
errorSource: errorSource, | ||
nestedUneval: nestedUneval | ||
}); | ||
}, | ||
Boolean: function (e, n) { | ||
var t = n.nestedUneval, | ||
r = n.useNew, | ||
o = n.parenthesis, | ||
c = t(e.valueOf()); | ||
return p("Boolean(".concat(c, ")"), { | ||
useNew: r, | ||
parenthesis: o | ||
}); | ||
}, | ||
Error: function (e, n) { | ||
var t = n.nestedUneval, | ||
r = n.useNew, | ||
o = n.parenthesis, | ||
c = n.accurateErrorProperties, | ||
i = t(e.message), | ||
a = p("".concat(v(e), "(").concat(i, ")"), { | ||
useNew: r, | ||
parenthesis: o | ||
}); | ||
return c ? l({ | ||
error: e, | ||
errorSource: a, | ||
nestedUneval: t | ||
}) : a; | ||
}, | ||
Date: function (e, n) { | ||
var t = n.nestedUneval, | ||
r = n.useNew, | ||
o = n.parenthesis, | ||
c = t(e.valueOf()); | ||
return p("Date(".concat(c, ")"), { | ||
useNew: r, | ||
parenthesis: o | ||
}); | ||
}, | ||
Function: function (e, n) { | ||
var t, | ||
r = n.showFunctionBody, | ||
o = n.parenthesis, | ||
c = n.depth; | ||
if (r) t = e.toString();else { | ||
var i = void 0 === e.prototype ? "() =>" : "function ".concat(0 === c ? e.name : "", "()"); | ||
t = "".concat(i, " {/* hidden */}"); | ||
} | ||
return o ? "(".concat(t, ")") : t; | ||
}, | ||
Number: function (e, n) { | ||
var t = n.nestedUneval, | ||
r = n.useNew, | ||
o = n.parenthesis, | ||
c = t(e.valueOf()); | ||
return p("Number(".concat(c, ")"), { | ||
useNew: r, | ||
parenthesis: o | ||
}); | ||
}, | ||
Object: f, | ||
RegExp: function (e) { | ||
return e.toString(); | ||
}, | ||
String: function (e, n) { | ||
var t = n.nestedUneval, | ||
r = n.useNew, | ||
o = n.parenthesis, | ||
c = t(e.valueOf()); | ||
return p("String(".concat(c, ")"), { | ||
useNew: r, | ||
parenthesis: o | ||
}); | ||
} | ||
return errorSource; | ||
}; | ||
e("uneval", function (e) { | ||
var n = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}, | ||
t = n.parenthesis, | ||
o = void 0 !== t && t, | ||
a = n.singleQuote, | ||
u = void 0 !== a && a, | ||
s = n.useNew, | ||
l = void 0 !== s && s, | ||
v = n.objectConstructor, | ||
b = void 0 !== v && v, | ||
g = n.compact, | ||
y = void 0 !== g && g, | ||
m = n.showFunctionBody, | ||
S = void 0 !== m && m, | ||
O = n.indentUsingTab, | ||
w = void 0 !== O && O, | ||
U = n.indentSize, | ||
j = void 0 === U ? 2 : U, | ||
N = n.accurateErrorProperties; | ||
return function e(n, t) { | ||
var o = function (e) { | ||
var n = i(e); | ||
return "function" === n ? { | ||
compositeType: "Function" | ||
} : "object" === n ? { | ||
compositeType: c(e) | ||
} : { | ||
primitiveType: n | ||
}; | ||
}(n), | ||
a = o.primitiveType, | ||
u = o.compositeType, | ||
s = r({}, t, { | ||
nestedUneval: function (n) { | ||
var o = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {}; | ||
return e(n, r({}, t, { | ||
depth: t.depth + 1 | ||
}, o)); | ||
var makeErrorSourceAccurate = function makeErrorSourceAccurate(_ref2) { | ||
var error = _ref2.error, | ||
errorSource = _ref2.errorSource, | ||
nestedUneval = _ref2.nestedUneval; | ||
var ownPropertyNames = Object.getOwnPropertyNames(error).filter(function (name) { | ||
return name !== "message"; | ||
}); | ||
var definePropertiesSource = ownPropertyNames.map(function (name) { | ||
var descriptor = Object.getOwnPropertyDescriptor(error, name); | ||
return "Object.defineProperty(error, ".concat(nestedUneval(name), ", ").concat(nestedUneval(descriptor), ")"); | ||
}); // TODO: make indentation dependent of current depth | ||
return "(function (error) {\n ".concat(definePropertiesSource.join("\n "), "\n return error\n})(").concat(errorSource, ")"); | ||
}; | ||
var errorToConstructorName = function errorToConstructorName(_ref3) { | ||
var name = _ref3.name; | ||
if (derivedErrorNameArray.includes(name)) { | ||
return name; | ||
} | ||
return "Error"; | ||
}; // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Error_types | ||
var derivedErrorNameArray = ["EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError"]; | ||
var unevalRegExp = function unevalRegExp(value) { | ||
return value.toString(); | ||
}; | ||
var compositeMap = { | ||
Array: unevalArray, | ||
Boolean: unevalBooleanObject, | ||
Error: unevalError, | ||
Date: unevalDate, | ||
Function: unevalFunction, | ||
Number: unevalNumberObject, | ||
Object: unevalObject, | ||
RegExp: unevalRegExp, | ||
String: unevalStringObject | ||
}; | ||
var uneval = exports('uneval', function uneval(value) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$parenthesis = _ref.parenthesis, | ||
parenthesis = _ref$parenthesis === void 0 ? false : _ref$parenthesis, | ||
_ref$singleQuote = _ref.singleQuote, | ||
singleQuote = _ref$singleQuote === void 0 ? false : _ref$singleQuote, | ||
_ref$useNew = _ref.useNew, | ||
useNew = _ref$useNew === void 0 ? false : _ref$useNew, | ||
_ref$objectConstructo = _ref.objectConstructor, | ||
objectConstructor = _ref$objectConstructo === void 0 ? false : _ref$objectConstructo, | ||
_ref$compact = _ref.compact, | ||
compact = _ref$compact === void 0 ? false : _ref$compact, | ||
_ref$showFunctionBody = _ref.showFunctionBody, | ||
showFunctionBody = _ref$showFunctionBody === void 0 ? false : _ref$showFunctionBody, | ||
_ref$indentUsingTab = _ref.indentUsingTab, | ||
indentUsingTab = _ref$indentUsingTab === void 0 ? false : _ref$indentUsingTab, | ||
_ref$indentSize = _ref.indentSize, | ||
indentSize = _ref$indentSize === void 0 ? 2 : _ref$indentSize, | ||
_ref$accurateErrorPro = _ref.accurateErrorProperties, | ||
accurateErrorProperties = _ref$accurateErrorPro === void 0 ? false : _ref$accurateErrorPro; | ||
var scopedUneval = function scopedUneval(scopedValue, scopedOptions) { | ||
var _valueToType = valueToType(scopedValue), | ||
primitiveType = _valueToType.primitiveType, | ||
compositeType = _valueToType.compositeType; | ||
var options = _objectSpread({}, scopedOptions, { | ||
nestedUneval: function nestedUneval(nestedValue) { | ||
var nestedOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return scopedUneval(nestedValue, _objectSpread({}, scopedOptions, { | ||
depth: scopedOptions.depth + 1 | ||
}, nestedOptions)); | ||
} | ||
}); | ||
return a ? d[a](n, s) : u in h ? h[u](n, s) : p("".concat(u, "(").concat(f(n, s), ")"), r({}, s, { | ||
parenthesis: !1 | ||
if (primitiveType) return primitiveMap[primitiveType](scopedValue, options); | ||
if (compositeType in compositeMap) return compositeMap[compositeType](scopedValue, options); | ||
return unevalConstructor("".concat(compositeType, "(").concat(unevalObject(scopedValue, options), ")"), _objectSpread({}, options, { | ||
parenthesis: false | ||
})); | ||
}(e, { | ||
parenthesis: o, | ||
singleQuote: u, | ||
useNew: l, | ||
objectConstructor: b, | ||
compact: y, | ||
showFunctionBody: S, | ||
indentUsingTab: w, | ||
indentSize: j, | ||
accurateErrorProperties: void 0 !== N && N, | ||
}; | ||
return scopedUneval(value, { | ||
parenthesis: parenthesis, | ||
singleQuote: singleQuote, | ||
useNew: useNew, | ||
objectConstructor: objectConstructor, | ||
compact: compact, | ||
showFunctionBody: showFunctionBody, | ||
indentUsingTab: indentUsingTab, | ||
indentSize: indentSize, | ||
accurateErrorProperties: accurateErrorProperties, | ||
depth: 0 | ||
@@ -351,0 +592,0 @@ }); |
'use strict'; | ||
var entryPointName = "main"; | ||
var groupMap = { | ||
"best": { | ||
"incompatibleNameArray": ["proposal-json-strings", "proposal-optional-catch-binding", "proposal-unicode-property-regex", "syntax-object-rest-spread", "syntax-optional-catch-binding", "transform-dotall-regex"], | ||
"platformCompatMap": { | ||
"node": "8.3" | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _typeof(obj) { | ||
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { | ||
_typeof = function (obj) { | ||
return typeof obj; | ||
}; | ||
} else { | ||
_typeof = function (obj) { | ||
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; | ||
}; | ||
} | ||
return _typeof(obj); | ||
} | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
return obj; | ||
} | ||
function _objectSpread(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
var ownKeys = Object.keys(source); | ||
if (typeof Object.getOwnPropertySymbols === 'function') { | ||
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(source, sym).enumerable; | ||
})); | ||
} | ||
}, | ||
"otherwise": { | ||
"incompatibleNameArray": ["proposal-object-rest-spread", "proposal-optional-catch-binding", "proposal-unicode-property-regex", "proposal-json-strings", "syntax-object-rest-spread", "syntax-optional-catch-binding", "transform-async-to-promises", "transform-arrow-functions", "transform-block-scoped-functions", "transform-block-scoping", "transform-classes", "transform-computed-properties", "transform-destructuring", "transform-dotall-regex", "transform-duplicate-keys", "transform-exponentiation-operator", "transform-for-of", "transform-function-name", "transform-literals", "transform-new-target", "transform-object-super", "transform-parameters", "transform-shorthand-properties", "transform-spread", "transform-sticky-regex", "transform-template-literals", "transform-typeof-symbol", "transform-unicode-regex"], | ||
"platformCompatMap": {} | ||
ownKeys.forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} | ||
}; | ||
var detect = function detect() { | ||
return target; | ||
} | ||
var valueToType = function valueToType(value) { | ||
var primitiveType = valueToPrimitiveType(value); | ||
if (primitiveType === "function") { | ||
return { | ||
compositeType: "Function" | ||
}; | ||
} | ||
if (primitiveType === "object") { | ||
var compositeType = valueToCompositeType(value); | ||
return { | ||
compositeType: compositeType | ||
}; | ||
} | ||
return { | ||
name: "node", | ||
version: process.version.slice(1) | ||
primitiveType: primitiveType | ||
}; | ||
}; | ||
var toString = Object.prototype.toString; | ||
var valueToVersion = function valueToVersion(value) { | ||
if (typeof value === "number") { | ||
return numberToVersion(value); | ||
var valueToCompositeType = function valueToCompositeType(object) { | ||
if (_typeof(object) === "object" && Object.getPrototypeOf(object) === null) return "Object"; | ||
var toStringResult = toString.call(object); // returns format is '[object ${tagName}]'; | ||
// and we want ${tagName} | ||
var tagName = toStringResult.slice("[object ".length, -1); | ||
if (tagName === "Object") { | ||
var objectConstructorName = object.constructor.name; | ||
if (objectConstructorName !== "Object") { | ||
return objectConstructorName; | ||
} | ||
} | ||
if (typeof value === "string") { | ||
return stringToVersion(value); | ||
return tagName; | ||
}; | ||
var valueToPrimitiveType = function valueToPrimitiveType(value) { | ||
if (value === null) { | ||
return "null"; | ||
} | ||
throw new TypeError(createValueErrorMessage({ | ||
version: value | ||
if (value === undefined) { | ||
return "undefined"; | ||
} | ||
return _typeof(value); | ||
}; // const type = getCompositeType(value) | ||
// if (type in mapping) { | ||
// return mapping[type](value, options) | ||
// } | ||
// return unevalConstructor(`${type}(${unevalObject(value, options)})`, { | ||
// ...options, | ||
// parenthesis: false, | ||
// }) | ||
var unevalBoolean = function unevalBoolean(value) { | ||
return value.toString(); | ||
}; | ||
var unevalNull = function unevalNull() { | ||
return "null"; | ||
}; | ||
var unevalNumber = function unevalNumber(value) { | ||
return Object.is(value, -0) ? "-0" : value.toString(); | ||
}; | ||
// https://github.com/joliss/js-string-escape/blob/master/index.js | ||
// http://javascript.crockford.com/remedial.html | ||
var quote = function quote(value) { | ||
var string = String(value); | ||
var i = 0; | ||
var j = string.length; | ||
var escapedString = ""; | ||
while (i < j) { | ||
var char = string[i]; | ||
var escapedChar = void 0; | ||
if (char === '"' || char === "'" || char === "\\") { | ||
escapedChar = "\\".concat(char); | ||
} else if (char === "\n") { | ||
escapedChar = "\\n"; | ||
} else if (char === "\r") { | ||
escapedChar = "\\r"; | ||
} else if (char === "\u2028") { | ||
escapedChar = "\\u2028"; | ||
} else if (char === "\u2029") { | ||
escapedChar = "\\u2029"; | ||
} else { | ||
escapedChar = char; | ||
} | ||
escapedString += escapedChar; | ||
i++; | ||
} | ||
return escapedString; | ||
}; | ||
var preNewLineAndIndentation = function preNewLineAndIndentation(value, _ref) { | ||
var depth = _ref.depth, | ||
indentUsingTab = _ref.indentUsingTab, | ||
indentSize = _ref.indentSize; | ||
return "".concat(newLineAndIndent({ | ||
count: depth + 1, | ||
useTabs: indentUsingTab, | ||
size: indentSize | ||
})).concat(value); | ||
}; | ||
var postNewLineAndIndentation = function postNewLineAndIndentation(_ref2) { | ||
var depth = _ref2.depth, | ||
indentUsingTab = _ref2.indentUsingTab, | ||
indentSize = _ref2.indentSize; | ||
return newLineAndIndent({ | ||
count: depth, | ||
useTabs: indentUsingTab, | ||
size: indentSize | ||
}); | ||
}; | ||
var newLineAndIndent = function newLineAndIndent(_ref3) { | ||
var count = _ref3.count, | ||
useTabs = _ref3.useTabs, | ||
size = _ref3.size; | ||
if (useTabs) { | ||
// eslint-disable-next-line prefer-template | ||
return "\n" + "\t".repeat(count); | ||
} // eslint-disable-next-line prefer-template | ||
return "\n" + " ".repeat(count * size); | ||
}; | ||
var wrapNewLineAndIndentation = function wrapNewLineAndIndentation(value, _ref4) { | ||
var depth = _ref4.depth, | ||
indentUsingTab = _ref4.indentUsingTab, | ||
indentSize = _ref4.indentSize; | ||
return "".concat(preNewLineAndIndentation(value, { | ||
depth: depth, | ||
indentUsingTab: indentUsingTab, | ||
indentSize: indentSize | ||
})).concat(postNewLineAndIndentation({ | ||
depth: depth, | ||
indentUsingTab: indentUsingTab, | ||
indentSize: indentSize | ||
})); | ||
}; | ||
var numberToVersion = function numberToVersion(number) { | ||
return { | ||
major: number, | ||
minor: 0, | ||
patch: 0 | ||
}; | ||
var unevalString = function unevalString(value, _ref) { | ||
var singleQuote = _ref.singleQuote; | ||
var quotedValue = quote(value); | ||
return singleQuote ? "'".concat(quotedValue, "'") : "\"".concat(quotedValue, "\""); | ||
}; | ||
var stringToVersion = function stringToVersion(string) { | ||
if (string.indexOf(".") > -1) { | ||
var parts = string.split("."); | ||
return { | ||
major: Number(parts[0]), | ||
minor: parts[1] ? Number(parts[1]) : 0, | ||
patch: parts[2] ? Number(parts[2]) : 0 | ||
}; | ||
var unevalSymbol = function unevalSymbol(value, _ref) { | ||
var nestedUneval = _ref.nestedUneval, | ||
parenthesis = _ref.parenthesis; | ||
var toStringResult = value.toString(); | ||
var openingParenthesisIndex = toStringResult.indexOf("("); | ||
var closingParenthesisIndex = toStringResult.indexOf(")"); | ||
var symbolDescription = toStringResult.slice(openingParenthesisIndex + 1, closingParenthesisIndex); | ||
var symbolDescriptionSource = symbolDescription ? nestedUneval(symbolDescription) : ""; | ||
var symbolSource = "Symbol(".concat(symbolDescriptionSource, ")"); | ||
if (parenthesis) { | ||
return "".concat(symbolSource); | ||
} | ||
if (isNaN(string)) { | ||
return { | ||
major: 0, | ||
minor: 0, | ||
patch: 0 | ||
}; | ||
return symbolSource; | ||
}; | ||
var unevalUndefined = function unevalUndefined() { | ||
return "undefined"; | ||
}; | ||
var primitiveMap = { | ||
boolean: unevalBoolean, | ||
null: unevalNull, | ||
number: unevalNumber, | ||
string: unevalString, | ||
symbol: unevalSymbol, | ||
undefined: unevalUndefined | ||
}; | ||
var unevalConstructor = function unevalConstructor(value, _ref) { | ||
var parenthesis = _ref.parenthesis, | ||
useNew = _ref.useNew; | ||
var formattedString = value; | ||
if (parenthesis) { | ||
formattedString = "(".concat(value, ")"); | ||
} | ||
return { | ||
major: Number(string), | ||
minor: 0, | ||
patch: 0 | ||
}; | ||
if (useNew) { | ||
formattedString = "new ".concat(formattedString); | ||
} | ||
return formattedString; | ||
}; | ||
var createValueErrorMessage = function createValueErrorMessage(_ref) { | ||
var value = _ref.value; | ||
return "value must be a number or a string.\nvalue: ".concat(value); | ||
var unevalArray = function unevalArray(value, _ref) { | ||
var _ref$seen = _ref.seen, | ||
seen = _ref$seen === void 0 ? [] : _ref$seen, | ||
nestedUneval = _ref.nestedUneval, | ||
compact = _ref.compact, | ||
depth = _ref.depth, | ||
indentUsingTab = _ref.indentUsingTab, | ||
indentSize = _ref.indentSize, | ||
parenthesis = _ref.parenthesis, | ||
useNew = _ref.useNew; | ||
if (seen.indexOf(value) > -1) { | ||
return "Symbol.for('circular')"; | ||
} | ||
seen.push(value); | ||
var valuesSource = ""; | ||
var i = 0; | ||
var j = value.length; | ||
while (i < j) { | ||
var valueSource = value.hasOwnProperty(i) ? nestedUneval(value[i], { | ||
seen: seen | ||
}) : ""; | ||
if (compact) { | ||
if (i === 0) { | ||
valuesSource += valueSource; | ||
} else if (valueSource) { | ||
valuesSource += ", ".concat(valueSource); | ||
} else { | ||
valuesSource += ","; | ||
} | ||
} else if (i === 0) { | ||
valuesSource += valueSource; | ||
} else { | ||
valuesSource += ",".concat(preNewLineAndIndentation(valueSource, { | ||
depth: depth, | ||
indentUsingTab: indentUsingTab, | ||
indentSize: indentSize | ||
})); | ||
} | ||
i++; | ||
} | ||
var arraySource; | ||
if (valuesSource.length) { | ||
if (compact) { | ||
arraySource = "".concat(valuesSource); | ||
} else { | ||
arraySource = wrapNewLineAndIndentation(valuesSource, { | ||
depth: depth, | ||
indentUsingTab: indentUsingTab, | ||
indentSize: indentSize | ||
}); | ||
} | ||
} else { | ||
arraySource = ""; | ||
} | ||
arraySource = "[".concat(arraySource, "]"); | ||
return unevalConstructor(arraySource, { | ||
parenthesis: parenthesis, | ||
useNew: useNew | ||
}); | ||
}; | ||
var versionCompare = function versionCompare(versionA, versionB) { | ||
var semanticVersionA = valueToVersion(versionA); | ||
var semanticVersionB = valueToVersion(versionB); | ||
var majorDiff = semanticVersionA.major - semanticVersionB.major; | ||
var unevalObject = function unevalObject(value, _ref) { | ||
var nestedUneval = _ref.nestedUneval, | ||
_ref$seen = _ref.seen, | ||
seen = _ref$seen === void 0 ? [] : _ref$seen, | ||
compact = _ref.compact, | ||
depth = _ref.depth, | ||
indentUsingTab = _ref.indentUsingTab, | ||
indentSize = _ref.indentSize, | ||
objectConstructor = _ref.objectConstructor, | ||
parenthesis = _ref.parenthesis, | ||
useNew = _ref.useNew; | ||
if (majorDiff > 0) { | ||
return majorDiff; | ||
if (seen.indexOf(value) > -1) { | ||
return "Symbol.for('circular')"; | ||
} | ||
if (majorDiff < 0) { | ||
return majorDiff; | ||
seen.push(value); | ||
var propertiesSource = ""; | ||
var propertyNames = Object.getOwnPropertyNames(value); | ||
var i = 0; | ||
var j = propertyNames.length; | ||
while (i < j) { | ||
var propertyName = propertyNames[i]; | ||
var propertyNameAsNumber = parseInt(propertyName, 10); | ||
var propertyNameSource = nestedUneval(Number.isInteger(propertyNameAsNumber) ? propertyNameAsNumber : propertyName); | ||
var propertyValueSource = nestedUneval(value[propertyName], { | ||
seen: seen | ||
}); | ||
if (compact) { | ||
if (i === 0) { | ||
propertiesSource += "".concat(propertyNameSource, ": ").concat(propertyValueSource); | ||
} else { | ||
propertiesSource += ", ".concat(propertyNameSource, ": ").concat(propertyValueSource); | ||
} | ||
} else if (i === 0) { | ||
propertiesSource += "".concat(propertyNameSource, ": ").concat(propertyValueSource); | ||
} else { | ||
propertiesSource += ",".concat(preNewLineAndIndentation("".concat(propertyNameSource, ": ").concat(propertyValueSource), { | ||
depth: depth, | ||
indentUsingTab: indentUsingTab, | ||
indentSize: indentSize | ||
})); | ||
} | ||
i++; | ||
} | ||
var minorDiff = semanticVersionA.minor - semanticVersionB.minor; | ||
var objectSource; | ||
if (minorDiff > 0) { | ||
return minorDiff; | ||
if (propertiesSource.length) { | ||
if (compact) { | ||
objectSource = "".concat(propertiesSource); | ||
} else { | ||
objectSource = "".concat(wrapNewLineAndIndentation(propertiesSource, { | ||
depth: depth, | ||
indentUsingTab: indentUsingTab, | ||
indentSize: indentSize | ||
})); | ||
} | ||
} else { | ||
objectSource = ""; | ||
} | ||
if (minorDiff < 0) { | ||
return minorDiff; | ||
if (objectConstructor) { | ||
objectSource = "Object({".concat(objectSource, "})"); | ||
} else { | ||
objectSource = "{".concat(objectSource, "}"); | ||
} | ||
var patchDiff = semanticVersionA.patch - semanticVersionB.patch; | ||
return unevalConstructor(objectSource, { | ||
parenthesis: parenthesis, | ||
useNew: useNew | ||
}); | ||
}; | ||
if (patchDiff > 0) { | ||
return patchDiff; | ||
var unevalFunction = function unevalFunction(value, _ref) { | ||
var showFunctionBody = _ref.showFunctionBody, | ||
parenthesis = _ref.parenthesis, | ||
depth = _ref.depth; | ||
var functionSource; | ||
if (showFunctionBody) { | ||
functionSource = value.toString(); | ||
} else { | ||
var isArrowFunction = value.prototype === undefined; | ||
var head = isArrowFunction ? "() =>" : "function ".concat(depth === 0 ? value.name : "", "()"); | ||
functionSource = "".concat(head, " {/* hidden */}"); | ||
} | ||
if (patchDiff < 0) { | ||
return patchDiff; | ||
if (parenthesis) { | ||
return "(".concat(functionSource, ")"); | ||
} | ||
return 0; | ||
return functionSource; | ||
}; | ||
var versionIsBelow = function versionIsBelow(versionSupposedBelow, versionSupposedAbove) { | ||
return versionCompare(versionSupposedBelow, versionSupposedAbove) < 0; | ||
var unevalDate = function unevalDate(value, _ref) { | ||
var nestedUneval = _ref.nestedUneval, | ||
useNew = _ref.useNew, | ||
parenthesis = _ref.parenthesis; | ||
var dateSource = nestedUneval(value.valueOf()); | ||
return unevalConstructor("Date(".concat(dateSource, ")"), { | ||
useNew: useNew, | ||
parenthesis: parenthesis | ||
}); | ||
}; | ||
var findHighestVersion = function findHighestVersion() { | ||
for (var _len = arguments.length, values = new Array(_len), _key = 0; _key < _len; _key++) { | ||
values[_key] = arguments[_key]; | ||
var unevalNumberObject = function unevalNumberObject(value, _ref) { | ||
var nestedUneval = _ref.nestedUneval, | ||
useNew = _ref.useNew, | ||
parenthesis = _ref.parenthesis; | ||
var numberSource = nestedUneval(value.valueOf()); | ||
return unevalConstructor("Number(".concat(numberSource, ")"), { | ||
useNew: useNew, | ||
parenthesis: parenthesis | ||
}); | ||
}; | ||
var unevalStringObject = function unevalStringObject(value, _ref) { | ||
var nestedUneval = _ref.nestedUneval, | ||
useNew = _ref.useNew, | ||
parenthesis = _ref.parenthesis; | ||
var stringSource = nestedUneval(value.valueOf()); | ||
return unevalConstructor("String(".concat(stringSource, ")"), { | ||
useNew: useNew, | ||
parenthesis: parenthesis | ||
}); | ||
}; | ||
var unevalBooleanObject = function unevalBooleanObject(value, _ref) { | ||
var nestedUneval = _ref.nestedUneval, | ||
useNew = _ref.useNew, | ||
parenthesis = _ref.parenthesis; | ||
var booleanSource = nestedUneval(value.valueOf()); | ||
return unevalConstructor("Boolean(".concat(booleanSource, ")"), { | ||
useNew: useNew, | ||
parenthesis: parenthesis | ||
}); | ||
}; | ||
var unevalError = function unevalError(error, _ref) { | ||
var nestedUneval = _ref.nestedUneval, | ||
useNew = _ref.useNew, | ||
parenthesis = _ref.parenthesis, | ||
accurateErrorProperties = _ref.accurateErrorProperties; | ||
var messageSource = nestedUneval(error.message); | ||
var errorSource = unevalConstructor("".concat(errorToConstructorName(error), "(").concat(messageSource, ")"), { | ||
useNew: useNew, | ||
parenthesis: parenthesis | ||
}); | ||
if (accurateErrorProperties) { | ||
return makeErrorSourceAccurate({ | ||
error: error, | ||
errorSource: errorSource, | ||
nestedUneval: nestedUneval | ||
}); | ||
} | ||
if (values.length === 0) throw new Error("missing argument"); | ||
return values.reduce(function (highestVersion, value) { | ||
if (versionIsBelow(highestVersion, value)) { | ||
return value; | ||
} | ||
return errorSource; | ||
}; | ||
return highestVersion; | ||
var makeErrorSourceAccurate = function makeErrorSourceAccurate(_ref2) { | ||
var error = _ref2.error, | ||
errorSource = _ref2.errorSource, | ||
nestedUneval = _ref2.nestedUneval; | ||
var ownPropertyNames = Object.getOwnPropertyNames(error).filter(function (name) { | ||
return name !== "message"; | ||
}); | ||
var definePropertiesSource = ownPropertyNames.map(function (name) { | ||
var descriptor = Object.getOwnPropertyDescriptor(error, name); | ||
return "Object.defineProperty(error, ".concat(nestedUneval(name), ", ").concat(nestedUneval(descriptor), ")"); | ||
}); // TODO: make indentation dependent of current depth | ||
return "(function (error) {\n ".concat(definePropertiesSource.join("\n "), "\n return error\n})(").concat(errorSource, ")"); | ||
}; | ||
var nodeToCompileId = function nodeToCompileId(_ref, groupMap) { | ||
var name = _ref.name, | ||
version = _ref.version; | ||
return Object.keys(groupMap).find(function (compileIdCandidate) { | ||
var platformCompatMap = groupMap[compileIdCandidate].platformCompatMap; | ||
var errorToConstructorName = function errorToConstructorName(_ref3) { | ||
var name = _ref3.name; | ||
if (name in platformCompatMap === false) { | ||
return false; | ||
} | ||
if (derivedErrorNameArray.includes(name)) { | ||
return name; | ||
} | ||
var versionForGroup = platformCompatMap[name]; | ||
var highestVersion = findHighestVersion(version, versionForGroup); | ||
return highestVersion === version; | ||
return "Error"; | ||
}; // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Error_types | ||
var derivedErrorNameArray = ["EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError"]; | ||
var unevalRegExp = function unevalRegExp(value) { | ||
return value.toString(); | ||
}; | ||
var compositeMap = { | ||
Array: unevalArray, | ||
Boolean: unevalBooleanObject, | ||
Error: unevalError, | ||
Date: unevalDate, | ||
Function: unevalFunction, | ||
Number: unevalNumberObject, | ||
Object: unevalObject, | ||
RegExp: unevalRegExp, | ||
String: unevalStringObject | ||
}; | ||
var uneval = function uneval(value) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$parenthesis = _ref.parenthesis, | ||
parenthesis = _ref$parenthesis === void 0 ? false : _ref$parenthesis, | ||
_ref$singleQuote = _ref.singleQuote, | ||
singleQuote = _ref$singleQuote === void 0 ? false : _ref$singleQuote, | ||
_ref$useNew = _ref.useNew, | ||
useNew = _ref$useNew === void 0 ? false : _ref$useNew, | ||
_ref$objectConstructo = _ref.objectConstructor, | ||
objectConstructor = _ref$objectConstructo === void 0 ? false : _ref$objectConstructo, | ||
_ref$compact = _ref.compact, | ||
compact = _ref$compact === void 0 ? false : _ref$compact, | ||
_ref$showFunctionBody = _ref.showFunctionBody, | ||
showFunctionBody = _ref$showFunctionBody === void 0 ? false : _ref$showFunctionBody, | ||
_ref$indentUsingTab = _ref.indentUsingTab, | ||
indentUsingTab = _ref$indentUsingTab === void 0 ? false : _ref$indentUsingTab, | ||
_ref$indentSize = _ref.indentSize, | ||
indentSize = _ref$indentSize === void 0 ? 2 : _ref$indentSize, | ||
_ref$accurateErrorPro = _ref.accurateErrorProperties, | ||
accurateErrorProperties = _ref$accurateErrorPro === void 0 ? false : _ref$accurateErrorPro; | ||
var scopedUneval = function scopedUneval(scopedValue, scopedOptions) { | ||
var _valueToType = valueToType(scopedValue), | ||
primitiveType = _valueToType.primitiveType, | ||
compositeType = _valueToType.compositeType; | ||
var options = _objectSpread({}, scopedOptions, { | ||
nestedUneval: function nestedUneval(nestedValue) { | ||
var nestedOptions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
return scopedUneval(nestedValue, _objectSpread({}, scopedOptions, { | ||
depth: scopedOptions.depth + 1 | ||
}, nestedOptions)); | ||
} | ||
}); | ||
if (primitiveType) return primitiveMap[primitiveType](scopedValue, options); | ||
if (compositeType in compositeMap) return compositeMap[compositeType](scopedValue, options); | ||
return unevalConstructor("".concat(compositeType, "(").concat(unevalObject(scopedValue, options), ")"), _objectSpread({}, options, { | ||
parenthesis: false | ||
})); | ||
}; | ||
return scopedUneval(value, { | ||
parenthesis: parenthesis, | ||
singleQuote: singleQuote, | ||
useNew: useNew, | ||
objectConstructor: objectConstructor, | ||
compact: compact, | ||
showFunctionBody: showFunctionBody, | ||
indentUsingTab: indentUsingTab, | ||
indentSize: indentSize, | ||
accurateErrorProperties: accurateErrorProperties, | ||
depth: 0 | ||
}); | ||
}; | ||
// eslint-disable-next-line import/no-unresolved | ||
var compileId = nodeToCompileId(detect(), groupMap); // eslint-disable-next-line import/no-dynamic-require | ||
module.exports = require("./".concat(compileId, "/").concat(entryPointName, ".js")); | ||
exports.uneval = uneval; | ||
//# sourceMappingURL=main.js.map |
{ | ||
"name": "@dmail/uneval", | ||
"version": "4.8.0", | ||
"version": "4.9.0", | ||
"license": "MIT", | ||
@@ -22,12 +22,12 @@ "repository": { | ||
"devDependencies": { | ||
"@jsenv/core": "5.6.0", | ||
"@jsenv/core": "5.30.0", | ||
"@jsenv/eslint-config": "8.0.0", | ||
"@jsenv/eslint-import-resolver": "4.1.0", | ||
"@jsenv/eslint-import-resolver": "4.6.0", | ||
"@jsenv/prettier-config": "1.0.0", | ||
"@jsenv/prettier-check-project": "1.0.0", | ||
"@jsenv/babel-config-map": "1.0.0", | ||
"@dmail/assert": "3.0.0", | ||
"@jsenv/prettier-check-project": "2.3.0", | ||
"@jsenv/codecov-upload": "1.6.0", | ||
"@jsenv/node-module-import-map": "1.4.0", | ||
"@dmail/assert": "3.4.0", | ||
"babel-eslint": "11.0.0-beta.0", | ||
"prettier": "1.15.3", | ||
"codecov": "2.3.0", | ||
"prettier": "1.16.3", | ||
"eslint": "5.1.0", | ||
@@ -34,0 +34,0 @@ "eslint-plugin-import": "2.6.0", |
@@ -1,7 +0,6 @@ | ||
/* eslint-disable import/max-dependencies */ | ||
import { valueToType } from "./valueToType.js" | ||
import { primitiveMap } from "./primitive/index.js" | ||
import { compositeMap } from "./composite/index.js" | ||
import { primitiveMap } from "./primitiveMap.js" | ||
import { compositeMap } from "./compositeMap.js" | ||
import { unevalConstructor } from "./unevalConstructor.js" | ||
import { unevalObject } from "./composite/unevalObject.js" | ||
import { unevalObject } from "./unevalObject.js" | ||
@@ -8,0 +7,0 @@ export const uneval = ( |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
0
119687
29
1423
2