@react-pug/is-expression
v0.1.7
Published
Check if a string is a valid JavaScript expression
Maintainers
Readme
@react-pug/is-expression
Validates a string as a JavaScript, TypeScript, or JSX expression.
Installation
npm install @react-pug/is-expressionUsage
isExpression(src[, options])
Validates a string as a JavaScript, TypeScript, or JSX expression.
src contains the source.
options currently supports:
throw: Throw the parser error if the string is not a valid expression. Defaults tofalse.
Examples
var isExpression = require('@react-pug/is-expression')
isExpression('myVar')
//=> true
isExpression('var')
//=> false
isExpression('["an", "array", "\'s"].indexOf("index")')
//=> true
isExpression('value as string')
//=> true
isExpression('<Button label="ok" />')
//=> true
isExpression('abc // my comment')
//=> true
isExpression('var', {throw: true})
// SyntaxError: Unexpected token (1:0)Notes
- This package is maintained in the
react-pugmonorepo. - It intentionally validates modern JavaScript, TypeScript, and JSX expression syntax.
- This fork reset version numbering under the
@react-pug/*namespace, so0.1.6is newer than the old upstream-style4.xline used before vendoring.
Attribution
This package is derived from the original pugjs/is-expression project:
https://github.com/pugjs/is-expression
License
MIT
