Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
escape-string-regexp | 1.0.5 | 1.54 kB | MIT | prod |
Escape-string-regexp is a highly useful npm package made for JavaScript developers. It works by escaping RegExp (Regular Expression) special characters within a string. This can be incredibly helpful when you want to create a new RegExp from a variable and want to prevent mistaken identification of special characters. In simpler terms, this package takes a string and returns a new string where all the special characters have been properly escaped.
To use escape-string-regexp, first you need to install it via npm. You can add it to your JavaScript project by running the command:
$ npm install escape-string-regexp
Once installed, you can utilize it in your code. Here's a simple usage example:
import escapeStringRegexp from 'escape-string-regexp';
const escapedString = escapeStringRegexp('How much $ for a 🦄?');
console.log(escapedString);
// Output: 'How much \\$ for a 🦄\\?'
This example takes the string 'How much $ for a 🦄?' and escapes the dollar sign, which is a special RegExp character. The resulting string can then be safely used to create a new RegExp.
The main documentation for escape-string-regexp is the contents of its README file on the GitHub repository, which can be found at https://github.com/sindresorhus/escape-string-regexp. This README provides the fundamental details of what the package does and how to use it.