You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

is-expression

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-expression

Check if a string is a valid JavaScript expression


Version published
Weekly downloads
1.5M
increased by0.87%
Maintainers
2
Install size
546 kB
Created
Weekly downloads
 

Changelog

Source

2.1.0 - 2016-07-27

Added

  • Updated to acorn ~3.3.0
    • The ES2016 check for strict mode in function parameters is now implemented for {ecmaVersion: 7}.
    • See [acorn's CHANGELOG][acorn-3.3.0] for a full list of changes.

Readme

Source

is-expression

Validates a string as a JavaScript expression

Build Status Dependency Status npm version

Installation

npm install is-expression

Usage

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.

Examples

var isExpression = require('is-expression')

isExpression('myVar')
//=> true
isExpression('var')
//=> false
isExpression('["an", "array", "\'s"].indexOf("index")')
//=> true

isExpression('var', {throw: true})
// SyntaxError: Unexpected token (1:0)
//     at Parser.pp.raise (acorn/dist/acorn.js:940:13)
//     at ...

isExpression('public')
//=> true
isExpression('public', {strict: true})
//=> false

isExpression('abc // my comment')
//=> false
isExpression('abc // my comment', {lineComment: true})
//=> true

License

MIT

Keywords

FAQs

Package last updated on 26 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc