Socket
Socket
Sign inDemoInstall

telejson

Package Overview
Dependencies
Maintainers
4
Versions
49
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telejson - npm Package Compare versions

Comparing version 6.0.4 to 6.0.5

1178

dist/index.js

@@ -0,49 +1,494 @@

function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
return arr2;
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
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 _instanceof(left, right) {
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
return !!right[Symbol.hasInstance](left);
} else {
return left instanceof right;
}
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
}
function _iterableToArrayLimit(arr, i) {
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
if (_i == null) return;
var _arr = [];
var _n = true;
var _d = false;
var _s, _e;
try {
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally{
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally{
if (_d) throw _e;
}
}
return _arr;
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
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 target;
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
var _typeof = function(obj) {
"@swc/helpers - typeof";
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
};
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(n);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
var __create = Object.create;
var __defProp = Object.defineProperty;
var __defProps = Object.defineProperties;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key2, value2) => key2 in obj ? __defProp(obj, key2, { enumerable: true, configurable: true, writable: true, value: value2 }) : obj[key2] = value2;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))
if (__hasOwnProp.call(b, prop))
__defNormalProp(a, prop, b[prop]);
if (__getOwnPropSymbols)
for (var prop of __getOwnPropSymbols(b)) {
if (__propIsEnum.call(b, prop))
__defNormalProp(a, prop, b[prop]);
var __esm = function(fn, res) {
return function __init() {
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
};
};
var __commonJS = function(cb, mod) {
return function __require() {
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = {
exports: {}
}).exports, mod), mod.exports;
};
};
var __export = function(target, all) {
for(var name2 in all)__defProp(target, name2, {
get: all[name2],
enumerable: true
});
};
var __copyProps = function(to, from, except, desc) {
if (from && typeof from === "object" || typeof from === "function") {
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
try {
var _loop = function(_iterator, _step) {
var key2 = _step.value;
if (!__hasOwnProp.call(to, key2) && key2 !== except) __defProp(to, key2, {
get: function() {
return from[key2];
},
enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable
});
};
for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop(_iterator, _step);
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally{
try {
if (!_iteratorNormalCompletion && _iterator.return != null) {
_iterator.return();
}
} finally{
if (_didIteratorError) {
throw _iteratorError;
}
}
}
}
return a;
return to;
};
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
var __export = (target, all) => {
for (var name2 in all)
__defProp(target, name2, { get: all[name2], enumerable: true });
var __toESM = function(mod, isNodeMode, target) {
return target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
value: mod,
enumerable: true
}) : target, mod);
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key2 of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key2) && key2 !== except)
__defProp(to, key2, { get: () => from[key2], enumerable: !(desc = __getOwnPropDesc(from, key2)) || desc.enumerable });
}
return to;
var __toCommonJS = function(mod) {
return __copyProps(__defProp({}, "__esModule", {
value: true
}), mod);
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// node_modules/tsup/assets/cjs_shims.js
var init_cjs_shims = __esm({
"node_modules/tsup/assets/cjs_shims.js": function() {}
});
// node_modules/lodash.get/index.js
var require_lodash = __commonJS({
"node_modules/lodash.get/index.js": function(exports, module2) {
var getValue = function getValue(object, key2) {
return object == null ? void 0 : object[key2];
};
var isHostObject = function isHostObject(value2) {
var result2 = false;
if (value2 != null && typeof value2.toString != "function") {
try {
result2 = !!(value2 + "");
} catch (e) {}
}
return result2;
};
var Hash = function Hash(entries) {
var index = -1, length = entries ? entries.length : 0;
this.clear();
while(++index < length){
var entry = entries[index];
this.set(entry[0], entry[1]);
}
};
var hashClear = function hashClear() {
this.__data__ = nativeCreate ? nativeCreate(null) : {};
};
var hashDelete = function hashDelete(key2) {
return this.has(key2) && delete this.__data__[key2];
};
var hashGet = function hashGet(key2) {
var data = this.__data__;
if (nativeCreate) {
var result2 = data[key2];
return result2 === HASH_UNDEFINED ? void 0 : result2;
}
return hasOwnProperty.call(data, key2) ? data[key2] : void 0;
};
var hashHas = function hashHas(key2) {
var data = this.__data__;
return nativeCreate ? data[key2] !== void 0 : hasOwnProperty.call(data, key2);
};
var hashSet = function hashSet(key2, value2) {
var data = this.__data__;
data[key2] = nativeCreate && value2 === void 0 ? HASH_UNDEFINED : value2;
return this;
};
var ListCache = function ListCache(entries) {
var index = -1, length = entries ? entries.length : 0;
this.clear();
while(++index < length){
var entry = entries[index];
this.set(entry[0], entry[1]);
}
};
var listCacheClear = function listCacheClear() {
this.__data__ = [];
};
var listCacheDelete = function listCacheDelete(key2) {
var data = this.__data__, index = assocIndexOf(data, key2);
if (index < 0) {
return false;
}
var lastIndex = data.length - 1;
if (index == lastIndex) {
data.pop();
} else {
splice.call(data, index, 1);
}
return true;
};
var listCacheGet = function listCacheGet(key2) {
var data = this.__data__, index = assocIndexOf(data, key2);
return index < 0 ? void 0 : data[index][1];
};
var listCacheHas = function listCacheHas(key2) {
return assocIndexOf(this.__data__, key2) > -1;
};
var listCacheSet = function listCacheSet(key2, value2) {
var data = this.__data__, index = assocIndexOf(data, key2);
if (index < 0) {
data.push([
key2,
value2
]);
} else {
data[index][1] = value2;
}
return this;
};
var MapCache = function MapCache(entries) {
var index = -1, length = entries ? entries.length : 0;
this.clear();
while(++index < length){
var entry = entries[index];
this.set(entry[0], entry[1]);
}
};
var mapCacheClear = function mapCacheClear() {
this.__data__ = {
"hash": new Hash(),
"map": new (Map2 || ListCache)(),
"string": new Hash()
};
};
var mapCacheDelete = function mapCacheDelete(key2) {
return getMapData(this, key2)["delete"](key2);
};
var mapCacheGet = function mapCacheGet(key2) {
return getMapData(this, key2).get(key2);
};
var mapCacheHas = function mapCacheHas(key2) {
return getMapData(this, key2).has(key2);
};
var mapCacheSet = function mapCacheSet(key2, value2) {
getMapData(this, key2).set(key2, value2);
return this;
};
var assocIndexOf = function assocIndexOf(array, key2) {
var length = array.length;
while(length--){
if (eq(array[length][0], key2)) {
return length;
}
}
return -1;
};
var baseGet = function baseGet(object, path) {
path = isKey(path, object) ? [
path
] : castPath(path);
var index = 0, length = path.length;
while(object != null && index < length){
object = object[toKey(path[index++])];
}
return index && index == length ? object : void 0;
};
var baseIsNative = function baseIsNative(value2) {
if (!isObject2(value2) || isMasked(value2)) {
return false;
}
var pattern = isFunction2(value2) || isHostObject(value2) ? reIsNative : reIsHostCtor;
return pattern.test(toSource(value2));
};
var baseToString = function baseToString(value2) {
if (typeof value2 == "string") {
return value2;
}
if (isSymbol2(value2)) {
return symbolToString ? symbolToString.call(value2) : "";
}
var result2 = value2 + "";
return result2 == "0" && 1 / value2 == -INFINITY ? "-0" : result2;
};
var castPath = function castPath(value2) {
return isArray(value2) ? value2 : stringToPath(value2);
};
var getMapData = function getMapData(map, key2) {
var data = map.__data__;
return isKeyable(key2) ? data[typeof key2 == "string" ? "string" : "hash"] : data.map;
};
var getNative = function getNative(object, key2) {
var value2 = getValue(object, key2);
return baseIsNative(value2) ? value2 : void 0;
};
var isKey = function isKey(value2, object) {
if (isArray(value2)) {
return false;
}
var type = typeof value2 === "undefined" ? "undefined" : _typeof(value2);
if (type == "number" || type == "symbol" || type == "boolean" || value2 == null || isSymbol2(value2)) {
return true;
}
return reIsPlainProp.test(value2) || !reIsDeepProp.test(value2) || object != null && value2 in Object(object);
};
var isKeyable = function isKeyable(value2) {
var type = typeof value2 === "undefined" ? "undefined" : _typeof(value2);
return type == "string" || type == "number" || type == "symbol" || type == "boolean" ? value2 !== "__proto__" : value2 === null;
};
var isMasked = function isMasked(func) {
return !!maskSrcKey && maskSrcKey in func;
};
var toKey = function toKey(value2) {
if (typeof value2 == "string" || isSymbol2(value2)) {
return value2;
}
var result2 = value2 + "";
return result2 == "0" && 1 / value2 == -INFINITY ? "-0" : result2;
};
var toSource = function toSource(func) {
if (func != null) {
try {
return funcToString.call(func);
} catch (e) {}
try {
return func + "";
} catch (e1) {}
}
return "";
};
var eq = function eq(value2, other) {
return value2 === other || value2 !== value2 && other !== other;
};
var isFunction2 = function isFunction2(value2) {
var tag = isObject2(value2) ? objectToString.call(value2) : "";
return tag == funcTag || tag == genTag;
};
var isObject2 = function isObject2(value2) {
var type = typeof value2 === "undefined" ? "undefined" : _typeof(value2);
return !!value2 && (type == "object" || type == "function");
};
var isObjectLike = function isObjectLike(value2) {
return !!value2 && typeof value2 == "object";
};
var isSymbol2 = function isSymbol2(value2) {
return (typeof value2 === "undefined" ? "undefined" : _typeof(value2)) == "symbol" || isObjectLike(value2) && objectToString.call(value2) == symbolTag;
};
var toString = function toString(value2) {
return value2 == null ? "" : baseToString(value2);
};
var get2 = function get2(object, path, defaultValue) {
var result2 = object == null ? void 0 : baseGet(object, path);
return result2 === void 0 ? defaultValue : result2;
};
init_cjs_shims();
var FUNC_ERROR_TEXT = "Expected a function";
var HASH_UNDEFINED = "__lodash_hash_undefined__";
var INFINITY = 1 / 0;
var funcTag = "[object Function]";
var genTag = "[object GeneratorFunction]";
var symbolTag = "[object Symbol]";
var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
var reIsPlainProp = /^\w*$/;
var reLeadingDot = /^\./;
var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
var reEscapeChar = /\\(\\)?/g;
var reIsHostCtor = /^\[object .+?Constructor\]$/;
var freeGlobal = typeof global == "object" && global && global.Object === Object && global;
var freeSelf = typeof self == "object" && self && self.Object === Object && self;
var root2 = freeGlobal || freeSelf || Function("return this")();
var arrayProto = Array.prototype;
var funcProto = Function.prototype;
var objectProto = Object.prototype;
var coreJsData = root2["__core-js_shared__"];
var maskSrcKey = function() {
var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || "");
return uid ? "Symbol(src)_1." + uid : "";
}();
var funcToString = funcProto.toString;
var hasOwnProperty = objectProto.hasOwnProperty;
var objectToString = objectProto.toString;
var reIsNative = RegExp("^" + funcToString.call(hasOwnProperty).replace(reRegExpChar, "\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, "$1.*?") + "$");
var Symbol2 = root2.Symbol;
var splice = arrayProto.splice;
var Map2 = getNative(root2, "Map");
var nativeCreate = getNative(Object, "create");
var symbolProto = Symbol2 ? Symbol2.prototype : void 0;
var symbolToString = symbolProto ? symbolProto.toString : void 0;
Hash.prototype.clear = hashClear;
Hash.prototype["delete"] = hashDelete;
Hash.prototype.get = hashGet;
Hash.prototype.has = hashHas;
Hash.prototype.set = hashSet;
ListCache.prototype.clear = listCacheClear;
ListCache.prototype["delete"] = listCacheDelete;
ListCache.prototype.get = listCacheGet;
ListCache.prototype.has = listCacheHas;
ListCache.prototype.set = listCacheSet;
MapCache.prototype.clear = mapCacheClear;
MapCache.prototype["delete"] = mapCacheDelete;
MapCache.prototype.get = mapCacheGet;
MapCache.prototype.has = mapCacheHas;
MapCache.prototype.set = mapCacheSet;
var stringToPath = memoize2(function(string) {
string = toString(string);
var result2 = [];
if (reLeadingDot.test(string)) {
result2.push("");
}
string.replace(rePropName, function(match, number, quote, string2) {
result2.push(quote ? string2.replace(reEscapeChar, "$1") : number || match);
});
return result2;
});
function memoize2(func, resolver) {
if (typeof func != "function" || resolver && typeof resolver != "function") {
throw new TypeError(FUNC_ERROR_TEXT);
}
var memoized = function() {
var args2 = arguments, key2 = resolver ? resolver.apply(this, args2) : args2[0], cache = memoized.cache;
if (cache.has(key2)) {
return cache.get(key2);
}
var result2 = func.apply(this, args2);
memoized.cache = cache.set(key2, result2);
return result2;
};
memoized.cache = new (memoize2.Cache || MapCache)();
return memoized;
}
memoize2.Cache = MapCache;
var isArray = Array.isArray;
module2.exports = get2;
}
});
// src/index.ts
var src_exports = {};
__export(src_exports, {
isJSON: () => isJSON,
parse: () => parse,
replacer: () => replacer,
reviver: () => reviver2,
stringify: () => stringify
isJSON: function() {
return isJSON;
},
parse: function() {
return parse;
},
replacer: function() {
return replacer;
},
reviver: function() {
return reviver2;
},
stringify: function() {
return stringify;
}
});
module.exports = __toCommonJS(src_exports);
init_cjs_shims();
var import_is_regex = __toESM(require("is-regex"));

@@ -53,365 +498,392 @@ var import_is_function = __toESM(require("is-function"));

var import_isobject = __toESM(require("isobject"));
var import_lodash = __toESM(require("lodash.get"));
var import_lodash = __toESM(require_lodash());
var import_memoizerific = __toESM(require("memoizerific"));
// src/dom-event.ts
init_cjs_shims();
var eventProperties = [
"bubbles",
"cancelBubble",
"cancelable",
"composed",
"currentTarget",
"defaultPrevented",
"eventPhase",
"isTrusted",
"returnValue",
"srcElement",
"target",
"timeStamp",
"type"
"bubbles",
"cancelBubble",
"cancelable",
"composed",
"currentTarget",
"defaultPrevented",
"eventPhase",
"isTrusted",
"returnValue",
"srcElement",
"target",
"timeStamp",
"type"
];
var customEventSpecificProperties = ["detail"];
var customEventSpecificProperties = [
"detail"
];
function extractEventHiddenProperties(event) {
const rebuildEvent = eventProperties.filter((value2) => event[value2] !== void 0).reduce((acc, value2) => {
return __spreadProps(__spreadValues({}, acc), { [value2]: event[value2] });
}, {});
if (event instanceof CustomEvent) {
customEventSpecificProperties.filter((value2) => event[value2] !== void 0).forEach((value2) => {
rebuildEvent[value2] = event[value2];
});
}
return rebuildEvent;
var rebuildEvent = eventProperties.filter(function(value2) {
return event[value2] !== void 0;
}).reduce(function(acc, value2) {
return _objectSpread({}, acc, _defineProperty({}, value2, event[value2]));
}, {});
if (_instanceof(event, CustomEvent)) {
customEventSpecificProperties.filter(function(value2) {
return event[value2] !== void 0;
}).forEach(function(value2) {
rebuildEvent[value2] = event[value2];
});
}
return rebuildEvent;
}
// src/index.ts
var isRunningInBrowser = typeof window !== "undefined" && typeof window.document !== "undefined";
var isObject = import_isobject.default;
var removeCodeComments = (code) => {
let inQuoteChar = null;
let inBlockComment = false;
let inLineComment = false;
let inRegexLiteral = false;
let newCode = "";
if (code.indexOf("//") >= 0 || code.indexOf("/*") >= 0) {
for (let i = 0; i < code.length; i += 1) {
if (!inQuoteChar && !inBlockComment && !inLineComment && !inRegexLiteral) {
if (code[i] === '"' || code[i] === "'" || code[i] === "`") {
inQuoteChar = code[i];
} else if (code[i] === "/" && code[i + 1] === "*") {
inBlockComment = true;
} else if (code[i] === "/" && code[i + 1] === "/") {
inLineComment = true;
} else if (code[i] === "/" && code[i + 1] !== "/") {
inRegexLiteral = true;
var removeCodeComments = function(code) {
var inQuoteChar = null;
var inBlockComment = false;
var inLineComment = false;
var inRegexLiteral = false;
var newCode = "";
if (code.indexOf("//") >= 0 || code.indexOf("/*") >= 0) {
for(var i = 0; i < code.length; i += 1){
if (!inQuoteChar && !inBlockComment && !inLineComment && !inRegexLiteral) {
if (code[i] === '"' || code[i] === "'" || code[i] === "`") {
inQuoteChar = code[i];
} else if (code[i] === "/" && code[i + 1] === "*") {
inBlockComment = true;
} else if (code[i] === "/" && code[i + 1] === "/") {
inLineComment = true;
} else if (code[i] === "/" && code[i + 1] !== "/") {
inRegexLiteral = true;
}
} else {
if (inQuoteChar && (code[i] === inQuoteChar && code[i - 1] !== "\\" || code[i] === "\n" && inQuoteChar !== "`")) {
inQuoteChar = null;
}
if (inRegexLiteral && (code[i] === "/" && code[i - 1] !== "\\" || code[i] === "\n")) {
inRegexLiteral = false;
}
if (inBlockComment && code[i - 1] === "/" && code[i - 2] === "*") {
inBlockComment = false;
}
if (inLineComment && code[i] === "\n") {
inLineComment = false;
}
}
if (!inBlockComment && !inLineComment) {
newCode += code[i];
}
}
} else {
if (inQuoteChar && (code[i] === inQuoteChar && code[i - 1] !== "\\" || code[i] === "\n" && inQuoteChar !== "`")) {
inQuoteChar = null;
}
if (inRegexLiteral && (code[i] === "/" && code[i - 1] !== "\\" || code[i] === "\n")) {
inRegexLiteral = false;
}
if (inBlockComment && code[i - 1] === "/" && code[i - 2] === "*") {
inBlockComment = false;
}
if (inLineComment && code[i] === "\n") {
inLineComment = false;
}
}
if (!inBlockComment && !inLineComment) {
newCode += code[i];
}
} else {
newCode = code;
}
} else {
newCode = code;
}
return newCode;
return newCode;
};
var cleanCode = (0, import_memoizerific.default)(1e4)((code) => removeCodeComments(code).replace(/\n\s*/g, "").trim());
var convertShorthandMethods = function(key2, stringified) {
const fnHead = stringified.slice(0, stringified.indexOf("{"));
const fnBody = stringified.slice(stringified.indexOf("{"));
if (fnHead.includes("=>")) {
return stringified;
}
if (fnHead.includes("function")) {
return stringified;
}
let modifiedHead = fnHead;
modifiedHead = modifiedHead.replace(key2, "function");
return modifiedHead + fnBody;
var cleanCode = (0, import_memoizerific.default)(1e4)(function(code) {
return removeCodeComments(code).replace(/\n\s*/g, "").trim();
});
var convertShorthandMethods = function convertShorthandMethods(key2, stringified) {
var fnHead = stringified.slice(0, stringified.indexOf("{"));
var fnBody = stringified.slice(stringified.indexOf("{"));
if (fnHead.includes("=>")) {
return stringified;
}
if (fnHead.includes("function")) {
return stringified;
}
var modifiedHead = fnHead;
modifiedHead = modifiedHead.replace(key2, "function");
return modifiedHead + fnBody;
};
var dateFormat = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{3})?Z$/;
var isJSON = (input) => input.match(/^[\[\{\"\}].*[\]\}\"]$/);
var isJSON = function(input) {
return input.match(/^[\[\{\"\}].*[\]\}\"]$/);
};
function convertUnconventionalData(data) {
if (!isObject(data)) {
return data;
}
let result2 = data;
let wasMutated = false;
if (isRunningInBrowser && data instanceof Event) {
result2 = extractEventHiddenProperties(result2);
wasMutated = true;
}
result2 = Object.keys(result2).reduce((acc, key2) => {
var _a;
try {
(_a = result2[key2]) == null ? void 0 : _a.toJSON;
acc[key2] = result2[key2];
} catch (err) {
wasMutated = true;
if (!isObject(data)) {
return data;
}
return acc;
}, {});
return wasMutated ? result2 : data;
var result2 = data;
var wasMutated = false;
if (isRunningInBrowser && _instanceof(data, Event)) {
result2 = extractEventHiddenProperties(result2);
wasMutated = true;
}
result2 = Object.keys(result2).reduce(function(acc, key2) {
try {
var ref;
(ref = result2[key2]) === null || ref === void 0 ? void 0 : ref.toJSON;
acc[key2] = result2[key2];
} catch (err) {
wasMutated = true;
}
return acc;
}, {});
return wasMutated ? result2 : data;
}
var replacer = function replacer2(options2) {
let objects;
let map;
let stack;
let keys;
return function replace(key2, value2) {
try {
if (key2 === "") {
keys = [];
objects = /* @__PURE__ */ new Map([[value2, "[]"]]);
map = /* @__PURE__ */ new Map();
stack = [];
return value2;
}
const origin = map.get(this) || this;
while (stack.length && origin !== stack[0]) {
stack.shift();
keys.pop();
}
if (typeof value2 === "boolean") {
return value2;
}
if (value2 === void 0) {
if (!options2.allowUndefined) {
return void 0;
var objects;
var map;
var stack;
var keys;
return function replace(key2, value2) {
try {
if (key2 === "") {
keys = [];
objects = /* @__PURE__ */ new Map([
[
value2,
"[]"
]
]);
map = /* @__PURE__ */ new Map();
stack = [];
return value2;
}
var origin = map.get(this) || this;
while(stack.length && origin !== stack[0]){
stack.shift();
keys.pop();
}
if (typeof value2 === "boolean") {
return value2;
}
if (value2 === void 0) {
if (!options2.allowUndefined) {
return void 0;
}
return "_undefined_";
}
if (value2 === null) {
return null;
}
if (typeof value2 === "number") {
if (value2 === -Infinity) {
return "_-Infinity_";
}
if (value2 === Infinity) {
return "_Infinity_";
}
if (Number.isNaN(value2)) {
return "_NaN_";
}
return value2;
}
if ((typeof value2 === "undefined" ? "undefined" : _typeof(value2)) === "bigint") {
return "_bigint_".concat(value2.toString());
}
if (typeof value2 === "string") {
if (dateFormat.test(value2)) {
if (!options2.allowDate) {
return void 0;
}
return "_date_".concat(value2);
}
return value2;
}
if ((0, import_is_regex.default)(value2)) {
if (!options2.allowRegExp) {
return void 0;
}
return "_regexp_".concat(value2.flags, "|").concat(value2.source);
}
if ((0, import_is_function.default)(value2)) {
if (!options2.allowFunction) {
return void 0;
}
var name2 = value2.name;
var stringified = value2.toString();
if (!stringified.match(/(\[native code\]|WEBPACK_IMPORTED_MODULE|__webpack_exports__|__webpack_require__)/)) {
return "_function_".concat(name2, "|").concat(cleanCode(convertShorthandMethods(key2, stringified)));
}
return "_function_".concat(name2, "|").concat((function() {}).toString());
}
if ((0, import_is_symbol.default)(value2)) {
if (!options2.allowSymbol) {
return void 0;
}
var globalRegistryKey = Symbol.keyFor(value2);
if (globalRegistryKey !== void 0) {
return "_gsymbol_".concat(globalRegistryKey);
}
return "_symbol_".concat(value2.toString().slice(7, -1));
}
if (stack.length >= options2.maxDepth) {
if (Array.isArray(value2)) {
return "[Array(".concat(value2.length, ")]");
}
return "[Object]";
}
if (value2 === this) {
return "_duplicate_".concat(JSON.stringify(keys));
}
if (value2.constructor && value2.constructor.name && value2.constructor.name !== "Object" && !Array.isArray(value2) && !options2.allowClass) {
return void 0;
}
var found = objects.get(value2);
if (!found) {
var converted = Array.isArray(value2) ? value2 : convertUnconventionalData(value2);
if (value2.constructor && value2.constructor.name && value2.constructor.name !== "Object" && !Array.isArray(value2) && options2.allowClass) {
try {
Object.assign(converted, {
"_constructor-name_": value2.constructor.name
});
} catch (e) {}
}
keys.push(key2);
stack.unshift(converted);
objects.set(value2, JSON.stringify(keys));
if (value2 !== converted) {
map.set(value2, converted);
}
return converted;
}
return "_duplicate_".concat(found);
} catch (e) {
return void 0;
}
return "_undefined_";
}
if (value2 === null) {
return null;
}
if (typeof value2 === "number") {
if (value2 === -Infinity) {
return "_-Infinity_";
};
};
var reviver2 = function reviver(options) {
var refs = [];
var root;
return function revive(key, value) {
if (key === "") {
root = value;
refs.forEach(function(param) {
var target = param.target, container = param.container, replacement = param.replacement;
var replacementArr = isJSON(replacement) ? JSON.parse(replacement) : replacement.split(".");
if (replacementArr.length === 0) {
container[target] = root;
} else {
container[target] = (0, import_lodash.default)(root, replacementArr);
}
});
}
if (value2 === Infinity) {
return "_Infinity_";
if (key === "_constructor-name_") {
return value;
}
if (Number.isNaN(value2)) {
return "_NaN_";
if (isObject(value) && value["_constructor-name_"] && options.allowFunction) {
var name2 = value["_constructor-name_"];
if (name2 !== "Object") {
var Fn = new Function("return function ".concat(name2.replace(/[\W_]+/g, ""), "(){}"))();
Object.setPrototypeOf(value, new Fn());
}
delete value["_constructor-name_"];
return value;
}
return value2;
}
if (typeof value2 === "bigint") {
return `_bigint_${value2.toString()}`;
}
if (typeof value2 === "string") {
if (dateFormat.test(value2)) {
if (!options2.allowDate) {
return void 0;
}
return `_date_${value2}`;
if (typeof value === "string" && value.startsWith("_function_") && options.allowFunction) {
var ref = _slicedToArray(value.match(/_function_([^|]*)\|(.*)/) || [], 3), name = ref[1], source = ref[2];
var sourceSanitized = source.replace(/[(\(\))|\\| |\]|`]*$/, "");
if (!options.lazyEval) {
return eval("(".concat(sourceSanitized, ")"));
}
var result = function() {
for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
args[_key] = arguments[_key];
}
var f = eval("(".concat(sourceSanitized, ")"));
return f.apply(void 0, _toConsumableArray(args));
};
Object.defineProperty(result, "toString", {
value: function() {
return sourceSanitized;
}
});
Object.defineProperty(result, "name", {
value: name
});
return result;
}
return value2;
}
if ((0, import_is_regex.default)(value2)) {
if (!options2.allowRegExp) {
return void 0;
if (typeof value === "string" && value.startsWith("_regexp_") && options.allowRegExp) {
var ref1 = _slicedToArray(value.match(/_regexp_([^|]*)\|(.*)/) || [], 3), flags = ref1[1], source2 = ref1[2];
return new RegExp(source2, flags);
}
return `_regexp_${value2.flags}|${value2.source}`;
}
if ((0, import_is_function.default)(value2)) {
if (!options2.allowFunction) {
return void 0;
if (typeof value === "string" && value.startsWith("_date_") && options.allowDate) {
return new Date(value.replace("_date_", ""));
}
const { name: name2 } = value2;
const stringified = value2.toString();
if (!stringified.match(/(\[native code\]|WEBPACK_IMPORTED_MODULE|__webpack_exports__|__webpack_require__)/)) {
return `_function_${name2}|${cleanCode(convertShorthandMethods(key2, stringified))}`;
if (typeof value === "string" && value.startsWith("_duplicate_")) {
refs.push({
target: key,
container: this,
replacement: value.replace(/^_duplicate_/, "")
});
return null;
}
return `_function_${name2}|${(() => {
}).toString()}`;
}
if ((0, import_is_symbol.default)(value2)) {
if (!options2.allowSymbol) {
return void 0;
if (typeof value === "string" && value.startsWith("_symbol_") && options.allowSymbol) {
return Symbol(value.replace("_symbol_", ""));
}
const globalRegistryKey = Symbol.keyFor(value2);
if (globalRegistryKey !== void 0) {
return `_gsymbol_${globalRegistryKey}`;
if (typeof value === "string" && value.startsWith("_gsymbol_") && options.allowSymbol) {
return Symbol.for(value.replace("_gsymbol_", ""));
}
return `_symbol_${value2.toString().slice(7, -1)}`;
}
if (stack.length >= options2.maxDepth) {
if (Array.isArray(value2)) {
return `[Array(${value2.length})]`;
if (typeof value === "string" && value === "_-Infinity_") {
return -Infinity;
}
return "[Object]";
}
if (value2 === this) {
return `_duplicate_${JSON.stringify(keys)}`;
}
if (value2.constructor && value2.constructor.name && value2.constructor.name !== "Object" && !Array.isArray(value2) && !options2.allowClass) {
return void 0;
}
const found = objects.get(value2);
if (!found) {
const converted = Array.isArray(value2) ? value2 : convertUnconventionalData(value2);
if (value2.constructor && value2.constructor.name && value2.constructor.name !== "Object" && !Array.isArray(value2) && options2.allowClass) {
try {
Object.assign(converted, { "_constructor-name_": value2.constructor.name });
} catch (e) {
}
if (typeof value === "string" && value === "_Infinity_") {
return Infinity;
}
keys.push(key2);
stack.unshift(converted);
objects.set(value2, JSON.stringify(keys));
if (value2 !== converted) {
map.set(value2, converted);
if (typeof value === "string" && value === "_NaN_") {
return NaN;
}
return converted;
}
return `_duplicate_${found}`;
} catch (e) {
return void 0;
}
};
};
var reviver2 = function reviver(options) {
const refs = [];
let root;
return function revive(key, value) {
if (key === "") {
root = value;
refs.forEach(({ target, container, replacement }) => {
const replacementArr = isJSON(replacement) ? JSON.parse(replacement) : replacement.split(".");
if (replacementArr.length === 0) {
container[target] = root;
} else {
container[target] = (0, import_lodash.default)(root, replacementArr);
if (typeof value === "string" && value.startsWith("_bigint_") && typeof BigInt === "function") {
return BigInt(value.replace("_bigint_", ""));
}
});
}
if (key === "_constructor-name_") {
return value;
}
if (isObject(value) && value["_constructor-name_"] && options.allowFunction) {
const name2 = value["_constructor-name_"];
if (name2 !== "Object") {
const Fn = new Function(`return function ${name2.replace(/[\W_]+/g, "")}(){}`)();
Object.setPrototypeOf(value, new Fn());
}
delete value["_constructor-name_"];
return value;
}
if (typeof value === "string" && value.startsWith("_function_") && options.allowFunction) {
const [, name, source] = value.match(/_function_([^|]*)\|(.*)/) || [];
const sourceSanitized = source.replace(/[(\(\))|\\| |\]|`]*$/, "");
if (!options.lazyEval) {
return eval(`(${sourceSanitized})`);
}
const result = (...args) => {
const f = eval(`(${sourceSanitized})`);
return f(...args);
};
Object.defineProperty(result, "toString", {
value: () => sourceSanitized
});
Object.defineProperty(result, "name", {
value: name
});
return result;
}
if (typeof value === "string" && value.startsWith("_regexp_") && options.allowRegExp) {
const [, flags, source2] = value.match(/_regexp_([^|]*)\|(.*)/) || [];
return new RegExp(source2, flags);
}
if (typeof value === "string" && value.startsWith("_date_") && options.allowDate) {
return new Date(value.replace("_date_", ""));
}
if (typeof value === "string" && value.startsWith("_duplicate_")) {
refs.push({ target: key, container: this, replacement: value.replace(/^_duplicate_/, "") });
return null;
}
if (typeof value === "string" && value.startsWith("_symbol_") && options.allowSymbol) {
return Symbol(value.replace("_symbol_", ""));
}
if (typeof value === "string" && value.startsWith("_gsymbol_") && options.allowSymbol) {
return Symbol.for(value.replace("_gsymbol_", ""));
}
if (typeof value === "string" && value === "_-Infinity_") {
return -Infinity;
}
if (typeof value === "string" && value === "_Infinity_") {
return Infinity;
}
if (typeof value === "string" && value === "_NaN_") {
return NaN;
}
if (typeof value === "string" && value.startsWith("_bigint_") && typeof BigInt === "function") {
return BigInt(value.replace("_bigint_", ""));
}
return value;
};
return value;
};
};
var defaultOptions = {
maxDepth: 10,
space: void 0,
allowFunction: true,
allowRegExp: true,
allowDate: true,
allowClass: true,
allowUndefined: true,
allowSymbol: true,
lazyEval: true
maxDepth: 10,
space: void 0,
allowFunction: true,
allowRegExp: true,
allowDate: true,
allowClass: true,
allowUndefined: true,
allowSymbol: true,
lazyEval: true
};
var stringify = (data, options2 = {}) => {
const mergedOptions = __spreadValues(__spreadValues({}, defaultOptions), options2);
return JSON.stringify(convertUnconventionalData(data), replacer(mergedOptions), options2.space);
var stringify = function(data) {
var options2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
var mergedOptions = _objectSpread({}, defaultOptions, options2);
return JSON.stringify(convertUnconventionalData(data), replacer(mergedOptions), options2.space);
};
var mutator = () => {
const mutated = /* @__PURE__ */ new Map();
return function mutateUndefined(value2) {
if (isObject(value2)) {
Object.entries(value2).forEach(([k, v]) => {
if (v === "_undefined_") {
value2[k] = void 0;
} else if (!mutated.get(v)) {
mutated.set(v, true);
mutateUndefined(v);
var mutator = function() {
var mutated = /* @__PURE__ */ new Map();
return function mutateUndefined(value2) {
if (isObject(value2)) {
Object.entries(value2).forEach(function(param) {
var _param = _slicedToArray(param, 2), k = _param[0], v = _param[1];
if (v === "_undefined_") {
value2[k] = void 0;
} else if (!mutated.get(v)) {
mutated.set(v, true);
mutateUndefined(v);
}
});
}
});
}
if (Array.isArray(value2)) {
value2.forEach((v, index) => {
mutated.set(v, true);
mutateUndefined(v);
if (v === "_undefined_") {
mutated.set(v, true);
value2[index] = void 0;
if (Array.isArray(value2)) {
value2.forEach(function(v, index) {
mutated.set(v, true);
mutateUndefined(v);
if (v === "_undefined_") {
mutated.set(v, true);
value2[index] = void 0;
}
});
}
});
}
};
};
};
var parse = (data, options2 = {}) => {
const mergedOptions = __spreadValues(__spreadValues({}, defaultOptions), options2);
const result2 = JSON.parse(data, reviver2(mergedOptions));
mutator()(result2);
return result2;
var parse = function(data) {
var options2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
var mergedOptions = _objectSpread({}, defaultOptions, options2);
var result2 = JSON.parse(data, reviver2(mergedOptions));
mutator()(result2);
return result2;
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
isJSON,
parse,
replacer,
reviver,
stringify
isJSON: isJSON,
parse: parse,
replacer: replacer,
reviver: reviver,
stringify: stringify
});
//# sourceMappingURL=index.js.map
{
"name": "telejson",
"version": "6.0.4",
"version": "6.0.5",
"description": "",

@@ -56,3 +56,2 @@ "keywords": [

"@types/is-function": "^1.0.0",
"@types/lodash.get": "^4.4.7",
"global": "^4.4.0",

@@ -63,3 +62,2 @@ "is-function": "^1.0.2",

"isobject": "^4.0.0",
"lodash.get": "^4.4.2",
"memoizerific": "^1.11.3"

@@ -73,3 +71,5 @@ },

"@storybook/eslint-config-storybook": "^3.0.0",
"@swc/core": "^1.2.179",
"@types/jest": "^26.0.22",
"@types/lodash.get": "^4.4.7",
"babel-core": "7.0.0-bridge.0",

@@ -80,2 +80,3 @@ "babel-jest": "^26.6.3",

"jest": "^26.6.3",
"lodash.get": "^4.4.2",
"prettier": "^2.2.1",

@@ -93,2 +94,3 @@ "regenerator-runtime": "^0.13.7",

],
"target": "es5",
"format": [

@@ -95,0 +97,0 @@ "esm",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc