# pug-lexer

> The pug lexer (takes a string and converts it to an array of tokens)

Latest version **5.0.1** (published 2021-02-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install pug-lexer
pnpm add pug-lexer
yarn add pug-lexer
bun add pug-lexer
```

## Health

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

Positive: no vulnerabilities; popular repo.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 5.0.1 |
| Published | 2021-02-28 |
| First published | 2015-12-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 57.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 21847 |
| Author | ForbesLindesay |
| Maintainers | forbeslindesay, pug-bot |
| Keywords | pug |

## Links

- npm: https://www.npmjs.com/package/pug-lexer
- Repository: https://github.com/pugjs/pug/tree/master/packages/pug-lexer
- npm.io page: https://npm.io/package/pug-lexer

## Dependencies (3)

- [pug-error](https://npm.io/package/pug-error.md) ^2.0.0
- [is-expression](https://npm.io/package/is-expression.md) ^4.0.0
- [character-parser](https://npm.io/package/character-parser.md) ^2.2.0

## Recent versions

- 5.0.1 (latest) — 2021-02-28
- 5.0.1-canary-10 (canary) — 2021-02-28
- 5.0.1-canary-9 — 2021-02-28
- 5.0.1-canary-8 — 2021-02-28
- 5.0.1-canary-7 — 2021-02-28
- 5.0.0 — 2020-05-25
- 5.0.0-canary-2 — 2020-05-25
- 5.0.0-canary-1 — 2020-05-24
- 4.1.0 — 2019-06-18
- 4.0.0 — 2018-03-06
- 3.1.0 — 2017-04-18
- 3.0.0 — 2017-02-04
- 2.3.2 — 2017-01-29
- 2.3.1 — 2017-01-24
- 2.3.0 — 2016-09-12
- … 12 more at https://npm.io/package/pug-lexer/versions

## README

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

## Usage

```js
var lex = require('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.

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

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