Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve documentation in README.md #34

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 48 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@

Generates regular expressions that match a set of strings.

## Table of Contents

- [Installation](#installation)
- [Example](#example)
- [API](#api)
- [CLI](#cli)
- [ES2015 and Unicode](#es2015-and-unicode)
- [How does it work?](#how-does-it-work)
- [License](#license)

## Installation

`regexgen` can be installed using [npm](https://npmjs.com):
`regexgen` can be installed using [npm](https://www.npmjs.com/package/regexgen):

```
npm install regexgen
Expand Down Expand Up @@ -32,6 +42,42 @@ t.add('foobaz');
t.toRegExp(); // => /fooba[rz]/
```

## API
### regexgen(inputs, flags)
Returns a regular expression that matches the given input strings.
| Parameter | Type | Description |
|--------------|-------------|-----------------------------------------------------------------------------------------------------------------------------|
| `inputs` | String Array|List of strings used to generate the regex |
| `flags` | String |Optional [flags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) to add to the regex|

### The `Trie` Class:
#### add(string)
Adds the given string to the trie.
| Parameter | Type | Description |
|--------------|-------------|-----------------|
| `string` | String |The string to add|

#### addAll(strings)
Adds the given array of strings to the trie.
| Parameter | Type | Description |
|--------------|-------------|---------------------------|
| `strings` | String Array|The array of strings to add|

#### minimize()
Returns a minimal DFA representing the strings in the trie.

#### toString(flags)
Returns a regex pattern that matches the strings in the trie.
| Parameter | Type | Description |
|--------------|-------------|-----------------------------------------------------------------------------------------------------------------------------|
| `flags` | String |Optional [flags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) to add to the regex|

#### toRegExp(flags)
Returns a regex that matches the strings in the trie.
| Parameter | Type | Description |
|--------------|-------------|-----------------------------------------------------------------------------------------------------------------------------|
| `flags` | String |Optional [flags](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) to add to the regex|

## CLI

`regexgen` also has a simple CLI to generate regexes using inputs from the command line.
Expand Down Expand Up @@ -82,4 +128,4 @@ Such regular expressions are compatible with current versions of Node, as well a

## License

MIT
`regexgen` is distributed under the MIT License.