chore(workflows-sdk, utils): Prevent unnecessary serialization (#13413)
* chore(workflows-sdk, utils): Prevent unnecessary serialization * Create poor-mugs-cheat.md
This commit is contained in:
@@ -58,6 +58,7 @@ export * from "./object-to-string-path"
|
||||
export * from "./omit-deep"
|
||||
export * from "./optional-numeric-serializer"
|
||||
export * from "./parse-cors-origins"
|
||||
export * from "./parse-stringify-if-necessary"
|
||||
export * from "./partition-array"
|
||||
export * from "./pick-deep"
|
||||
export * from "./pick-value-from-object"
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { isDefined } from "./is-defined"
|
||||
|
||||
/**
|
||||
* Only apply JSON.parse JSON.stringify when we have objects, arrays, dates, etc..
|
||||
* @param result
|
||||
* @returns
|
||||
*/
|
||||
export function parseStringifyIfNecessary(result: unknown) {
|
||||
if (typeof result !== "object") {
|
||||
return result
|
||||
}
|
||||
|
||||
const strResult = JSON.stringify(result)
|
||||
if (isDefined(strResult)) {
|
||||
return JSON.parse(strResult)
|
||||
}
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user