mirror of
https://github.com/less/less.js.git
synced 2026-01-23 06:07:56 -05:00
type-checking stylesheet functions
is-string, is-keyword, is-color, is-number
This commit is contained in:
@@ -174,6 +174,21 @@ tree.functions = {
|
||||
} else {
|
||||
throw { type: "Argument", message: "argument must be a string" };
|
||||
}
|
||||
},
|
||||
'is-color': function (n) {
|
||||
return this._isa(n, tree.Color);
|
||||
},
|
||||
'is-number': function (n) {
|
||||
return this._isa(n, tree.Dimension);
|
||||
},
|
||||
'is-string': function (n) {
|
||||
return this._isa(n, tree.Quoted);
|
||||
},
|
||||
'is-keyword': function (n) {
|
||||
return this._isa(n, tree.Keyword);
|
||||
},
|
||||
_isa: function (n, Type) {
|
||||
return (n instanceof Type) ? tree.True : tree.False;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -13,4 +13,7 @@ tree.Keyword.prototype = {
|
||||
}
|
||||
};
|
||||
|
||||
tree.True = new(tree.Keyword)('true');
|
||||
tree.False = new(tree.Keyword)('false');
|
||||
|
||||
})(require('../tree'));
|
||||
|
||||
@@ -27,6 +27,14 @@
|
||||
percentage: 20%;
|
||||
color: #ff0011;
|
||||
}
|
||||
#built-in .is-a {
|
||||
color: true;
|
||||
color: true;
|
||||
color: true;
|
||||
keyword: true;
|
||||
number: true;
|
||||
string: true;
|
||||
}
|
||||
#alpha {
|
||||
alpha: rgba(153, 94, 51, 0.6);
|
||||
}
|
||||
|
||||
@@ -30,6 +30,15 @@
|
||||
roundedpx: round(10px / 3);
|
||||
percentage: percentage(10px / 50);
|
||||
color: color("#ff0011");
|
||||
|
||||
.is-a {
|
||||
color: is-color(#ddd);
|
||||
color: is-color(red);
|
||||
color: is-color(rgb(0, 0, 0));
|
||||
keyword: is-keyword(hello);
|
||||
number: is-number(32);
|
||||
string: is-string("hello");
|
||||
}
|
||||
}
|
||||
|
||||
#alpha {
|
||||
|
||||
Reference in New Issue
Block a user