is-identifier

Check if a string is a valid JavaScript identifier

MIT 2 个版本
安装
npm install is-identifier
yarn add is-identifier
pnpm add is-identifier
bun add is-identifier
README

is-identifier

Check if a string is a valid JavaScript identifier

Install

npm install is-identifier

Usage

import isIdentifier from 'is-identifier';

isIdentifier('foo');
//=> true

isIdentifier('1kg');
//=> false

isIdentifier('await'); // Reserved identifier
//=> false

[!NOTE] Although globalThis, Infinity, NaN, and undefined are properties of the global object and not identifiers, they are treated as reserved here because they should generally not be used as identifiers.

API

isIdentifier(value)

Returns a boolean for whether the given value is a valid JavaScript identifier.

版本列表
1.0.1 2024-07-12
1.0.0 2024-05-05