• Stars
    star
    147
  • Rank 243,650 (Top 5 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

The regular expression parser for ECMAScript.

regexpp

npm version Downloads/month Build Status codecov Dependency Status

A regular expression parser for ECMAScript.

💿 Installation

$ npm install regexpp
  • require Node.js 8 or newer.

📖 Usage

import {
    AST,
    RegExpParser,
    RegExpValidator,
    RegExpVisitor,
    parseRegExpLiteral,
    validateRegExpLiteral,
    visitRegExpAST
} from "regexpp"

parseRegExpLiteral(source, options?)

Parse a given regular expression literal then make AST object.

This is equivalent to new RegExpParser(options).parseLiteral(source).

  • Parameters:
    • source (string | RegExp) The source code to parse.
    • options? (RegExpParser.Options) The options to parse.
  • Return:
    • The AST of the regular expression.

validateRegExpLiteral(source, options?)

Validate a given regular expression literal.

This is equivalent to new RegExpValidator(options).validateLiteral(source).

  • Parameters:

visitRegExpAST(ast, handlers)

Visit each node of a given AST.

This is equivalent to new RegExpVisitor(handlers).visit(ast).

RegExpParser

new RegExpParser(options?)

parser.parseLiteral(source, start?, end?)

Parse a regular expression literal.

  • Parameters:
    • source (string) The source code to parse. E.g. "/abc/g".
    • start? (number) The start index in the source code. Default is 0.
    • end? (number) The end index in the source code. Default is source.length.
  • Return:
    • The AST of the regular expression.

parser.parsePattern(source, start?, end?, uFlag?)

Parse a regular expression pattern.

  • Parameters:
    • source (string) The source code to parse. E.g. "abc".
    • start? (number) The start index in the source code. Default is 0.
    • end? (number) The end index in the source code. Default is source.length.
    • uFlag? (boolean) The flag to enable Unicode mode.
  • Return:
    • The AST of the regular expression pattern.

parser.parseFlags(source, start?, end?)

Parse a regular expression flags.

  • Parameters:
    • source (string) The source code to parse. E.g. "gim".
    • start? (number) The start index in the source code. Default is 0.
    • end? (number) The end index in the source code. Default is source.length.
  • Return:
    • The AST of the regular expression flags.

RegExpValidator

new RegExpValidator(options)

validator.validateLiteral(source, start, end)

Validate a regular expression literal.

  • Parameters:
    • source (string) The source code to validate.
    • start? (number) The start index in the source code. Default is 0.
    • end? (number) The end index in the source code. Default is source.length.

validator.validatePattern(source, start, end, uFlag)

Validate a regular expression pattern.

  • Parameters:
    • source (string) The source code to validate.
    • start? (number) The start index in the source code. Default is 0.
    • end? (number) The end index in the source code. Default is source.length.
    • uFlag? (boolean) The flag to enable Unicode mode.

validator.validateFlags(source, start, end)

Validate a regular expression flags.

  • Parameters:
    • source (string) The source code to validate.
    • start? (number) The start index in the source code. Default is 0.
    • end? (number) The end index in the source code. Default is source.length.

RegExpVisitor

new RegExpVisitor(handlers)

visitor.visit(ast)

Validate a regular expression literal.

  • Parameters:

📰 Changelog

🍻 Contributing

Welcome contributing!

Please use GitHub's Issues/PRs.

Development Tools

  • npm test runs tests and measures coverage.
  • npm run build compiles TypeScript source code to index.js, index.js.map, and index.d.ts.
  • npm run clean removes the temporary files which are created by npm test and npm run build.
  • npm run lint runs ESLint.
  • npm run update:test updates test fixtures.
  • npm run update:ids updates src/unicode/ids.ts.
  • npm run watch runs tests with --watch option.

More Repositories

1

npm-run-all

A CLI tool to run multiple npm-scripts in parallel or sequential.
JavaScript
5,634
star
2

eslint-plugin-node

Additional ESLint's rules for Node.js
JavaScript
956
star
3

cpx

A cli tool to watch and copy file globs.
JavaScript
523
star
4

eslint-plugin-eslint-comments

Additional ESLint rules for directive comments of ESLint.
JavaScript
352
star
5

abort-controller

An implementation of WHATWG AbortController interface.
TypeScript
296
star
6

event-target-shim

An implementation of WHATWG EventTarget interface, plus few extensions.
TypeScript
118
star
7

eslint-plugin-es

ESLint plugin about ECMAScript syntactic features.
JavaScript
105
star
8

eslint-plugin-vue-trial

Experimental ESLint plugin for Vue.js.
JavaScript
90
star
9

eslint-utils

Utilities for ESLint plugins and custom rules.
JavaScript
70
star
10

eslint4b

ESLint which works in browsers.
JavaScript
37
star
11

vue-eslint-editor

A code editor component to play ESLint.
Vue
35
star
12

eslint-gitignore

A utility for ESLint respecting `.gitignore` files.
TypeScript
34
star
13

vue-eslint-demo

The online demo to check `eslint-plugin-vue`.
JavaScript
31
star
14

react-helix

A small library for immutable design and React.
JavaScript
26
star
15

eslint-plugin

ESLint configurations and additional rules for me
JavaScript
25
star
16

appcache-manifest

A CLI tool to generate HTML5 Application Cache Manifest.
JavaScript
25
star
17

eslint-plugin-dprint

An ESLint plugin that fixes code with dprint
TypeScript
23
star
18

template-eslint-plugin

A repository template for ESLint plugins.
JavaScript
16
star
19

if-node-version

Run a shell command if it's on the node of specified versions.
JavaScript
14
star
20

eslint-plugin-ja

ESLint のエラーメッセージを日本語化する非公式の実験的なプラグインです。
JavaScript
11
star
21

eaw

The Node.js module to calculate the width of east Asian characters.
JavaScript
10
star
22

bre

A Binary-Object Mapper for JavaScript
TypeScript
10
star
23

eslint-config

Shareable configurations of ESLint for me.
JavaScript
8
star
24

eslint-evaluating-issues

ESLint evaluating feature issues
JavaScript
8
star
25

spy

Just a spy library.
TypeScript
8
star
26

uptodate

A CLI tool to update dependencies in your package.json.
JavaScript
7
star
27

validia

An object validator library that is TypeScript friendly
TypeScript
7
star
28

eslint-ast

The Extensible Type Definition of ESLint AST
TypeScript
6
star
29

warun

CLI tool which does Watch and Run.
JavaScript
5
star
30

Yammer-for-Developers

[Chrome Extension] The code formater and highlighter in Yammer's messages.
JavaScript
5
star
31

typescript-eslint-demo

A playground for @typescript-eslint.
JavaScript
4
star
32

mocha-assert-snapshot

Snapshot test utilities for Mocha.
TypeScript
4
star
33

type-tester

A tester to check expected type errors
TypeScript
4
star
34

eslint-custom-rule-tutorial

JavaScript
3
star
35

event-source-shim

An implementation for `EventSource` of Server-sent events standard.
TypeScript
2
star
36

run-all

CLI tool to execute multiple commands parallelly.
JavaScript
2
star
37

eslint-plugin-utils

Tools to maintain ESLint plugins
2
star
38

react-helix-examples

Examples for react-helix library.
JavaScript
2
star
39

github-actions-sandbox

JavaScript
2
star
40

hetemel

A HTML parser to make AST which fits for linting.
1
star
41

tools

My tools
TypeScript
1
star
42

fs-watcher

Lightweight file system watchers.
TypeScript
1
star
43

webkit-test

HTML
1
star
44

simple-vue-app

A CLI command to build a simple Vue.js SPA with almost no configuration.
JavaScript
1
star
45

.github

1
star
46

ajx

Simple fetch library for me.
JavaScript
1
star
47

string-replace-unexpected-behavior

Is this a bug?
JavaScript
1
star