JSPM

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

utilities for generating regular expression

Package Exports

  • regexp-util

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 (regexp-util) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

regexp-util

npm build coverage

utilities for generating regular expression

Changelog

Install

# using npm
npm install --save regexp-util

# using yarn
yarn add regexp-util

Usage

const util = require('regexp-util');

const regex = util.charset(['a', 'g']) // a ~ g
  .subtract(['c', 'e'])
  .toRegExp();

const aResult = 'a'.test(regex); //=> true
const dResult = 'd'.test(regex); //=> false

API

Base

declare abstract class Base {
  isEmpty(): boolean;
  toString(): string;
  toRegExp(flags?: string): RegExp;
}

Charset

declare type CharsetInput =
  | Charset
  | string // char
  | number // codepoint
  | [string, string] // char: start to end (inclusive)
  | [number, number]; // codepoint: start to end (inclusive)
declare const charset: (...inputs: CharsetInput[]) => Charset;
declare class Charset extends Base {
  constructor(...inputs: CharsetInput[]);
  union(...inputs: CharsetInput[]): Charset;
  subtract(...inputs: CharsetInput[]): Charset;
  intersect(...inputs: CharsetInput[]): Charset;
}

Development

# lint
yarn run lint

# build
yarn run build

# test
yarn run test

License

MIT © Ika