open-index/open-npm huggingface dataset:
npm package: @react-pug/is-expression
Description: Check if a string is a valid JavaScript expression
Author: Timothy Gu
Latest version: 0.1.7

# @react-pug/is-expression

Validates a string as a JavaScript, TypeScript, or JSX expression.

[![Build Status](https://img.shields.io/github/workflow/status/pugjs/is-expression/Test/master)](https://github.com/pugjs/is-expression/actions?query=branch%3Amaster+workflow%3ATest)
[![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 @react-pug/is-expression

## Usage

### `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 to `false`.

## Examples

```js
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-pug` monorepo.
- It intentionally validates modern JavaScript, TypeScript, and JSX expression syntax.
- This fork reset version numbering under the `@react-pug/*` namespace, so `0.1.6` is newer than the old upstream-style `4.x` line used before vendoring.

## Attribution

This package is derived from the original `pugjs/is-expression` project:

https://github.com/pugjs/is-expression

## License

MIT
npm package: @react-pug/pug-lexer
Description: The pug lexer (takes a string and converts it to an array of tokens)
Author: ForbesLindesay
Latest version: 0.1.7

# @react-pug/pug-lexer

The Pug lexer. This module is responsible for taking a string and converting it into an array of tokens.

[![Build Status](https://img.shields.io/travis/pugjs/pug-lexer/master.svg)](https://travis-ci.org/pugjs/pug-lexer)
[![Dependencies Status](https://david-dm.org/pugjs/pug/status.svg?path=packages/pug-lexer)](https://david-dm.org/pugjs/pug?path=packages/pug-lexer)
[![DevDependencies Status](https://david-dm.org/pugjs/pug/dev-status.svg?path=packages/pug-lexer)](https://david-dm.org/pugjs/pug?path=packages/pug-lexer&type=dev)
[![NPM version](https://img.shields.io/npm/v/pug-lexer.svg)](https://www.npmjs.org/package/pug-lexer)
[![Coverage Status](https://img.shields.io/codecov/c/github/pugjs/pug-lexer.svg)](https://codecov.io/gh/pugjs/pug-lexer)

## Installation

    npm install @react-pug/pug-lexer

## Usage

```js
var lex = require('@react-pug/pug-lexer');
```

### `lex(str, options)`

Convert Pug string to an array of tokens.

`options` can contain the following properties:

- `filename` (string): The name of the Pug file; it is used in error handling if provided.
- `plugins` (array): An array of plugins, in the order they should be applied.

For `react-pug` usage, this fork also supports modern TypeScript expression syntax inside Pug expressions and attributes, including `as`, `satisfies`, typed inline handlers, and spread attrs with TS casts.

```js
console.log(JSON.stringify(lex('div(data-foo="bar")', {filename: 'my-file.pug'}), null, '  '))
```

```json
[
  {
    "type": "tag",
    "line": 1,
    "val": "div",
    "selfClosing": false
  },
  {
    "type": "attrs",
    "line": 1,
    "attrs": [
      {
        "name": "data-foo",
        "val": "\"bar\"",
        "escaped": true
      }
    ]
  },
  {
    "type": "eos",
    "line": 1
  }
]
```

### `new lex.Lexer(str, options)`

Constructor for a Lexer class. This is not meant to be used directly unless you know what you are doing.

`options` may contain the following properties:

- `filename` (string): The name of the Pug file; it is used in error handling if provided.
- `interpolated` (boolean): if the Lexer is created as a child lexer for inline tag interpolation (e.g. `#[p Hello]`). Defaults to `false`.
- `startingLine` (integer): the real line number of the first line in the input. It is also used for inline tag interpolation. Defaults to `1`.
- `plugins` (array): An array of plugins, in the order they should be applied.

## License

  MIT

## Notes

- This package is maintained in the `react-pug` monorepo.
- It is a forked, vendored copy aligned with `react-pug`'s TypeScript-in-Pug requirements.
- Version numbering was reset under the `@react-pug/*` namespace, so `0.1.6` is newer than the older upstream-derived `4.x` package line previously used here.

## Attribution

This package is derived from the original `pug-lexer` package in the `pugjs/pug` monorepo:

https://github.com/pugjs/pug/tree/master/packages/pug-lexer