Added stringify_json

This commit is contained in:
Hein 2025-05-08 16:50:32 +02:00
parent 4058dd37f8
commit c04000c5cf
2 changed files with 15 additions and 2 deletions

View File

@ -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<T>(
export function decycle<T=any>(
object: T,
replacer?: (value: any) => any
): any {
@ -130,4 +130,17 @@ export function retrocycle<T>($: T): T {
}
}($));
return $;
}
/**
*
* @description Converts a object with circular references to JSON
* @param json
* @param object
* @returns
*/
export function stringify_json<T=any>(
object: T,
) {
return JSON.stringify(retrocycle(object))
}

View File

@ -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'