Denis 346b78aee1 first commit hace 2 años
..
lib 346b78aee1 first commit hace 2 años
CHANGELOG.md 346b78aee1 first commit hace 2 años
LICENSE 346b78aee1 first commit hace 2 años
README.md 346b78aee1 first commit hace 2 años
package.json 346b78aee1 first commit hace 2 años

README.md

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