From c04000c5cf30634cd3048be1c14c44bec59e6025 Mon Sep 17 00:00:00 2001 From: Hein Date: Thu, 8 May 2025 16:50:32 +0200 Subject: [PATCH] Added stringify_json --- src/object/decycle.ts | 15 ++++++++++++++- src/object/index.ts | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/object/decycle.ts b/src/object/decycle.ts index 9edb1f7..b8357d4 100644 --- a/src/object/decycle.ts +++ b/src/object/decycle.ts @@ -14,7 +14,7 @@ export interface RefObject { * @param replacer - Optional function to replace values during the process * @returns A decycled copy of the object */ -export function decycle( +export function decycle( object: T, replacer?: (value: any) => any ): any { @@ -130,4 +130,17 @@ export function retrocycle($: T): T { } }($)); return $; +} + +/** + * + * @description Converts a object with circular references to JSON + * @param json + * @param object + * @returns + */ +export function stringify_json( + object: T, +) { + return JSON.stringify(retrocycle(object)) } \ No newline at end of file diff --git a/src/object/index.ts b/src/object/index.ts index 6cd0c34..bb63fb9 100644 --- a/src/object/index.ts +++ b/src/object/index.ts @@ -1,5 +1,5 @@ export {getNestedValue,setNestedValue} from './nested' export {objectCompare} from './compare' export {createSelectOptions} from './util' -export {decycle,retrocycle} from './decycle' +export {decycle,retrocycle, stringify_json} from './decycle' export type {RefObject} from './decycle' \ No newline at end of file