source: node_modules/ramda-adjunct/es/escapeRegExp.js

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: 756 bytes
Line 
1import { when, replace } from 'ramda';
2import isString from './isString';
3
4/**
5 * Escapes the RegExp special characters.
6 *
7 * @func escapeRegExp
8 * @memberOf RA
9 * @since {@link https://char0n.github.io/ramda-adjunct/2.21.0|v2.21.0}
10 * @category String
11 * @sig String -> String
12 * @param {string} val the value to escape
13 * @return {string}
14 * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping|MDN Regular Expressions Escaping}
15 * @example
16 *
17 * RA.escapeRegExp('[ramda-adjunct](https://github.com/char0n/ramda-adjunct)'); //=> '\[ramda\-adjunct\]\(https://github\.com/char0n/ramda\-adjunct\)'
18 */
19var escapeRegExp = when(isString, replace(/[.*+?^${}()|[\]\\-]/g, '\\$&'));
20export default escapeRegExp;
Note: See TracBrowser for help on using the repository browser.