#Serialize to JavaScript
Options: plugins, disabledFeatures, depthLimit, compactArrayBufferViews.
#JSON
| Function | Returns | Guide |
|---|
toJSON(value, options?) | SerovalJSON | JSON |
toJSONAsync(value, options?) | Promise<SerovalJSON> | JSON |
fromJSON(tree, options?) | the value | JSON |
compileJSON(tree, options?) | string | JSON |
fromJSON options: plugins, disabledFeatures, depthLimit, maxBase64Length. compileJSON options: plugins.
#Cross-reference
#Streams
| Export | Description | Guide |
|---|
createStream() | Creates a stream that keeps every value. | Streams |
isStream(value) | Whether a value is a seroval stream. | |
createLiveStream(options?) | Creates a single-reader stream with backpressure. Returns { stream, producer }. | Live streams |
isLiveStream(value) | Whether a value is a live stream. | |
#References and plugins
#Options
All options in one place. Each function lists the ones it accepts above.
| Option | Type | Default | Description |
|---|
plugins | Plugin[] | none | Plugins for extra types. |
disabledFeatures | number | 0 | Feature flags to turn off, combined with |. |
depthLimit | number | 1000 | Maximum nesting depth. |
compactArrayBufferViews | boolean | false | Send only the bytes each typed array covers. |
refs | Map | a new Map | Values already sent, shared between cross-reference calls. |
scopeId | string | none | Writes to $R[scopeId] instead of $R. |
assignSharedRefsOnly | boolean | false | crossSerialize and crossSerializeAsync only. Stores only the values the output reads more than once in $R. |
maxBase64Length | number | 1000000 | Largest encoded ArrayBuffer that JSON decoding accepts. |
onSerialize(chunk, initial) | function | required | Receives each script chunk of a stream. |
onParse(node, initial) | function | required | Receives each JSON node of a stream. |
onDone() | function | none | Runs when a stream finishes. |
onError(error) | function | none | Runs when a stream fails. |
#Types
seroval also exports TypeScript types for the values above, including SerovalJSON, SerovalNode, Plugin, SerializeOptions, SerializeAsyncOptions, ToJSONOptions, ToJSONAsyncOptions, CrossSerializeOptions, Stream, StreamListener, LiveStream, LiveStreamProducer, LiveStreamConsumer, CrossDeserializer and the options type of each function.