seria
TypeScript icon, indicating that this package has built-in type declarations

0.2.0-beta4 • Public • Published

seria

npm CI

Seria is a serialization and deserialization library that goes beyond the conventional capabilities of JSON. It provides seamless handling for various data types, including those that JSON cannot handle directly.

This library is inspired on the new serialization capabilities react provides for server actions.

Installation

npm install seria
yarn add seria
pnpm add seria

Usage

Serialization and Deserialization

import * as seria from "seria";

const json = seria.stringify(value);
const value = seria.parse(json);

FormData Handling

Seria also supports encoding and decoding FormData:

import { encode, decode } from "seria/form-data";

const formData = encode(value);
const value = decode(formData);

Stream Handling

Seria provides stream-based serialization and deserialization:

import * as seria from "seria";

const stream = seria.stringifyToStream(value);
const result = await seria.parseFromStream(stream);

If you serialize a value that contains any Promise you need to serialize using a stream or use seria.stringifyAsync which resolve all the promises.

Supported Data Types

Types supported by seria in comparison with the standard JSON object.

Data Type seria.stringify/parse JSON.stringify/parse
string
number
boolean
null
undefined
Date
BigInt
Promise
AsyncGenerator
Symbol
Set
Map
Error
ArrayBuffer
TypedArrays*
DataView
File*
FormData*

Typed Arrays https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Typed_arrays

File and FormData are supported on seria/form-data.

seria also handles:

  • Infinity, -Infinity, NaN, -0
  • Cyclical references: obj.self = obj
  • Repeated references: [obj, new Set([obj]), new Map([["key", obj]])]
  • Custom types using replacers and revivers

See also

These libraries were used as references to improve seria features.

Package Sidebar

Install

npm i seria

Weekly Downloads

162

Version

0.2.0-beta4

License

MIT

Unpacked Size

972 kB

Total Files

176

Last publish

Collaborators

  • neociber94