Socket
Socket
Sign inDemoInstall

@scaleforge/joser

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @scaleforge/joser

Javascript object serializer


Version published
Maintainers
1
Created

Readme

Source

joser (Javascript Object Serializer)

const joser = new Joser();

const obj = {
  number: 1,
  string: 'string',
  boolean: true,
  null: null,
  Date: new Date('2023-04-25T00:00:00Z'),
  Buffer: Buffer.from([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
};

const serialized = joser.serialize(obj);

assert.deepEqual(serialized, {
  number: 1,
  string: 'string',
  boolean: true,
  null: null,
  Date: 1682380800000,
  Buffer: '00010203040506070809',
  __t: {
    Date: 'Date',
    Buffer: 'Buffer',
  },
});

assert.deepEqual(joser.deserialize(serialized), obj);

Built-in serializers

Joser has built-in serializers for the following NodeJS classes:

  • Date
  • Buffer
  • Set
  • Map

Custom serializers

It is also possible to provide custom serializers for custom classes. For example, to serialize the custom class ObjectId:

const joser = new Joser({
  serializers: [
    {
      type: ObjectId,
      serialize: (value: ObjectId) => value.toString(),
      deserialize: (raw: string) => ObjectId.from(raw),
    },
  ]
});

Keywords

FAQs

Last updated on 03 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc