[Pkg-javascript-commits] [less.js] 18/88: Adding replace function
Jonas Smedegaard
dr at jones.dk
Mon Oct 26 23:22:22 UTC 2015
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag v1.7.0
in repository less.js.
commit 089bf1b78a299b029609d66306e5230f08ff311e
Author: Jake Bellacera <jakeb at eleveninc.com>
Date: Thu Feb 6 23:29:14 2014 -0800
Adding replace function
* renamed gsub function to replace
* reordered replace's function arguments to be much more readable
* added support for replacement (Regexp) options
---
lib/less/functions.js | 8 ++++----
test/css/functions.css | 5 +++--
test/less/functions.less | 5 +++--
3 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/lib/less/functions.js b/lib/less/functions.js
index 883451a..96f9c3b 100644
--- a/lib/less/functions.js
+++ b/lib/less/functions.js
@@ -218,12 +218,12 @@ tree.functions = {
escape: function (str) {
return new(tree.Anonymous)(encodeURI(str.value).replace(/=/g, "%3D").replace(/:/g, "%3A").replace(/#/g, "%23").replace(/;/g, "%3B").replace(/\(/g, "%28").replace(/\)/g, "%29"));
},
- gsub: function (str, regexp, replacement) {
- var str = str.value;
+ replace: function (subject, pattern, replacement, options) {
+ var str = subject.value;
- str = str.replace(new RegExp(regexp.value, "g"), replacement.value);
+ str = str.replace(new RegExp(pattern.value, options ? options.value : ""), replacement.value);
- return new(tree.Quoted)('"' + str + '"', str)
+ return new(tree.Quoted)('"' + str + '"', str);
},
'%': function (quoted /* arg, arg, ...*/) {
var args = Array.prototype.slice.call(arguments, 1),
diff --git a/test/css/functions.css b/test/css/functions.css
index fa5ea89..0ba7a27 100644
--- a/test/css/functions.css
+++ b/test/css/functions.css
@@ -8,8 +8,6 @@
}
#built-in {
escaped: -Some::weird(#thing, y);
- gsub: "Hello, World!";
- gsub-captured: "This is a new string.";
lighten: #ffcccc;
darken: #330000;
saturate: #203c31;
@@ -47,6 +45,9 @@
contrast-dark-thresh-per: #eeeeee;
contrast-high-thresh-per: #eeeeee;
contrast-low-thresh-per: #111111;
+ replace: "Hello, World!";
+ replace-captured: "This is a new string.";
+ replace-options: "2 + 2 = 4";
format: "rgb(32, 128, 64)";
format-string: "hello world";
format-multiple: "hello earth 2";
diff --git a/test/less/functions.less b/test/less/functions.less
index eb7df7e..cac404f 100644
--- a/test/less/functions.less
+++ b/test/less/functions.less
@@ -12,8 +12,6 @@
#built-in {
@r: 32;
escaped: e("-Some::weird(#thing, y)");
- gsub: gsub("Hello, Foo.", "Foo\.$", "World!");
- gsub-captured: gsub("This is a string.", "(string)\.$", "new $1.");
lighten: lighten(#ff0000, 40%);
darken: darken(#ff0000, 40%);
saturate: saturate(#29332f, 20%);
@@ -51,6 +49,9 @@
contrast-dark-thresh-per: contrast(#000, #111111, #eeeeee, 50%);
contrast-high-thresh-per: contrast(#555, #111111, #eeeeee, 60%);
contrast-low-thresh-per: contrast(#555, #111111, #eeeeee, 10%);
+ replace: replace("Hello, Mars.", "Mars\.", "World!");
+ replace-captured: replace("This is a string.", "(string)\.$", "new $1.");
+ replace-options: replace("One + one = 4", "one", "2", "gi");
format: %("rgb(%d, %d, %d)", @r, 128, 64);
format-string: %("hello %s", "world");
format-multiple: %("hello %s %d", "earth", 2);
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/less.js.git
More information about the Pkg-javascript-commits
mailing list