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:
Adrien de Peretti
2025-09-04 16:19:35 +02:00
committed by GitHub
parent bd571aca82
commit 55a35e4721
5 changed files with 31 additions and 11 deletions
+1
View File
@@ -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
}