Added JSONSerialize
This commit is contained in:
parent
e8fdca8236
commit
2522635815
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@ztimson/utils",
|
"name": "@ztimson/utils",
|
||||||
"version": "0.23.1",
|
"version": "0.23.2",
|
||||||
"description": "Utility library",
|
"description": "Utility library",
|
||||||
"author": "Zak Timson",
|
"author": "Zak Timson",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
@ -224,6 +224,17 @@ export function JSONAttemptParse<T1, T2>(json: T2): T1 | T2 {
|
|||||||
catch { return json; }
|
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.
|
* Convert an object to a JSON string avoiding any circular references.
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user