diff --git a/package.json b/package.json index 02fbfd8..9b3dc4c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@ztimson/utils", - "version": "0.23.1", + "version": "0.23.2", "description": "Utility library", "author": "Zak Timson", "license": "MIT", diff --git a/src/objects.ts b/src/objects.ts index 0560e0e..bab46bf 100644 --- a/src/objects.ts +++ b/src/objects.ts @@ -224,6 +224,17 @@ export function JSONAttemptParse(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(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. *