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
utilities for generating regular expression
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
NOTE: You need to pass u
flag for codepoint that is greater than 0xffff
, or you'll have to downgrade the pattern (e.g. \u{10000}
-> \uD800\uDC00
) using regexpu-core
.
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