This repository has been archived on 2024-07-27. You can view files and clone it, but cannot push or open issues or pull requests.
keksAccountGUI/node_modulesOLD/stylus/lib/functions/replace.js

24 lines
684 B
JavaScript
Raw Normal View History

2019-08-11 18:48:02 +00:00
var utils = require('../utils')
, nodes = require('../nodes');
/**
* Returns string with all matches of `pattern` replaced by `replacement` in given `val`
*
* @param {String} pattern
* @param {String} replacement
* @param {String|Ident} val
* @return {String|Ident}
* @api public
*/
module.exports = function replace(pattern, replacement, val){
utils.assertString(pattern, 'pattern');
utils.assertString(replacement, 'replacement');
utils.assertString(val, 'val');
pattern = new RegExp(pattern.string, 'g');
var res = val.string.replace(pattern, replacement.string);
return val instanceof nodes.Ident
? new nodes.Ident(res)
: new nodes.String(res);
};