Package detail

regexp-util

ikatyang-collab276.2kMIT2.0.3

utilities for generating regular expression

regex

readme

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

changelog

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

2.0.3 (2025-03-08)

2.0.2 (2025-03-08)

2.0.1 (2025-03-07)

2.0.0 (2023-07-09)

Build System

Code Refactoring

  • replace snake_case with camelCase (d337df6)

Features

  • do not use surrogate pair if u-flag is specified (978e5e5)

BREAKING CHANGES

  • _is_empty/_to_string has been renamed with _isEmpty/_toString
  • this package is now pure ESM

1.2.2 (2018-03-21)

Bug Fixes

  • charset: union with central overlap (#26) (d44823e)

1.2.1 (2018-03-20)

Bug Fixes

  • charset: subtraction with multi central overlap (#25) (f6595ef)

1.2.0 (2018-02-09)

Features

  • charset: support surrogate pair (#8) (024764a)

1.1.0 (2018-02-05)

Features

  • charset: throw on invalid unicode code point (#6) (b412982)

1.0.0 (2018-02-05)

Features

  • initial implementation