regexp-util
v2.0.0
Published
utilities for generating regular expression
Downloads
174,596
Readme
regexp-util
utilities for generating regular expression
Install
npm install regexp-util
Usage
import { charset } from '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(flags?: string): 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 function 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
pnpm run lint
# build
pnpm run build
# test
pnpm run test
License
MIT © Ika