Teleport JavaScript Object (De)serialization

1.0.0 · active · verified Sun Apr 19

Teleport JavaScript is a specialized utility for the deep serialization and deserialization of JavaScript objects, extending far beyond the capabilities of the native `JSON.stringify` and `JSON.parse` methods. Currently stable at version 1.0.0, this library provides robust handling for a wide array of data types including `Date`, `BigInt`, `RegExp`, `Symbol`, `Set`, `Map`, `Buffer`, `undefined`, and all Typed Arrays (e.g., `Int8Array`, `Float64Array`). A key differentiator is its ability to correctly manage circular references within objects, preventing common serialization errors. While a specific release cadence isn't published, its current version suggests a focus on stability for its comprehensive feature set. It positions itself as a 'super light and fast' alternative for scenarios where standard JSON falls short, making it suitable for inter-process communication, storage, or deep cloning of complex JavaScript data structures. It prioritizes covering edge cases and modern JavaScript types for complete object graph preservation.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of `stringify` and `parse` for a complex object including `BigInt`, `RegExp`, `Set`, `Symbol`, `Date`, `undefined`, and circular references.

import { parse, stringify } from 'teleport-javascript';

const obj = {
  key: 'value',
  undefined: undefined,
  regex: /a-z/gi,
  set: new Set([-Infinity, NaN, Infinity]),
  bigint: 900719925474099123n,
  symbol: Symbol('key'),
  date: new Date()
};
obj.circular = obj; // Add a circular reference

console.log('Original object:', obj);

const stringified = stringify(obj);
console.log('\nStringified output:', stringified);

const parsed = parse(stringified);
console.log('\nParsed object:', parsed);

// Verify circular reference is re-established
console.log('Are circular references restored?', parsed.circular === parsed);
// Verify BigInt and Date types
console.log('BigInt type preserved?', typeof parsed.bigint === 'bigint');
console.log('Date type preserved?', parsed.date instanceof Date);

view raw JSON →