# is-expression

> Check if a string is a valid JavaScript expression

Latest version **4.0.0** (published 2020-05-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-expression
pnpm add is-expression
yarn add is-expression
bun add is-expression
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2020-05-19 |
| First published | 2015-11-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/is-expression) |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | Timothy Gu |
| Maintainers | forbeslindesay |
| Keywords | javascript, expression |

## Links

- npm: https://www.npmjs.com/package/is-expression
- Repository: https://github.com/pugjs/is-expression
- Homepage: https://github.com/pugjs/is-expression#readme
- Issues: https://github.com/pugjs/is-expression/issues
- npm.io page: https://npm.io/package/is-expression

## Dependencies (2)

- [acorn](https://npm.io/package/acorn.md) ^7.1.1
- [object-assign](https://npm.io/package/object-assign.md) ^4.1.1

## Recent versions

- 4.0.0 (latest) — 2020-05-19
- 3.0.0 — 2016-09-12
- 2.1.0 — 2016-07-26
- 2.0.1 — 2016-06-04
- 2.0.0 — 2016-02-13
- 1.0.2 — 2016-01-07
- 1.0.1 — 2015-11-12
- 1.0.0 — 2015-11-12

## README

# is-expression

Validates a string as a JavaScript expression

[![Build Status](https://img.shields.io/travis/pugjs/is-expression/master.svg)](https://travis-ci.org/pugjs/is-expression)
[![Dependency Status](https://img.shields.io/david/pugjs/is-expression.svg)](https://david-dm.org/pugjs/is-expression)
[![Rolling Versions](https://img.shields.io/badge/Rolling%20Versions-Enabled-brightgreen)](https://rollingversions.com/pugjs/is-expression)
[![npm version](https://img.shields.io/npm/v/is-expression.svg)](https://www.npmjs.org/package/is-expression)

## 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

```js
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

---
_Source: https://npm.io/package/is-expression · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
