tiptap/packages/core/src/utils/fromString.ts

20 lines
287 B
TypeScript
Raw Normal View History

2020-11-01 06:35:30 +08:00
export default function fromString(value: any) {
2020-11-01 06:56:31 +08:00
if (typeof value !== 'string') {
return value
}
2020-11-01 06:35:30 +08:00
if (value.match(/^\d*(\.\d+)?$/)) {
return Number(value)
}
if (value === 'true') {
return true
}
if (value === 'false') {
return false
}
return value
}