@punks/backend-core 0.0.47 → 0.0.48
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +14 -2
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/utils/objects/index.d.ts +1 -0
- package/dist/esm/index.js +14 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/utils/objects/index.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
|
@@ -8,6 +8,7 @@ export declare const buildObject: <T>(...props: {
|
|
|
8
8
|
}[]) => T;
|
|
9
9
|
export declare const mergeDeep: <T>(a: any, b: any) => T;
|
|
10
10
|
export declare const jsonSerialize: (obj: any, options?: {
|
|
11
|
+
removeCircularReferences?: boolean;
|
|
11
12
|
stripBinaryData?: boolean;
|
|
12
13
|
maxStringsLength?: number;
|
|
13
14
|
prettify?: boolean;
|
package/dist/esm/index.js
CHANGED
|
@@ -288,13 +288,25 @@ const mergeDeep = (a, b) => {
|
|
|
288
288
|
return c;
|
|
289
289
|
};
|
|
290
290
|
const jsonSerialize = (obj, options) => {
|
|
291
|
-
const { stripBinaryData = true, prettify = false, maxStringsLength, } = options ?? {};
|
|
291
|
+
const { removeCircularReferences = true, stripBinaryData = true, prettify = false, maxStringsLength, } = options ?? {};
|
|
292
292
|
const replacer = (key, value) => {
|
|
293
|
-
|
|
293
|
+
// remove circular references
|
|
294
|
+
const seen = new WeakSet();
|
|
295
|
+
if (removeCircularReferences &&
|
|
296
|
+
typeof value === "object" &&
|
|
297
|
+
value !== null) {
|
|
298
|
+
if (seen.has(value)) {
|
|
299
|
+
return;
|
|
300
|
+
}
|
|
301
|
+
seen.add(value);
|
|
302
|
+
}
|
|
303
|
+
// trim long strings
|
|
304
|
+
if (maxStringsLength && typeof value === "string") {
|
|
294
305
|
return value.length > maxStringsLength
|
|
295
306
|
? `${value.substring(0, maxStringsLength)}...`
|
|
296
307
|
: value;
|
|
297
308
|
}
|
|
309
|
+
// strip binary data
|
|
298
310
|
if (stripBinaryData) {
|
|
299
311
|
if (value instanceof Buffer) {
|
|
300
312
|
return `<binary data (${value.length} bytes)>`;
|