2.0.0 • Published 10 months ago

regexp-util v2.0.0

Weekly downloads
73,557
License
MIT
Repository
github
Last release
10 months ago

regexp-util

npm build

utilities for generating regular expression

Changelog

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