Registry / serialization / is-identifier

is-identifier

JSON →
library1.0.1jsnpmunverified

The `is-identifier` package provides a highly focused utility to determine if a given string constitutes a valid JavaScript identifier according to ECMAScript specifications. Currently at stable version 1.0.1, this package follows Sindre Sorhus's typical release cadence of infrequent, targeted updates, primarily for bug fixes or minor spec clarifications, ensuring long-term stability. Its key differentiators include precise adherence to the JavaScript identifier rules, including reserved keywords (like `await`) and special global properties (like `globalThis`, `Infinity`, `NaN`, `undefined`) which it correctly treats as invalid identifiers for practical use, despite some not being strictly "keywords". It is a small, dependency-free module optimized for performant identifier validation, contrasting with broader AST parsing libraries.

npm install is-identifier
INSTALL
IMPORT
SIG · IS-IDENTIFIER
I
is-identifier
serializationjavascriptv1.0.1
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.

isIdentifier
import isIdentifier from 'is-identifier';
import { isIdentifier } from 'is-identifier';
The library exports a default function. Do not use named imports.
isIdentifier (CommonJS)
const isIdentifier = require('is-identifier');
const { isIdentifier } = require('is-identifier');
While Node.js v18+ supports ESM natively, CommonJS `require` is still supported, but `isIdentifier` is the default export.

Demonstrates how to import and use `isIdentifier` to check various strings for JavaScript identifier validity, including valid cases, invalid cases, reserved keywords, and special global properties treated as non-identifiers.

import isIdentifier from 'is-identifier'; // Basic valid identifiers console.log(`'foo' is identifier: ${isIdentifier('foo')}`); console.log(`'$bar' is identifier: ${isIdentifier('$bar')}`); console.log(`'_baz' is identifier: ${isIdentifier('_baz')}`); console.log(`'myVariable123' is identifier: ${isIdentifier('myVariable123')}`); // Invalid identifiers console.log(`'1kg' is identifier: ${isIdentifier('1kg')}`); console.log(`'await' is identifier: ${isIdentifier('await')}`); // Reserved keyword console.log(`'my-variable' is identifier: ${isIdentifier('my-variable')}`); console.log(`'function' is identifier: ${isIdentifier('function')}`); // Reserved keyword // Special global properties treated as non-identifiers console.log(`'globalThis' is identifier: ${isIdentifier('globalThis')}`); console.log(`'Infinity' is identifier: ${isIdentifier('Infinity')}`); console.log(`'NaN' is identifier: ${isIdentifier('NaN')}`); console.log(`'undefined' is identifier: ${isIdentifier('undefined')}`);
Debug
Known issues
gotchaTypeScript users upgrading from v1.0.0 might observe changes in type inference or validation. Version 1.0.1 removed an incorrect TypeScript type guard, which corrects the library's type behavior to align precisely with its runtime logic and ECMAScript identifier rules.
fix
No direct code change is typically required; this fix improves type correctness. Re-check any custom type assertions if issues arise.
affects: =1.0.0
gotchaThe library intentionally treats certain global properties (e.g., `globalThis`, `Infinity`, `NaN`, `undefined`) as invalid identifiers. While not strictly reserved keywords, using them as identifiers is generally ill-advised and this package enforces that practical restriction.
fix
Be aware of this specific behavior. If you require identifier validation that permits these global properties (against common best practices), this library might require a wrapper or an alternative.
affects: >=1.0.0
gotchaThe `await` keyword is correctly recognized and treated as a reserved identifier, causing `isIdentifier('await')` to return `false`. This holds true even in contexts where `await` might be valid within an `async` function, as the check is for general identifier validity.
fix
Always validate context-sensitive keywords like `await` using `isIdentifier` to ensure adherence to general JavaScript identifier rules, independent of execution context.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: (0 , is_identifier__WEBPACK_IMPORTED_MODULE_0__.default) is not a function
Incorrectly attempting to destructure the default import in some bundler configurations, or using a named import when the package only provides a default export.
fix
Ensure you are using `import isIdentifier from 'is-identifier';` (ESM) or `const isIdentifier = require('is-identifier');` (CommonJS) as it is a default export.
ReferenceError: isIdentifier is not defined
Attempting to use `isIdentifier` without properly importing or requiring it, or using an incorrect import/require syntax.
fix
Verify your import statement: `import isIdentifier from 'is-identifier';` for ESM, or `const isIdentifier = require('is-identifier');` for CommonJS environments.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
is-identifier — npm install is-identifier · libregistry