Skip to content

Latest commit

 

History

History
46 lines (33 loc) · 1.01 KB

README.md

File metadata and controls

46 lines (33 loc) · 1.01 KB

npm version

@aegenet/belt-str-escape-regex

Escape String RegExp

Fork of https://github.com/sindresorhus/escape-string-regexp/ (this project, unfortunately, does not work well with TypeScript)

💾 Installation

yarn add @aegenet/belt-str-escape-regex@^2.0.0
# or
npm i @aegenet/belt-str-escape-regex@^2.0.0

📝 Usage

import { escapeRegex } from '@aegenet/belt-str-escape-regex';

const result = escapeRegex('Hello');
// result = 'Hello'
const result = escapeRegex('Hell{o} [you]');
// result = 'Hell\{o\} \[you\]'
const result = escapeRegex('');
// result = ''
const result = escapeRegex(null);
// throw Error 'Invalid usage: argument provided is not a string.'
const result = escapeRegex(undefined);
// throw Error 'Invalid usage: argument provided is not a string.'