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

20 lines
291 B
TypeScript
Raw Normal View History

export 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
}