Check if a string is a valid JavaScript identifier
MIT License
Check if a string is a valid JavaScript identifier
npm install is-identifier
import isIdentifier from 'is-identifier';
isIdentifier('foo');
//=> true
isIdentifier('1kg');
//=> false
isIdentifier('await'); // Reserved identifier
//=> false
[!NOTE] Although
globalThis
,Infinity
,NaN
, andundefined
are properties of the global object and not identifiers, they are treated as reserved here because they should generally not be used as identifiers.
Returns a boolean for whether the given value is a valid JavaScript identifier.