Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/IMax153/expressive-ts
A functional programming library designed to simplify building complex regular expressions
https://github.com/IMax153/expressive-ts
functional-programming javascript regex regular-expressions typescript
Last synced: 12 days ago
JSON representation
A functional programming library designed to simplify building complex regular expressions
- Host: GitHub
- URL: https://github.com/IMax153/expressive-ts
- Owner: IMax153
- License: mit
- Created: 2020-08-04T20:04:10.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T20:44:39.000Z (almost 2 years ago)
- Last Synced: 2024-10-26T20:41:05.964Z (17 days ago)
- Topics: functional-programming, javascript, regex, regular-expressions, typescript
- Language: TypeScript
- Homepage: https://imax153.github.io/expressive-ts/
- Size: 2.66 MB
- Stars: 90
- Watchers: 4
- Forks: 4
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-list - expressive-ts
README
![Expressive-ts Logo](./assets/logo.png)
![Build Status Badge](https://github.com/IMax153/expressive-ts/workflows/Build/badge.svg)
> `expressive-ts` is a functional programming library designed to simplify building complex regular expressions.
# Expressive-ts
**Table of contents**
- [Installation](#installation)
- [Why?](#why)
- [Usage](#usage)
- [Documentation](#documentation)
- [Prior Art](#prior-art)## Installation
```
npm install fp-ts expressive-ts
```or
```
yarn add fp-ts expressive-ts
```**Note**: `fp-ts` is a peer dependency of `expressive-ts`
## Why?
The expressive nature of the `expressive-ts` API makes it incredibly easy to understand the purpose of an otherwise cryptic regular expression. Function composition is a core component of the API. By composing together the various functions provided by `expressive-ts`, extremely complex regular expressions can be built easily.
## Usage
Lets imagine that we would like to recognize and validate a basic URL. Here's how it would look using `expressive-ts`.
```typescript
import { pipe } from 'fp-ts/lib/function'
import * as E from 'expressive-ts/lib/Expression'const expression = pipe(
E.compile, // expressions always begin with a call to `compile`
E.startOfInput,
E.string('http'),
E.maybe('s'),
E.string('://'),
E.maybe('www.'),
E.anythingBut(' '),
E.endOfInput,
E.toRegex
)assert.strictEqual(expression.test('https://www.google.com'), true)
assert.strictEqual(expression.test('https://google.com'), true)
assert.strictEqual(expression.test('http://google.com'), true)
assert.strictEqual(expression.test('http:/google.com'), false)
assert.strictEqual(expression.test('http://goog le.com'), false)
```## Documentation
- [Docs](https://imax153.github.io/expressive-ts/)
## Prior Art
- [Super Expressive](https://github.com/francisrstokes/super-expressive/) (@francisrstokes)
- [Verbal Expressions](https://github.com/VerbalExpressions/JSVerbalExpressions/) (@VerbalExpressions)