@synergycodes/is-valid-var-name

1.0.3 • Public • Published

is-valid-var-name

It's fork of https://github.com/SteveWestbrook/is-valid-var-name

Single-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"]).

Special Thanks/Acknowledgements

This implementation draws heavily on the excellent research of Matthias Bynens, who did the legwork in explaining valid variable names for ES5 and ES6.

License

Copyright (c) 2017 Steve Westbrook

MIT

Package Sidebar

Install

npm i @synergycodes/is-valid-var-name

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

121 kB

Total Files

5

Last publish

Collaborators

  • tswistak_sc
  • artur.ptaszek.sc
  • przemyslaw.serwicki
  • dawid.aksamski.sc
  • mateuszdropinski