Check ECMAScript Identifier Names

3.0.0 · active · verified Sun Apr 19

estree-util-is-identifier-name is a focused utility from the unified collective designed to determine whether a given string or Unicode code point can constitute a valid ECMAScript (JavaScript) identifier name. The package, currently at stable version 3.0.0, provides functions like `name` to validate full identifier strings, and `start` and `cont` to check individual code points for starting or continuing an identifier. Major releases, such as v3.0.0, typically coincide with updates to Node.js compatibility (now requiring Node.js 16+) and significant internal changes like the adoption of `exports` for module resolution and enhanced Unicode support for astrals and code points. A key differentiator is its strict adherence to ECMAScript identifier rules, including optional support for JSX identifiers, while intentionally not handling language keywords. It's an ESM-only package since v2.0.0 and ships with full TypeScript types.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to validate full identifier names and individual code points for starting or continuing an identifier, including the optional JSX support.

import { cont, name, start } from 'estree-util-is-identifier-name';

// Check if a string is a valid identifier name
console.log('Is "$something69" a valid name?', name('$something69')); // => true
console.log('Is "69" a valid name?', name('69')); // => false
console.log('Is "var" a valid name (keywords are not handled here)?', name('var')); // => true

// Check if a code point can start an identifier
// 48 is the Unicode code point for '0'
console.log('Can code point 48 (for "0") start an identifier?', start(48)); // => false
// 97 is the Unicode code point for 'a'
console.log('Can code point 97 (for "a") start an identifier?', start(97)); // => true

// Check if a code point can continue an identifier
// 48 is the Unicode code point for '0'
console.log('Can code point 48 (for "0") continue an identifier?', cont(48)); // => true

// Example with JSX option for names that include hyphens
console.log('Is "my-component" a valid name (without JSX)?', name('my-component')); // => false
console.log('Is "my-component" a valid name (with JSX)?', name('my-component', { jsx: true })); // => true

view raw JSON →