Browse packages

Package · v0.3.0

symbol

Shared interoperability symbols

Shared interoperability symbols for JavaScript runtimes.

What is @rcompat/symbol?#

A cross-runtime module providing custom protocol symbols through JavaScript's global symbol registry. Using the same registry keys gives separately loaded copies of the package identical symbols across Node, Deno, Bun, and browsers.

Installation#

bash
npm install @rcompat/symbol
bash
pnpm add @rcompat/symbol
bash
yarn add @rcompat/symbol
bash
bun add @rcompat/symbol

Usage#

js
import symbol from "@rcompat/symbol";

// mark an object as parseable
class RequestBag {
  [symbol.parse]() {
    return this.toJSON();
  }
}

// mark an object as streamable
class FileRef {
  [symbol.stream]() {
    return this.toReadableStream();
  }
}

API Reference#

symbol.parse#

ts
import symbol from "@rcompat/symbol";

symbol.parse: unique symbol;

Denotes that an object can produce a plain representation of itself by calling [symbol.parse](). Validation libraries can look for this symbol and use it instead of requiring a plain object directly.

Registered globally as Symbol.for("std:symbol/parse").

symbol.stream#

ts
import symbol from "@rcompat/symbol";

symbol.stream: unique symbol;

Denotes that an object is streamable via [symbol.stream]().

Registered globally as Symbol.for("std:symbol/stream").

Cross-Runtime Compatibility#

Runtime Supported
Node.js ✓
Deno ✓
Bun ✓
Browser ✓

No configuration required — just import and use.

License#

MIT

Contributing#

See CONTRIBUTING.md in the repository root.