Add into to prelude #51

Closed
probablycorey wants to merge 1 commits from add-into into main

View File

@ -161,6 +161,19 @@ export const globals = {
return list
},
into: (value: unknown, type: Value['type']) => {
if (type === 'number') {
const num = Number(value)
if (isNaN(num)) throw new Error(`into: cannot convert ${value} to number`)
return num
} else if (type === 'string') {
return String(value)
} else if (type === 'boolean') {
return Boolean(value)
} else {
throw new Error(`into: unsupported target type ${type}`)
}
},
}
export const colors = {