Registry / serialization / reserved-identifiers

reserved-identifiers

JSON →
library1.2.0jsnpmunverified

`reserved-identifiers` is a JavaScript library that provides a comprehensive `Set` of reserved identifiers according to the latest ECMAScript specification (currently ES2023) and module context. It offers a straightforward API to retrieve these identifiers, making it easy to check if a given string is reserved in modern JavaScript environments. The library also includes a dedicated export for TypeScript's built-in reserved types, useful for tooling that needs to validate type names. Maintained by Sindresorhus, the package typically sees stable, infrequent releases focused on incorporating new ECMAScript specifications or minor feature enhancements like the recent addition of TypeScript reserved types in v1.1.0 and strict mode identifiers in v1.2.0. Its primary differentiator is its strict adherence to modern JavaScript standards, intentionally omitting support for older JS versions. This focus ensures accuracy for current development practices, distinguishing it from libraries that might cater to a wider range of historical JS versions. The current stable version is 1.2.0.

npm install reserved-identifiers
INSTALL
IMPORT
SIG · RESERVED-IDENTIFIE
R
reserved-identifiers
serializationjavascriptv1.2.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.

reservedIdentifiers
import reservedIdentifiers from 'reserved-identifiers';
const reservedIdentifiers = require('reserved-identifiers');
This is the default export. The package is ESM-only and requires import syntax.
typeScriptReservedTypes
import { typeScriptReservedTypes } from 'reserved-identifiers';
import typeScriptReservedTypes from 'reserved-identifiers';
This is a named export. Available since v1.1.0.

Demonstrates importing both default and named exports, checking JavaScript reserved identifiers (with and without global properties), and checking TypeScript reserved types.

import reservedIdentifiers from 'reserved-identifiers'; import { typeScriptReservedTypes } from 'reserved-identifiers'; // Get the default set of reserved identifiers (ES2023 module context) const jsReserved = reservedIdentifiers(); const isJsReserved = (identifier) => jsReserved.has(identifier); console.log('Is "await" reserved?', isJsReserved('await')); //=> true console.log('Is "enum" reserved?', isJsReserved('enum')); //=> true console.log('Is "myVar" reserved?', isJsReserved('myVar')); //=> false // Get the set including common global properties const jsReservedWithGlobals = reservedIdentifiers({ includeGlobalProperties: true }); const isJsReservedWithGlobals = (identifier) => jsReservedWithGlobals.has(identifier); console.log('Is "undefined" reserved (default)?', isJsReserved('undefined')); //=> false console.log('Is "undefined" reserved (with globals)?', isJsReservedWithGlobals('undefined')); //=> true // Get TypeScript-specific reserved types const tsReservedTypes = typeScriptReservedTypes(); const isTsReservedType = (typeName) => tsReservedTypes.has(typeName); console.log('Is "any" a reserved TypeScript type?', isTsReservedType('any')); //=> true console.log('Is "string" a reserved TypeScript type?', isTsReservedType('string')); //=> true
Debug
Known issues
gotchaThe library explicitly assumes the latest JavaScript version (ES2023) and a module context. It does not support older JavaScript environments, which means certain identifiers might be considered reserved by this library but not by an older runtime, or vice-versa.
fix
Ensure your target environment supports ES2023 and ESM, or use a different library if older JavaScript compatibility is required.
affects: >=1.0.0
gotchaBy default, the `reservedIdentifiers()` set does not include global properties like `globalThis`, `Infinity`, `NaN`, or `undefined`. These are commonly avoided as identifiers but are not strictly 'reserved' by the ECMAScript spec.
fix
To include these in the returned set, initialize the set with `reservedIdentifiers({ includeGlobalProperties: true })`.
affects: >=1.0.0
breakingThe `typeScriptReservedTypes` named export was introduced in version 1.1.0. Attempting to use this export in versions prior to 1.1.0 will result in a `TypeError` or `undefined`.
fix
Upgrade to `reserved-identifiers@^1.1.0` or higher to utilize the `typeScriptReservedTypes` export.
affects: <1.1.0
breakingIn version 1.2.0, 'missing strict mode reserved identifiers' were added to the default set. This means the `Set` returned by `reservedIdentifiers()` may now contain more entries than in previous versions, potentially causing identifiers that were previously deemed non-reserved to now be considered reserved.
fix
Review code that relies on `isReserved` checks for compatibility, as more identifiers might now be flagged as reserved in applications upgrading from older versions.
affects: <1.2.0
Errors
Common errors & fixes
ReferenceError: require is not defined
Attempting to import the package using CommonJS `require()` syntax in an ESM-only context (e.g., a modern Node.js project with `type: "module"` or browser modules).
fix
Use ESM `import` syntax: `import reservedIdentifiers from 'reserved-identifiers';`
TypeError: reservedIdentifiers is not a function
Incorrectly attempting to import the default export `reservedIdentifiers` as a named export, e.g., `import { reservedIdentifiers } from 'reserved-identifiers';`.
fix
Use the correct default import syntax: `import reservedIdentifiers from 'reserved-identifiers';`
TypeError: Cannot read properties of undefined (reading 'typeScriptReservedTypes')
Attempting to use the `typeScriptReservedTypes` named export in a version of the library prior to v1.1.0, where it was introduced.
fix
Upgrade the package to `reserved-identifiers@^1.1.0` or higher using `npm install reserved-identifiers@latest`.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
reserved-identifiers — npm install reserved-identifiers · libregistry