JSPM

expressive-ts

0.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 91
  • Score
    100M100P100Q68907F
  • License MIT

A functional programming library designed to simplify building complex regular expressions

Package Exports

  • expressive-ts

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (expressive-ts) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Expressive-ts Logo

Build Status Badge

expressive-ts is a functional programming library designed to simplify building complex regular expressions.

Expressive-ts

Table of contents

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.

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

Prior Art