defaultValue = structuredClone(defaultValue)

This commit is contained in:
2022-05-26 21:35:24 -05:00
parent a79b1ce565
commit 82ce66554c
9 changed files with 61 additions and 9 deletions

View File

@@ -4,6 +4,7 @@ export type JSONObject<Value = JSONDataTypes, Key extends string = string> = {
}
export function defaultJson<T>(data: any, defaultValue: T): T {
defaultValue = structuredClone(defaultValue)
if (typeof data !== 'object') {
return defaultValue
}
@@ -22,6 +23,7 @@ export function defaultJsonString(
data: string,
defaultValue: string | JSONObject = ''
): string {
defaultValue = structuredClone(defaultValue)
if (data.length === 0) {
//no existing data, give the default value instead