The `identifier-regex` package provides a precise regular expression function, `identifierRegex()`, designed to match valid JavaScript identifiers according to the ECMAScript specification. This includes proper handling of reserved words and specific syntax rules. The current stable version is 1.0.1, focusing on correctness and stability rather than rapid feature additions. Its primary differentiator is its strict adherence to JavaScript identifier rules, offering an `exact` option to control whether the regex matches the entire string or finds identifiers within a larger text. It explicitly excludes global properties like `Infinity` from being considered valid identifiers, aligning with common usage expectations. This library is ideal for parsers, linters, or any application needing to validate or extract JavaScript identifiers reliably.
npm install identifier-regexVerified import paths — ran on the pinned version, not inferred.
Demonstrates importing the `identifierRegex` function, using it to test strings for identifier validity (including reserved words), and extracting identifiers from longer strings with the `exact: false` option, while also showing it returns a `RegExp` instance.
Integrate with a regex timeout library like `super-regex` when processing untrusted input.
If you need to match these global properties specifically, you will need to augment the result of `identifierRegex()` with additional patterns or handle them separately.
Pass `{ exact: false }` to the `identifierRegex` function when matching substrings: `identifierRegex({ exact: false }).test('foo bar')`.Call `identifierRegex()` to obtain the regular expression object: `identifierRegex().test('foo')`.Ensure your project is configured as an ES module by adding `'type': 'module'` to your `package.json`, or use a bundler that transpiles ES modules to CJS for older environments. This package requires Node.js >=18, which has robust ESM support.
Set the `exact` option to `false` when you want to find identifiers within a larger string: `identifierRegex({ exact: false }).test('foo bar')`.No dependency data recorded yet.