Comparing version 2.1.1 to 2.2.0
@@ -111,2 +111,6 @@ "use strict"; | ||
if ((0, _isRegex.default)(value)) { | ||
if (!options.allowRegExp) { | ||
return undefined; | ||
} | ||
return "_regexp_".concat(value.flags, "|").concat(value.source); | ||
@@ -116,2 +120,6 @@ } | ||
if ((0, _isFunction.default)(value)) { | ||
if (!options.allowFunction) { | ||
return undefined; | ||
} | ||
var name = value.name; | ||
@@ -128,2 +136,6 @@ var stringified = value.toString(); | ||
if ((0, _isSymbol.default)(value)) { | ||
if (!options.allowSymbol) { | ||
return undefined; | ||
} | ||
return "_symbol_".concat(value.toString().slice(7, -1)); | ||
@@ -133,2 +145,6 @@ } | ||
if (typeof value === 'string' && dateFormat.test(value)) { | ||
if (!options.allowDate) { | ||
return undefined; | ||
} | ||
return "_date_".concat(value); | ||
@@ -138,2 +154,6 @@ } | ||
if (value === undefined) { | ||
if (!options.allowUndefined) { | ||
return undefined; | ||
} | ||
return '_undefined_'; | ||
@@ -176,2 +196,6 @@ } | ||
if (value && (0, _isobject.default)(value) && value.constructor && value.constructor.name && value.constructor.name !== 'Object') { | ||
if (!options.allowClass) { | ||
return undefined; | ||
} | ||
try { | ||
@@ -322,2 +346,12 @@ Object.assign(value, { | ||
exports.isJSON = isJSON; | ||
var defaultOptions = { | ||
maxDepth: 10, | ||
space: undefined, | ||
allowFunction: true, | ||
allowRegExp: true, | ||
allowDate: true, | ||
allowClass: true, | ||
allowUndefined: true, | ||
allowSymbol: true | ||
}; | ||
@@ -324,0 +358,0 @@ var stringify = function stringify(data) { |
{ | ||
"name": "telejson", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "", | ||
@@ -40,4 +40,3 @@ "keywords": [ | ||
"lodash.get": "^4.4.2", | ||
"memoizerific": "^1.11.3", | ||
"safe-eval": "^0.4.1" | ||
"memoizerific": "^1.11.3" | ||
}, | ||
@@ -44,0 +43,0 @@ "devDependencies": { |
@@ -31,3 +31,3 @@ # TeleJSON | ||
This lazy eval is important for performance. | ||
The eval happens via [safe-eval](https://www.npmjs.com/package/safe-eval) | ||
The eval happens via `eval()` | ||
Functions are stripped of comments and whitespace. | ||
@@ -103,3 +103,3 @@ | ||
default value is `10` | ||
This option is really useful if your object is huge/complex, and you don't care deeply nested data, | ||
This option is really useful if your object is huge/complex, and you don't care about the deeply nested data. | ||
@@ -110,2 +110,14 @@ `space`: controls how to prettify the output string. | ||
`allowFunction`: When set to false, functions will not be serialized. (default = true) | ||
`allowRegExp`: When set to false, regular expressions will not be serialized. (default = true) | ||
`allowClass`: When set to false, class instances will not be serialized. (default = true) | ||
`allowDate`: When set to false, Date objects will not be serialized. (default = true) | ||
`allowUndefined`: When set to false, `undefined` will not be serialized. (default = true) | ||
`allowSymbol`: When set to false, Symbols will not be serialized. (default = true) | ||
### reviver | ||
@@ -112,0 +124,0 @@ |
@@ -87,2 +87,5 @@ import { window, document } from 'global'; | ||
if (isRegExp(value)) { | ||
if (!options.allowRegExp) { | ||
return undefined; | ||
} | ||
return `_regexp_${value.flags}|${value.source}`; | ||
@@ -92,2 +95,5 @@ } | ||
if (isFunction(value)) { | ||
if (!options.allowFunction) { | ||
return undefined; | ||
} | ||
const { name } = value; | ||
@@ -103,2 +109,5 @@ const stringified = value.toString(); | ||
if (isSymbol(value)) { | ||
if (!options.allowSymbol) { | ||
return undefined; | ||
} | ||
return `_symbol_${value.toString().slice(7, -1)}`; | ||
@@ -108,2 +117,5 @@ } | ||
if (typeof value === 'string' && dateFormat.test(value)) { | ||
if (!options.allowDate) { | ||
return undefined; | ||
} | ||
return `_date_${value}`; | ||
@@ -113,2 +125,5 @@ } | ||
if (value === undefined) { | ||
if (!options.allowUndefined) { | ||
return undefined; | ||
} | ||
return '_undefined_'; | ||
@@ -151,2 +166,6 @@ } | ||
) { | ||
if (!options.allowClass) { | ||
return undefined; | ||
} | ||
try { | ||
@@ -268,3 +287,14 @@ Object.assign(value, { '_constructor-name_': value.constructor.name }); | ||
const defaultOptions = { | ||
maxDepth: 10, | ||
space: undefined, | ||
allowFunction: true, | ||
allowRegExp: true, | ||
allowDate: true, | ||
allowClass: true, | ||
allowUndefined: true, | ||
allowSymbol: true, | ||
} | ||
export const stringify = (data, options = {}) => JSON.stringify(data, replacer(options.maxDepth || 10), options.space); | ||
export const parse = data => JSON.parse(data, reviver()); |
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
34207
7
8
630
135
- Removedsafe-eval@^0.4.1
- Removedsafe-eval@0.4.1(transitive)