What is typeson-registry?
The typeson-registry npm package is a collection of types for Typeson, a library that allows you to serialize and deserialize JavaScript objects with custom types. It provides a registry of common types that can be used to extend the functionality of Typeson.
What are typeson-registry's main functionalities?
Date Serialization
This feature allows you to serialize and deserialize Date objects. The code sample demonstrates how to register the date type from typeson-registry and use it to serialize and deserialize a Date object.
{"import":"import Typeson from 'typeson';\nimport typesonRegistry from 'typeson-registry';","usage":"const typeson = new Typeson().register(typesonRegistry.date);\nconst serialized = typeson.stringify(new Date());\nconst deserialized = typeson.parse(serialized);"}
Set Serialization
This feature allows you to serialize and deserialize Set objects. The code sample demonstrates how to register the set type from typeson-registry and use it to serialize and deserialize a Set object.
{"import":"import Typeson from 'typeson';\nimport typesonRegistry from 'typeson-registry';","usage":"const typeson = new Typeson().register(typesonRegistry.set);\nconst serialized = typeson.stringify(new Set([1, 2, 3]));\nconst deserialized = typeson.parse(serialized);"}
Map Serialization
This feature allows you to serialize and deserialize Map objects. The code sample demonstrates how to register the map type from typeson-registry and use it to serialize and deserialize a Map object.
{"import":"import Typeson from 'typeson';\nimport typesonRegistry from 'typeson-registry';","usage":"const typeson = new Typeson().register(typesonRegistry.map);\nconst serialized = typeson.stringify(new Map([[1, 'one'], [2, 'two']]));\nconst deserialized = typeson.parse(serialized);"}
Other packages similar to typeson-registry
superjson
SuperJSON is a library that allows you to serialize JavaScript objects containing more complex data types like Dates, Maps, Sets, and more. It is similar to typeson-registry in that it provides serialization and deserialization capabilities for complex types, but it is designed to work seamlessly with Next.js and other modern frameworks.
flatted
Flatted is a library that allows you to serialize and deserialize JavaScript objects with circular references. While it does not provide the same type registry as typeson-registry, it offers a solution for handling circular references, which can be a limitation in standard JSON serialization.
circular-json
CircularJSON is another library for serializing and deserializing JavaScript objects with circular references. It is similar to flatted but offers a different approach to handling circular references. Unlike typeson-registry, it does not provide a registry of types but focuses on solving the circular reference problem.