pax_global_header00006660000000000000000000000064136502357670014530gustar00rootroot0000000000000052 comment=71083e89129bcf72a10656508de5442d3f97966d escape-string-regexp-4.0.0/000077500000000000000000000000001365023576700155655ustar00rootroot00000000000000escape-string-regexp-4.0.0/.editorconfig000066400000000000000000000002571365023576700202460ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 escape-string-regexp-4.0.0/.gitattributes000066400000000000000000000000231365023576700204530ustar00rootroot00000000000000* text=auto eol=lf escape-string-regexp-4.0.0/.github/000077500000000000000000000000001365023576700171255ustar00rootroot00000000000000escape-string-regexp-4.0.0/.github/funding.yml000066400000000000000000000001761365023576700213060ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/escape-string-regexp custom: https://sindresorhus.com/donate escape-string-regexp-4.0.0/.github/security.md000066400000000000000000000002631365023576700213170ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. escape-string-regexp-4.0.0/.gitignore000066400000000000000000000000271365023576700175540ustar00rootroot00000000000000node_modules yarn.lock escape-string-regexp-4.0.0/.npmrc000066400000000000000000000000231365023576700167000ustar00rootroot00000000000000package-lock=false escape-string-regexp-4.0.0/.travis.yml000066400000000000000000000000551365023576700176760ustar00rootroot00000000000000language: node_js node_js: - '12' - '10' escape-string-regexp-4.0.0/index.d.ts000066400000000000000000000007231365023576700174700ustar00rootroot00000000000000/** Escape RegExp special characters. You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class. @example ``` import escapeStringRegexp = require('escape-string-regexp'); const escapedString = escapeStringRegexp('How much $ for a 🦄?'); //=> 'How much \\$ for a 🦄\\?' new RegExp(escapedString); ``` */ declare const escapeStringRegexp: (string: string) => string; export = escapeStringRegexp; escape-string-regexp-4.0.0/index.js000066400000000000000000000007151365023576700172350ustar00rootroot00000000000000'use strict'; module.exports = string => { if (typeof string !== 'string') { throw new TypeError('Expected a string'); } // Escape characters with special meaning either inside or outside character sets. // Use a simple backslash escape when it’s always valid, and a \unnnn escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar. return string .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&') .replace(/-/g, '\\x2d'); }; escape-string-regexp-4.0.0/index.test-d.ts000066400000000000000000000002151365023576700204410ustar00rootroot00000000000000import {expectType} from 'tsd'; import escapeStringRegexp = require('.'); expectType(escapeStringRegexp('how much $ for a 🦄?')); escape-string-regexp-4.0.0/license000066400000000000000000000021351365023576700171330ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://sindresorhus.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. escape-string-regexp-4.0.0/package.json000066400000000000000000000012561365023576700200570ustar00rootroot00000000000000{ "name": "escape-string-regexp", "version": "4.0.0", "description": "Escape RegExp special characters", "license": "MIT", "repository": "sindresorhus/escape-string-regexp", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "engines": { "node": ">=10" }, "scripts": { "test": "xo && ava && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "escape", "regex", "regexp", "regular", "expression", "string", "special", "characters" ], "devDependencies": { "ava": "^1.4.1", "tsd": "^0.11.0", "xo": "^0.28.3" } } escape-string-regexp-4.0.0/readme.md000066400000000000000000000020431365023576700173430ustar00rootroot00000000000000# escape-string-regexp [![Build Status](https://travis-ci.org/sindresorhus/escape-string-regexp.svg?branch=master)](https://travis-ci.org/sindresorhus/escape-string-regexp) > Escape RegExp special characters ## Install ``` $ npm install escape-string-regexp ``` ## Usage ```js const escapeStringRegexp = require('escape-string-regexp'); const escapedString = escapeStringRegexp('How much $ for a 🦄?'); //=> 'How much \\$ for a 🦄\\?' new RegExp(escapedString); ``` You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class. ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
escape-string-regexp-4.0.0/test.js000066400000000000000000000007331365023576700171050ustar00rootroot00000000000000import test from 'ava'; import escapeStringRegexp from '.'; test('main', t => { t.is( escapeStringRegexp('\\ ^ $ * + ? . ( ) | { } [ ]'), '\\\\ \\^ \\$ \\* \\+ \\? \\. \\( \\) \\| \\{ \\} \\[ \\]' ); }); test('escapes `-` in a way compatible with PCRE', t => { t.is( escapeStringRegexp('foo - bar'), 'foo \\x2d bar' ); }); test('escapes `-` in a way compatible with the Unicode flag', t => { t.regex( '-', new RegExp(escapeStringRegexp('-'), 'u') ); });