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#
npm install @rcompat/symbolpnpm add @rcompat/symbolyarn add @rcompat/symbolbun add @rcompat/symbolUsage#
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#
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#
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.