Determines whether a string is a valid javascript variable name. ES2015 and ES5 compatibility. Strict mode evaluation by default.
npm install is-valid-var-nameSingle-purpose node module that determines whether a string is a valid javascript variable.
This implementation has been optimized for performance.
The primary function is ES6 compatible; ES5 variable names can also be validated.
``
const isVarName = require('is-valid-var-name');
// true
var isValid = isVarName('x');
// false
isValid = isVarName(' not a var ');
// win the respect of your colleagues with this highly maintainable code
isValid = isVarName('ᚢᚫᚱ');
`
Installation
``
$ npm install is-valid-var-name
Options
By default, the validation function assumes ES2015 strict mode. These values can be overridden.
To provide ES5 evaluation:
`
const isVarName = require('is-valid-var-name').es5;
// valid under ES5
isValid = isVarName('await');
`
To turn off strict mode evaluation:
`
// Turn off strict mode evaluation
isVarName.strict = false;
// valid when strict mode is off
isValid = isVarName('arguments');
``
What about other identifiers?
This module validates variable names, but is not intended to validate more complex identifiers such as multi-part values (a.b.c) or string-accessible properties (a["null"]).