JavaScript Reserved Identifiers

1.2.0 · active · verified Sun Apr 19

`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.

Common errors

Warnings

Install

Imports

Quickstart

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

view raw JSON →