mirror of https://github.com/ghostfolio/ghostfolio
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
889 B
38 lines
889 B
/**
|
|
* This module provides utility functions for working with RegExp in TypeScript.
|
|
*
|
|
* @since 2.0.0
|
|
*/
|
|
import * as predicate from "./Predicate.js"
|
|
|
|
/**
|
|
* Tests if a value is a `RegExp`.
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* import * as assert from "node:assert"
|
|
* import { RegExp } from "effect"
|
|
*
|
|
* assert.deepStrictEqual(RegExp.isRegExp(/a/), true)
|
|
* assert.deepStrictEqual(RegExp.isRegExp("a"), false)
|
|
* ```
|
|
*
|
|
* @category guards
|
|
* @since 3.9.0
|
|
*/
|
|
export const isRegExp: (input: unknown) => input is RegExp = predicate.isRegExp
|
|
|
|
/**
|
|
* Escapes special characters in a regular expression pattern.
|
|
*
|
|
* @example
|
|
* ```ts
|
|
* import * as assert from "node:assert"
|
|
* import { RegExp } from "effect"
|
|
*
|
|
* assert.deepStrictEqual(RegExp.escape("a*b"), "a\\*b")
|
|
* ```
|
|
*
|
|
* @since 2.0.0
|
|
*/
|
|
export const escape = (string: string): string => string.replace(/[/\\^$*+?.()|[\]{}]/g, "\\$&")
|
|
|