Comparing version 5.0.0-0 to 5.0.0
@@ -125,6 +125,3 @@ "use strict"; | ||
keys = []; | ||
objects = [{ | ||
keys: '[]', | ||
value: value | ||
}]; | ||
objects = new Map([[value, '[]']]); | ||
stack = []; | ||
@@ -141,7 +138,15 @@ return value; | ||
if (options.allowRegExp && (0, _isRegex["default"])(value)) { | ||
if ((0, _isRegex["default"])(value)) { | ||
if (!options.allowRegExp) { | ||
return undefined; | ||
} | ||
return "_regexp_".concat(value.flags, "|").concat(value.source); | ||
} | ||
if (options.allowFunction && (0, _isFunction["default"])(value)) { | ||
if ((0, _isFunction["default"])(value)) { | ||
if (!options.allowFunction) { | ||
return undefined; | ||
} | ||
var name = value.name; | ||
@@ -157,11 +162,23 @@ var stringified = value.toString(); | ||
if (options.allowSymbol && (0, _isSymbol["default"])(value)) { | ||
if ((0, _isSymbol["default"])(value)) { | ||
if (!options.allowSymbol) { | ||
return undefined; | ||
} | ||
return "_symbol_".concat(value.toString().slice(7, -1)); | ||
} | ||
if (options.allowDate && typeof value === 'string' && dateFormat.test(value)) { | ||
if (typeof value === 'string' && dateFormat.test(value)) { | ||
if (!options.allowDate) { | ||
return undefined; | ||
} | ||
return "_date_".concat(value); | ||
} | ||
if (options.allowUndefined && value === undefined) { | ||
if (value === undefined) { | ||
if (!options.allowUndefined) { | ||
return undefined; | ||
} | ||
return '_undefined_'; | ||
@@ -202,5 +219,3 @@ } | ||
var found = objects.find(function (o) { | ||
return o.value === value; | ||
}); | ||
var found = objects.get(value); | ||
@@ -225,6 +240,3 @@ if (!found) { | ||
stack.unshift(value); | ||
objects.push({ | ||
keys: JSON.stringify(keys), | ||
value: value | ||
}); | ||
objects.set(value, JSON.stringify(keys)); | ||
return value; | ||
@@ -234,3 +246,3 @@ } // actually, here's the only place where the keys keeping is useful | ||
return "_duplicate_".concat(found.keys); | ||
return "_duplicate_".concat(found); | ||
} catch (e) { | ||
@@ -390,3 +402,3 @@ return undefined; | ||
var mutator = function mutator() { | ||
var mutated = []; | ||
var mutated = {}; | ||
return function mutateUndefined(value) { | ||
@@ -404,4 +416,4 @@ // JSON.parse will not output keys with value of undefined | ||
value[k] = undefined; | ||
} else if (!mutated.includes(v)) { | ||
mutated.push(v); | ||
} else if (!mutated[v]) { | ||
mutated[v] = true; | ||
mutateUndefined(v); | ||
@@ -414,3 +426,3 @@ } | ||
value.forEach(function (v) { | ||
mutated.push(v); | ||
mutated[v] = true; | ||
mutateUndefined(v); | ||
@@ -417,0 +429,0 @@ }); |
{ | ||
"name": "telejson", | ||
"version": "5.0.0-0", | ||
"version": "5.0.0", | ||
"description": "", | ||
@@ -47,3 +47,3 @@ "keywords": [ | ||
"is-function": "^1.0.2", | ||
"is-regex": "^1.1.0", | ||
"is-regex": "^1.1.1", | ||
"is-symbol": "^1.0.3", | ||
@@ -50,0 +50,0 @@ "isobject": "^4.0.0", |
@@ -14,2 +14,3 @@ # TeleJSON | ||
`JSON.parse` & `JSON.stringify` have limitation by design, because there are no data formats for things like | ||
- Date | ||
@@ -30,3 +31,3 @@ - Function | ||
**Functions** are supported, they are stringified and will be eval-ed when called. | ||
**Functions** are supported, they are stringified and will be eval-ed when called. | ||
This lazy eval is important for performance. | ||
@@ -51,3 +52,3 @@ The eval happens via `eval()` | ||
const Foo = function(){}; | ||
const Foo = function () {}; | ||
@@ -58,5 +59,7 @@ const root = { | ||
regex2: /foo/g, | ||
regex2: new RegExp('foo','i'), | ||
regex2: new RegExp('foo', 'i'), | ||
fn1: () => 'foo', | ||
fn2: function fn2() { return 'foo'; }, | ||
fn2: function fn2() { | ||
return 'foo'; | ||
}, | ||
Foo: new Foo(), | ||
@@ -103,3 +106,3 @@ }; | ||
`maxDepth`: controls how deep to keep stringifying. When max depth is reach, | ||
`maxDepth`: controls how deep to keep stringifying. When max depth is reach, | ||
objects will be replaced with `"[Object]"`, arrays will be replaced with `"[Array(<length>)]"`. | ||
@@ -131,2 +134,6 @@ default value is `10` | ||
## Requirements | ||
`telejson` depends on the collection type `Map`. If you support older browsers and devices which may not yet provide these natively (e.g. IE < 11) or which have non-compliant implementations (e.g. IE 11), consider including a global polyfill in your bundled application, such as `core-js` or `babel-polyfill`. | ||
## Contributing | ||
@@ -133,0 +140,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
20634
360
0
144
Updatedis-regex@^1.1.1