diff --git a/package-lock.json b/package-lock.json index 6ced5cb..7232003 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@ztimson/utils", - "version": "0.2.4", + "version": "0.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@ztimson/utils", - "version": "0.2.4", + "version": "0.3.0", "license": "MIT", "devDependencies": { "@types/jest": "^29.5.12", diff --git a/package.json b/package.json index 25bce9a..da70d9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/utils", - "version": "0.2.4", + "version": "0.3.0", "description": "Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/objects.ts b/src/objects.ts index 8bb2118..b26491a 100644 --- a/src/objects.ts +++ b/src/objects.ts @@ -153,3 +153,14 @@ export function mixin(target: any, constructors: any[]) { }); }); } + +export function sanitizedJSON(obj: any, space?: number) { + let cache: any[] = []; + return JSON.parse(JSON.stringify(obj, (key, value) => { + if (typeof value === 'object' && value !== null) { + if (cache.includes(value)) return; + cache.push(value); + } + return value; + }, space)); +}