JavaScript.validateVarname()

Determine whether the provided would be valid as the name of a ECMAScript 5.1 variable.

Usage

Hover over inputs/exits for more info.

var JavaScript = require('machinepack-javascript');


// Determine whether the provided would be valid as the name of a ECMAScript 5.1 variable.

JavaScript.validateVarname({

string: 'foo$barz',

}).execSync();

Inputs

string required

The string to inspect.

'foo$barz'

Exits

error

An unexpected error occurred.

invalid

The specified string cannot be coerced into a valid ECMAScript 5.1-compatible variable name. It might have inappropriate characters or collide with a JavaScript reserved word (e.g. `if` or `for`).

success

OK.