Registry / serialization / teleport-javascript

teleport-javascript

JSON →
library1.0.0jsnpmunverified

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.

npm install teleport-javascript
INSTALL
IMPORT
SIG · TELEPORT-JAVASCRIP
T
teleport-javascript
serializationjavascriptv1.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse, stringify
import { parse, stringify } from 'teleport-javascript';
const {parse, stringify} = require('teleport-javascript');
For ESM environments, use named imports. CommonJS `require` is also supported.
parse, stringify
const { parse, stringify } = require('teleport-javascript');
import { parse, stringify } from 'teleport-javascript';
For CommonJS environments, use destructuring assignment with `require`.
teleport
import * as teleport from 'teleport-javascript';
import teleport from 'teleport-javascript';
The library exports named functions, not a default export. Use `* as` for grouping if preferred.

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);
Debug
Known issues
gotchaWhen a `Symbol` is serialized and then deserialized, `teleport-javascript` creates a *new* `Symbol` with the same description, rather than preserving the original `Symbol` reference. This is standard behavior for serialization, but important to note if strict reference equality for `Symbol`s is expected.
fix
If exact `Symbol` reference preservation is critical, consider alternative strategies like passing `Symbol`s out-of-band or using a different serialization approach specifically designed for reference tracking beyond object graphs.
affects: >=1.0.0
gotchaAs with any custom deserialization library, parsing stringified data from untrusted sources carries inherent security risks. While `teleport-javascript` reconstructs objects without executing arbitrary code, specially crafted malicious input could potentially lead to unexpected object structures, resource exhaustion, or other application-specific vulnerabilities.
fix
Avoid deserializing input from untrusted sources. If absolutely necessary, sanitize or validate inputs rigorously before passing them to `parse`, and implement robust error handling and resource limits.
affects: >=1.0.0
gotcha`teleport-javascript` extends `JSON.stringify`'s capabilities by supporting types like `undefined`, `BigInt`, and `Set` which `JSON.stringify` either omits or throws on. Users expecting strict JSON-compliant output or the default `JSON.stringify` behavior (e.g., omitting `undefined` properties) should be aware of these differences.
fix
Understand the full list of supported types and how they are handled. If strict `JSON.stringify` behavior is needed for a subset of the data, use `JSON.stringify` directly on that subset.
affects: >=1.0.0
Errors
Common errors & fixes
ReferenceError: require is not defined in ES module scope
Attempting to use CommonJS `require()` syntax within an ES Module (type: 'module' in package.json or .mjs file).
fix
Change `const {parse, stringify} = require('teleport-javascript');` to `import { parse, stringify } from 'teleport-javascript';`
TypeError: stringify is not a function
Attempting to call `stringify()` or `parse()` directly after a default import, or if the named imports were missed in destructuring.
fix
Ensure you are using named imports: `import { parse, stringify } from 'teleport-javascript';` or `const { parse, stringify } = require('teleport-javascript');`
TypeError: Cannot convert a BigInt value to a JSON string
Trying to serialize an object containing a `BigInt` using the native `JSON.stringify()` method, which does not support `BigInt`s by default.
fix
Use `teleport-javascript`'s `stringify` function instead: `const stringified = stringify(objWithBigInt);`
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Amazon
1
OpenAI (training)
1
Resources
teleport-javascript — npm install teleport-javascript · libregistry