aboutsummaryrefslogtreecommitdiff
path: root/node_modules/stylus/lib/functions/replace.js
diff options
context:
space:
mode:
Diffstat (limited to 'node_modules/stylus/lib/functions/replace.js')
-rw-r--r--node_modules/stylus/lib/functions/replace.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/node_modules/stylus/lib/functions/replace.js b/node_modules/stylus/lib/functions/replace.js
new file mode 100644
index 00000000..15d9c904
--- /dev/null
+++ b/node_modules/stylus/lib/functions/replace.js
@@ -0,0 +1,23 @@
+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);
+};