Quickstart
Getting started with @nhtio/web-serialization is quick and easy. Just follow the steps below and you'll be up and running in no time.
Installation
You can install @nhtio/web-serialization directly from your preferred package manager
sh
npm i @nhtio/web-serializationsh
pnpm add @nhtio/web-serializationsh
yarn add @nhtio/web-serializationUsing
This library exports 4 main methods:
typescript
import {
canSerialize,
confirm,
deserialize,
serialize
} from '@nhtio/web-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 add support for serialization / deserialization of the standard types supported out of the box by @ungap/structured-clone
- 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
Additionally, this library also supports serialization/deserialization of the following types: