Added JSONSerialize
This commit is contained in:
@ -224,6 +224,17 @@ export function JSONAttemptParse<T1, T2>(json: T2): T1 | T2 {
|
||||
catch { return json; }
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringifies objects & skips primitives
|
||||
*
|
||||
* @param {any} obj Object to convert to serializable value
|
||||
* @return {string | T} Serialized value
|
||||
*/
|
||||
export function JSONSerialize<T1>(obj: T1): T1 | string {
|
||||
if(typeof obj == 'object' && obj != null) return JSONSanitize(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert an object to a JSON string avoiding any circular references.
|
||||
*
|
||||
|
Reference in New Issue
Block a user