source: trip-planner-front/node_modules/stylus/lib/functions/replace.js@ eed0bf8

Last change on this file since eed0bf8 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 744 bytes
Line 
1var utils = require('../utils')
2 , nodes = require('../nodes');
3
4/**
5 * Returns string with all matches of `pattern` replaced by `replacement` in given `val`
6 *
7 * @param {String} pattern
8 * @param {String} replacement
9 * @param {String|Ident} val
10 * @return {String|Ident}
11 * @api public
12 */
13
14function replace(pattern, replacement, val){
15 utils.assertString(pattern, 'pattern');
16 utils.assertString(replacement, 'replacement');
17 utils.assertString(val, 'val');
18 pattern = new RegExp(pattern.string, 'g');
19 var res = val.string.replace(pattern, replacement.string);
20 return val instanceof nodes.Ident
21 ? new nodes.Ident(res)
22 : new nodes.String(res);
23}
24replace.params = ['pattern', 'replacement', 'val'];
25module.exports = replace;
Note: See TracBrowser for help on using the repository browser.