main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
761 bytes
|
Line | |
---|
1 | import { when, replace } from 'ramda';
|
---|
2 |
|
---|
3 | import isString from './isString';
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * Escapes the RegExp special characters.
|
---|
7 | *
|
---|
8 | * @func escapeRegExp
|
---|
9 | * @memberOf RA
|
---|
10 | * @since {@link https://char0n.github.io/ramda-adjunct/2.21.0|v2.21.0}
|
---|
11 | * @category String
|
---|
12 | * @sig String -> String
|
---|
13 | * @param {string} val the value to escape
|
---|
14 | * @return {string}
|
---|
15 | * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping|MDN Regular Expressions Escaping}
|
---|
16 | * @example
|
---|
17 | *
|
---|
18 | * RA.escapeRegExp('[ramda-adjunct](https://github.com/char0n/ramda-adjunct)'); //=> '\[ramda\-adjunct\]\(https://github\.com/char0n/ramda\-adjunct\)'
|
---|
19 | */
|
---|
20 | const escapeRegExp = when(isString, replace(/[.*+?^${}()|[\]\\-]/g, '\\$&'));
|
---|
21 |
|
---|
22 | export default escapeRegExp;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.