symbol.prototype.description

Spec-compliant shim for Symbol.prototype.description proposal.

MIT 9 个版本
安装
npm install symbol.prototype.description
yarn add symbol.prototype.description
pnpm add symbol.prototype.description
bun add symbol.prototype.description
README

Symbol.prototype.description Version Badge

github actions coverage License Downloads

npm badge

An ECMAScript spec-compliant Symbol.prototype.description shim. Invoke its "shim" method to shim Symbol.prototype.description if it is unavailable. Note: Symbol#description requires a true ES6 environment, specifically one with native Symbols (eg, node >= v11.15.0)

This package implements the es-shim API interface. It works in an ES6-supported environment and complies with the spec.

Most common usage:

var description = require('symbol.prototype.description');
var shimDescription = require('symbol.prototype.description/shim');
var assert = require('assert');

assert(description(Symbol('foo')) === 'foo');
assert(description(Symbol()) === undefined);
assert(description(Symbol(undefined)) === undefined);
assert(description(Symbol(null)) === 'null');

if (!('description' in Symbol.prototype)) {
	// note: this should be the empty string, but in many engines,
	// it is impossible to distinguish Symbol() and Symbol('')
	// without globally replacing `Symbol`
	assert(description(Symbol('')) === undefined);

	shimDescription();
}

assert(description(Symbol('foo')) === Symbol('foo').description);
assert(description(Symbol()) === Symbol().description);
assert(description(Symbol(undefined)) === Symbol(undefined).description);
assert(description(Symbol(null)) === Symbol(null).description);

assert(Symbol('').description === ''); // this works fine!

Tests

Simply clone the repo, npm install, and run npm test

版本列表
2.0.0 2025-12-11
1.0.7 2024-12-18
1.0.6 2024-02-15
1.0.5 2021-08-17
1.0.4 2021-02-21
1.0.3 2020-11-23
1.0.2 2019-12-14
1.0.1 2019-10-19
1.0.0 2018-01-23