2
0

🗃️ Update non-string variable values in Database

This commit is contained in:
Baptiste Arnaud
2022-12-05 15:45:39 +01:00
parent d75eceb23f
commit 461d2e2746
3 changed files with 80 additions and 7 deletions

View File

@ -45,17 +45,16 @@ export const parseCorrectValueType = (
): string | boolean | number | null | undefined => {
if (value === null) return null
if (value === undefined) return undefined
const isNumberStartingWithZero =
value.startsWith('0') && !value.startsWith('0.') && value.length > 1
if (typeof value === 'string' && isNumberStartingWithZero) return value
if (typeof value === 'number') return value
if (value === 'true') return true
if (value === 'false') return false
if (value === 'null') return null
if (value === 'undefined') return undefined
// isNaN works with strings
if (isNaN(value as unknown as number)) return value
return Number(value)
try {
return JSON.parse(value)
} catch {
return value
}
}
const jsonParse = (str: string) =>