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 * @param replacer - Optional function to replace values during the process
* @returns A decycled copy of the object * @returns A decycled copy of the object
*/ */
export function decycle<T>( export function decycle<T=any>(
object: T, object: T,
replacer?: (value: any) => any replacer?: (value: any) => any
): any { ): any {
@ -131,3 +131,16 @@ export function retrocycle<T>($: T): T {
}($)); }($));
return $; 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 {getNestedValue,setNestedValue} from './nested'
export {objectCompare} from './compare' export {objectCompare} from './compare'
export {createSelectOptions} from './util' export {createSelectOptions} from './util'
export {decycle,retrocycle} from './decycle' export {decycle,retrocycle, stringify_json} from './decycle'
export type {RefObject} from './decycle' export type {RefObject} from './decycle'