Skip to content

About

Interfaces and utility for implementing serialization and serializable objects.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

@tsdotnet/serialization: Values to text, and back. Serialize primitives and your own types.

npm version GitHub license

Convert primitives and Serializable objects to strings with toString, and strings back with toPrimitive.

Install

npm install @tsdotnet/serialization

Usage

import { toString, toPrimitive } from '@tsdotnet/serialization';

toString(42);          // '42'
toString(true);        // 'true'
toPrimitive('3.5');    // 3.5
toPrimitive('false');  // false

toString also accepts any object with a serialize(): string method (Serializable). Unknown types throw unless you pass a default.

Use it from

ESM (import { toString, toPrimitive } from '@tsdotnet/serialization';) or CommonJS (const { toString, toPrimitive } = require('@tsdotnet/serialization');).

In a browser, without a bundler
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/exceptions@1/dist/umd/exceptions.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/type@1/dist/umd/type.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@tsdotnet/serialization@1/dist/umd/serialization.min.js"></script>
<script>
  const { toString, toPrimitive } = tsdotnet.serialization;
</script>

Docs

tsdotnet.github.io/serialization

About

Interfaces and utility for implementing serialization and serializable objects.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages