{"id":11101,"library":"is-identifier","title":"is-identifier","description":"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.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/sindresorhus/is-identifier","tags":["javascript","identifier","keyword","word","check","test","reserved","ecmascript","typescript"],"install":[{"cmd":"npm install is-identifier","lang":"bash","label":"npm"},{"cmd":"yarn add is-identifier","lang":"bash","label":"yarn"},{"cmd":"pnpm add is-identifier","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library exports a default function. Do not use named imports.","wrong":"import { isIdentifier } from 'is-identifier';","symbol":"isIdentifier","correct":"import isIdentifier from 'is-identifier';"},{"note":"While Node.js v18+ supports ESM natively, CommonJS `require` is still supported, but `isIdentifier` is the default export.","wrong":"const { isIdentifier } = require('is-identifier');","symbol":"isIdentifier (CommonJS)","correct":"const isIdentifier = require('is-identifier');"}],"quickstart":{"code":"import isIdentifier from 'is-identifier';\n\n// Basic valid identifiers\nconsole.log(`'foo' is identifier: ${isIdentifier('foo')}`);\nconsole.log(`'$bar' is identifier: ${isIdentifier('$bar')}`);\nconsole.log(`'_baz' is identifier: ${isIdentifier('_baz')}`);\nconsole.log(`'myVariable123' is identifier: ${isIdentifier('myVariable123')}`);\n\n// Invalid identifiers\nconsole.log(`'1kg' is identifier: ${isIdentifier('1kg')}`);\nconsole.log(`'await' is identifier: ${isIdentifier('await')}`); // Reserved keyword\nconsole.log(`'my-variable' is identifier: ${isIdentifier('my-variable')}`);\nconsole.log(`'function' is identifier: ${isIdentifier('function')}`); // Reserved keyword\n\n// Special global properties treated as non-identifiers\nconsole.log(`'globalThis' is identifier: ${isIdentifier('globalThis')}`);\nconsole.log(`'Infinity' is identifier: ${isIdentifier('Infinity')}`);\nconsole.log(`'NaN' is identifier: ${isIdentifier('NaN')}`);\nconsole.log(`'undefined' is identifier: ${isIdentifier('undefined')}`);","lang":"javascript","description":"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."},"warnings":[{"fix":"No direct code change is typically required; this fix improves type correctness. Re-check any custom type assertions if issues arise.","message":"TypeScript 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.","severity":"gotcha","affected_versions":"=1.0.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always validate context-sensitive keywords like `await` using `isIdentifier` to ensure adherence to general JavaScript identifier rules, independent of execution context.","message":"The `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.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Ensure you are using `import isIdentifier from 'is-identifier';` (ESM) or `const isIdentifier = require('is-identifier');` (CommonJS) as it is a default export.","cause":"Incorrectly attempting to destructure the default import in some bundler configurations, or using a named import when the package only provides a default export.","error":"TypeError: (0 , is_identifier__WEBPACK_IMPORTED_MODULE_0__.default) is not a function"},{"fix":"Verify your import statement: `import isIdentifier from 'is-identifier';` for ESM, or `const isIdentifier = require('is-identifier');` for CommonJS environments.","cause":"Attempting to use `isIdentifier` without properly importing or requiring it, or using an incorrect import/require syntax.","error":"ReferenceError: isIdentifier is not defined"}],"ecosystem":"npm"}