Name: is-expression
Owner: Pug
Description: Validates a string as a JavaScript expression
Created: 2015-11-12 01:31:44.0
Updated: 2017-04-24 22:23:18.0
Pushed: 2018-05-07 15:27:11.0
Size: 20
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Validates a string as a JavaScript expression
npm install is-expression
isExpression(src[, options])
Validates a string as a JavaScript expression.
src
contains the source.
options
can contain any Acorn options (since we use Acorn under-the-hood),
or any of the following:
throw
: Throw an error if the string is not an expression. The error can
be an Acorn error, with location information in err.loc
and err.pos
.
Defaults to false
.strict
: Use strict mode when trying to parse the string. Defaults to
false
. Even if this option is false
, if you have provided
options.sourceType === 'module'
which imples strict mode under ES2015,
strict mode will be used.lineComment
: When true
, allows line comments in the expression.
Defaults to false
for safety.See the examples below for usage.
isExpression = require('is-expression')
pression('myVar')
true
pression('var')
false
pression('["an", "array", "\'s"].indexOf("index")')
true
pression('var', {throw: true})
yntaxError: Unexpected token (1:0)
at Parser.pp.raise (acorn/dist/acorn.js:940:13)
at ...
pression('public')
true
pression('public', {strict: true})
false
pression('abc // my comment')
false
pression('abc // my comment', {lineComment: true})
true
MIT