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

20 lines
299 B
TypeScript
Raw Normal View History

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