Skip to main content

numberValue

function

Build a SerializationSchema that returns `value` when it is a finite `number`, otherwise returns `defaultValue` (`0` by default). `NaN`, `Infinity`, and `-Infinity` are all treated as out of domain since they can not be round-tripped through JSON. A string spelled as a JSON number is accepted and converted, so a document that stored `"120"` where Lexical writes `120` — a hand-authored fixture, a converter, or a backend that stringified its numbers — keeps its value instead of silently falling back to the default. The domain is still numbers: that is what the schema reports and what parsing returns, a string is only an input encoding of it. Only the JSON grammar is read, so notations that JSON itself can not produce (`"0x10"`, `"1_000"`, `"+1"`, `"Infinity"`) stay out of domain.

function numberValue(defaultValue?: number, options?: NumberValueOptions): SerializationSchema<number, never, number | string>

Import

import { numberValue } from '@modular/sdk/editor';

Notes

__NO_SIDE_EFFECTS__