@poppinss/utils
Advanced tools
Comparing version 3.0.1 to 3.0.2
@@ -7,3 +7,3 @@ export declare const pick: (source: any, ...keys: (string | string[])[]) => any; | ||
export declare const unset: (source: any, key: string | string[]) => boolean; | ||
export declare const mergeWith: (source: any) => any; | ||
export declare const mergeWith: (source: any, ...otherArgs: any[]) => any; | ||
export declare const merge: (source: any, ...rest: any[]) => any; | ||
@@ -10,0 +10,0 @@ export declare const size: (source: any) => number; |
@@ -0,4 +1,6 @@ | ||
declare type ReplacerFn = (this: any, key: string, value: any) => any; | ||
/** | ||
* Safely stringifies a Javascript native value | ||
*/ | ||
export declare function safeStringify(value: any): string; | ||
export declare function safeStringify(value: any, replacer?: ReplacerFn, space?: string | number): string; | ||
export {}; |
@@ -17,9 +17,15 @@ "use strict"; | ||
/** | ||
* Replacer to remove Circular values all together | ||
* Replacer to handle bigints and remove Circular values all together | ||
*/ | ||
function replacer(_, value) { | ||
if (value === '[Circular]') { | ||
return; | ||
} | ||
return value; | ||
function jsonStringifyReplacer(replacer, removeCircular) { | ||
return function (key, value) { | ||
if (removeCircular && value === '[Circular]') { | ||
return; | ||
} | ||
const val = replacer ? replacer.call(this, key, value) : value; | ||
if (typeof val === 'bigint') { | ||
return val.toString(); | ||
} | ||
return val; | ||
}; | ||
} | ||
@@ -29,10 +35,10 @@ /** | ||
*/ | ||
function safeStringify(value) { | ||
function safeStringify(value, replacer, space) { | ||
try { | ||
return JSON.stringify(value); | ||
return JSON.stringify(value, jsonStringifyReplacer(replacer, false), space); | ||
} | ||
catch { | ||
return fast_safe_stringify_1.default(value, replacer); | ||
return fast_safe_stringify_1.default(value, jsonStringifyReplacer(replacer, true), space); | ||
} | ||
} | ||
exports.safeStringify = safeStringify; |
{ | ||
"name": "@poppinss/utils", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Handy utilities for repetitive work", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
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
117190
1968