Skip to content

Commit 8487426

Browse files
authored
Merge pull request #1 from jacobwarduk/type-checking-length-units
Type checking length units
2 parents 3699921 + cb7f563 commit 8487426

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

lib/less/functions/types.js

+18
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ functionRegistry.addMultiple({
5757
isem: function (n) {
5858
return isunit(n, 'em');
5959
},
60+
isrem: function (n) {
61+
return isunit(n, 'rem');
62+
},
63+
isvw: function (n) {
64+
return isunit(n, 'vw');
65+
},
66+
isvh: function (n) {
67+
return isunit(n, 'vh');
68+
},
69+
isvmin: function (n) {
70+
return isunit(n, 'vmin');
71+
},
72+
isvmax: function (n) {
73+
return isunit(n, 'vmax');
74+
},
75+
isch: function (n) {
76+
return isunit(n, 'ch');
77+
},
6078
isunit: isunit,
6179
unit: function (val, unit) {
6280
if (!(val instanceof Dimension)) {

lib/less/tree/unit.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Unit.prototype.is = function (unitString) {
4242
return this.toString().toUpperCase() === unitString.toUpperCase();
4343
};
4444
Unit.prototype.isLength = function () {
45-
return Boolean(this.toCSS().match(/px|em|%|in|cm|mm|pc|pt|ex/));
45+
return RegExp('^(px|em|rem|in|cm|mm|pc|pt|ex|vw|vh|vmin|vmax)$', 'g').test(this.toCSS());
4646
};
4747
Unit.prototype.isEmpty = function () {
4848
return this.numerator.length === 0 && this.denominator.length === 0;

test/css/functions.css

+6
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@
150150
pixel: true;
151151
percent: true;
152152
em: true;
153+
rem: true;
154+
vw: true;
155+
vh: true;
156+
vmin: true;
157+
vmax: true;
158+
ch: true;
153159
cat: true;
154160
no-unit-is-empty: true;
155161
case-insensitive-1: true;

test/less/functions.less

+9-3
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@
134134

135135
fade-out: fadeout(red, 5%); // support fadeOut and fadeout
136136
fade-in: fadein(fadeout(red, 10%), 5%);
137-
fade-out-relative: fadeout(red, 5%,relative);
137+
fade-out-relative: fadeout(red, 5%,relative);
138138
fade-in-relative: fadein(fadeout(red, 10%, relative), 5%, relative);
139-
fade-out2: fadeout(fadeout(red, 50%), 50%);
139+
fade-out2: fadeout(fadeout(red, 50%), 50%);
140140
fade-out2-relative: fadeout(fadeout(red, 50%, relative), 50%, relative);
141-
141+
142142
hsv: hsv(5, 50%, 30%);
143143
hsva: hsva(3, 50%, 30%, 0.2);
144144

@@ -163,6 +163,12 @@
163163
pixel: ispixel(32px);
164164
percent: ispercentage(32%);
165165
em: isem(32em);
166+
rem: isrem(32rem);
167+
vw: isvw(32vw);
168+
vh: isvh(32vh);
169+
vmin: isvmin(32vmin);
170+
vmax: isvmax(32vmax);
171+
ch: isch(32ch);
166172
cat: isunit(32cat, cat);
167173
no-unit-is-empty: isunit(32, '');
168174
case-insensitive-1: isunit(32CAT, cat);

0 commit comments

Comments
 (0)