Quickstart
Getting started with @nhtio/serialization is quick and easy. Just follow the steps below and you'll be up and running in no time.
Prerequisites
- Node.js version 22 or higher.
Installation
You can install @nhtio/serialization directly from your preferred package manager
sh
npm i @nhtio/serializationsh
pnpm add @nhtio/serializationsh
yarn add @nhtio/serializationUsing
This library exports 4 main methods:
typescript
import {
canSerialize,
confirm,
deserialize,
serialize
} from '@nhtio/serialization'To serialize a value, simply use the serialize method
typescript
const serialized = serialize(...);To return the value to its initial state, use the deserialize method
typescript
const initial = deserialize(serialized);Supported data types
This library wraps the v8:*serialize methods, adding support for the standard types supported out of the box by v8.serialize and v8.deserialize
- Javascript Primitives
- Typed Arrays containing encodable data
- Dates
- RegExps
- ArrayBuffers
- DataViews
- Arrays containing encodable data
- Plain Objects where the property keys are string and the values are encodable data
- Maps where the keys and values are encodable data
- Sets where the values are encodable data
- Errors but not classes which extend
Error - EvalErrors but not classes which extend
EvalError - RangeErrors but not classes which extend
RangeError - ReferenceErrors but not classes which extend
ReferenceError - SyntaxErrors but not classes which extend
SyntaxError - TypeErrors but not classes which extend
TypeError - URIErrors but not classes which extend
URIError
Additionally, this library also supports serialization/deserialization of the following types: