safe-json-value
Advanced tools
Comparing version 1.4.1 to 1.4.2
@@ -44,3 +44,3 @@ import normalizeException from"normalize-exception"; | ||
typeof value.toJSON==="function"&& | ||
!(TO_JSON_RECURSION in value)); | ||
!TO_JSON_RECURSION.has(value)); | ||
@@ -55,11 +55,10 @@ }; | ||
const triggerToJSON=function(value){ | ||
value[TO_JSON_RECURSION]=true; | ||
const triggerToJSON=function(object){ | ||
TO_JSON_RECURSION.add(object); | ||
try{ | ||
return value.toJSON(); | ||
return object.toJSON(); | ||
}finally{ | ||
delete value[TO_JSON_RECURSION]; | ||
TO_JSON_RECURSION.delete(object); | ||
} | ||
@@ -69,3 +68,4 @@ }; | ||
const TO_JSON_RECURSION=Symbol("toJsonRecursion"); | ||
const TO_JSON_RECURSION=new WeakSet([]); | ||
//# sourceMappingURL=to_json.js.map |
{ | ||
"name": "safe-json-value", | ||
"version": "1.4.1", | ||
"version": "1.4.2", | ||
"type": "module", | ||
@@ -5,0 +5,0 @@ "exports": "./build/src/main.js", |
@@ -194,5 +194,5 @@ [![Codecov](https://img.shields.io/codecov/c/github/ehmicky/safe-json-value.svg?label=tested&logo=codecov)](https://codecov.io/gh/ehmicky/safe-json-value) | ||
```js | ||
const input = { toJSON: () => ({ one: true, input: { ...input } }) } | ||
const input = { toJSON: () => ({ one: true, input }) } | ||
JSON.stringify(input) // Throws due to infinite `toJSON()` recursion | ||
JSON.stringify(safeJsonValue(input).value) // '{"one":true,"input":{}}" | ||
JSON.stringify(safeJsonValue(input).value) // '{"one":true,"input":{...}}" | ||
``` | ||
@@ -199,0 +199,0 @@ |
Sorry, the diff of this file is not supported yet
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
77745
3849