Last change
on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
744 bytes
|
Line | |
---|
1 | var 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 |
|
---|
14 | function 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 | }
|
---|
24 | replace.params = ['pattern', 'replacement', 'val'];
|
---|
25 | module.exports = replace;
|
---|
Note:
See
TracBrowser
for help on using the repository browser.