✨ Introducing The Forge (#1072)
The Forge allows anyone to easily create their own Typebot Block. Closes #380
This commit is contained in:
22
packages/variables/parseGuessedValueType.ts
Normal file
22
packages/variables/parseGuessedValueType.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { Variable } from '@typebot.io/schemas'
|
||||
|
||||
export const parseGuessedValueType = (
|
||||
value: Variable['value']
|
||||
): string | (string | null)[] | boolean | number | null | undefined => {
|
||||
if (value === null) return null
|
||||
if (value === undefined) return undefined
|
||||
if (typeof value !== 'string') return value
|
||||
const isStartingWithZero =
|
||||
value.startsWith('0') && !value.startsWith('0.') && value.length > 1
|
||||
if (typeof value === 'string' && isStartingWithZero) return value
|
||||
const isStartingWithPlus = value.startsWith('+')
|
||||
if (typeof value === 'string' && isStartingWithPlus) 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)
|
||||
}
|
||||
Reference in New Issue
Block a user