8000 Add isunit function. fixes #1298 · browserstack/less.js@572b45a · GitHub
[go: up one dir, main page]

Skip to content

Commit 572b45a

Browse files
committed
Add isunit function. fixes less#1298
1 parent 4997ce9 commit 572b45a

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

lib/less/functions.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,16 @@ tree.functions = {
291291
return this._isa(n, tree.URL);
292292
},
293293
ispixel: function (n) {
294-
return (n instanceof tree.Dimension) && n.unit.is('px') ? tree.True : tree.False;
294+
return this.isunit(n, 'px');
295295
},
296296
ispercentage: function (n) {
297-
return (n instanceof tree.Dimension) && n.unit.is('%') ? tree.True : tree.False;
297+
return this.isunit(n, '%');
298298
},
299299
isem: function (n) {
300-
return (n instanceof tree.Dimension) && n.unit.is('em') ? tree.True : tree.False;
300+
return this.isunit(n, 'em');
301+
},
302+
isunit: function (n, unit) {
303+
return (n instanceof tree.Dimension) && n.unit.is(unit.value || unit) ? tree.True : tree.False;
301304
},
302305
_isa: function (n, Type) {
303306
return (n instanceof Type) ? tree.True : tree.False;

test/css/functions.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
pixel: true;
108108
percent: true;
109109
em: true;
110+
cat: true;
110111
}
111112
#alpha {
112113
alpha: rgba(153, 94, 51, 0.6);

test/less/functions.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@
116116
pixel: ispixel(32px);
117117
percent: ispercentage(32%);
118118
em: isem(32em);
119+
cat: isunit(32cat, cat);
119120
}
120121
}
121122

0 commit comments

Comments
 (0)
0