Compatibility

Supported types in each mode, feature flags for older runtimes, and package resolution.

This page lists the types each mode supports, the feature flags for older runtimes, and how the packages resolve.

Supported types

The modes are:

  • Sync: serialize, toJSON, crossSerialize and toCrossJSON.
  • Async: serializeAsync, toJSONAsync, crossSerializeAsync and toCrossJSONAsync.
  • Streaming: crossSerializeStream, toCrossJSONStream and Serializer.
  • Binary: binary.serialize. See Binary mode.
TypeSyncAsyncStreamingBinary
string, boolean, null, undefined✅✅✅✅
number, including NaN, Infinity, -Infinity and -0✅✅✅✅
bigint✅✅✅✅
Array, including sparse arrays✅✅✅✅
Object and Object.create(null)✅✅✅✅
Frozen, sealed and non-extensible objects✅✅✅✅
Date✅✅✅✅
Boxed primitives, such as Object(1) and Object('text')✅✅✅✅
RegExp✅ 1✅ 1✅ 1✅ 1
Map and Set✅✅✅✅
ArrayBuffer and DataView✅✅✅✅ 2
Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array✅✅✅✅ 2
BigInt64Array and BigUint64Array✅ 3✅ 3✅ 3✅ 3 2
Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError and URIError✅ 4✅ 4✅ 4✅ 4
AggregateError✅ 5✅ 5✅ 5✅ 5
Temporal types✅ 6✅ 6✅ 6✅ 6
Promise❌ 7✅✅✅
Iterables (Symbol.iterator)✅✅✅✅
Async iterables (Symbol.asyncIterator)❌ 8✅✅✅
createStream✅ 9✅✅✅
createLiveStream❌ 10✅✅✅
Well-known symbols✅✅✅✅
Shared and cyclic references✅✅✅✅
Isomorphic references✅✅✅✅

Web types such as URL, Request and FormData are supported through plugins.

Feature flags

Every function takes a disabledFeatures option. It turns features off, so the output runs in older runtimes, or so a receiver rejects types it does not want.

disabledFeatures is a bit mask. Combine flags with |:

JavaScript
import { Feature, serialize } from 'seroval';

serialize(value, {
  disabledFeatures: Feature.AggregateError | Feature.BigIntTypedArray,
});
FlagWhen disabled
Feature.AggregateErrorAggregateError is sent as an Error.
Feature.ErrorPrototypeStackThe stack property of errors is not sent.
Feature.ObjectAssignOutput assigns properties one by one instead of calling Object.assign.
Feature.BigIntTypedArrayBigInt64Array and BigUint64Array are sent as iterable plain objects.
Feature.RegExpRegExp throws when serialized, and is rejected when decoded.
Feature.TemporalTemporal values throw when serialized, and are rejected when decoded.
Feature.ArrowFunctionDeprecated. It has no effect.

All features are on by default. For example, with ObjectAssign disabled:

JavaScript
const value = Object.assign(Object.create(null), { x: 1 });

serialize(value);
// Object.assign(Object.create(null),{x:1})

serialize(value, { disabledFeatures: Feature.ObjectAssign });
// (h=>h=(h=Object.create(null),h.x=1,h))()

Versions

seroval does not keep payloads compatible across versions. A minor release can change how a node is encoded in JavaScript, JSON and binary output. Serialize and deserialize with the same seroval version. When a server and a client are deployed separately, deploy them with the same version.

Runtimes

seroval runs anywhere modern JavaScript runs: Node.js 20 or later, Deno, Bun, browsers and edge runtimes. It has no dependencies.

Package resolution

The seroval package has ESM and CommonJS builds, and a development build with full error messages. Bundlers pick the right one through the package's export conditions:

  • The development condition selects the build with full error messages.
  • The default selects the production build, which reports errors by code. See Errors.
  • The browser condition selects the same build as the default, so there is never a second copy of seroval's classes or reference registry.

The seroval/read, seroval/write, seroval/shared and seroval/binary entry points use the same conditions. They load the same files as seroval, so mixing entry points does not create a second copy either. TypeScript resolves their types with the node10, node16, nodenext and bundler settings of moduleResolution.

Resolvers that ignore export conditions, such as older bundlers and some React Native setups, can use the main and module fields. The base64 encoding of buffers uses Buffer when it exists, and portable browser APIs otherwise. Both produce the same output. Binary mode does not use base64.

Footnotes

  1. Requires Feature.RegExp, which is on by default. When it is off, a RegExp throws SerovalUnsupportedTypeError. ↩ ↩2 ↩3 ↩4

  2. Binary mode rejects typed arrays longer than 1,000,000 elements and a DataView longer than 1,000,000 bytes. An ArrayBuffer is limited to 1,000,000 bytes by default. Set maxArrayBufferLength on binary.deserialize to change it. ↩ ↩2 ↩3

  3. Requires Feature.BigIntTypedArray, which is on by default. When it is off, these arrays are sent as iterable plain objects, not as typed arrays. ↩ ↩2 ↩3 ↩4

  4. The stack property is sent only while Feature.ErrorPrototypeStack is on. ↩ ↩2 ↩3 ↩4

  5. Sent as an Error when Feature.AggregateError is off. ↩ ↩2 ↩3 ↩4

  6. Requires Feature.Temporal, and a runtime that has the Temporal global on both sides. ↩ ↩2 ↩3 ↩4

  7. Sync functions cannot wait for promises, so a promise throws a SerovalParserError whose cause is a SerovalUnsupportedTypeError. ↩

  8. Sync functions cannot wait for values, so an async iterable throws a SerovalParserError whose cause is a SerovalUnsupportedTypeError. ↩

  9. Sync functions send a stream that has ended with all its events. A stream that is still open throws a SerovalParserError whose cause is a SerovalUnsupportedTypeError. ↩

  10. Sync functions cannot read a live stream, so it throws a SerovalParserError whose cause is a SerovalUnsupportedTypeError. ↩