mirror of
https://github.com/less/less.js.git
synced 2026-05-01 03:00:22 -04:00
Merge pull request #1 from jacobwarduk/type-checking-length-units
Type checking length units
This commit is contained in:
@@ -57,6 +57,24 @@ functionRegistry.addMultiple({
|
||||
isem: function (n) {
|
||||
return isunit(n, 'em');
|
||||
},
|
||||
isrem: function (n) {
|
||||
return isunit(n, 'rem');
|
||||
},
|
||||
isvw: function (n) {
|
||||
return isunit(n, 'vw');
|
||||
},
|
||||
isvh: function (n) {
|
||||
return isunit(n, 'vh');
|
||||
},
|
||||
isvmin: function (n) {
|
||||
return isunit(n, 'vmin');
|
||||
},
|
||||
isvmax: function (n) {
|
||||
return isunit(n, 'vmax');
|
||||
},
|
||||
isch: function (n) {
|
||||
return isunit(n, 'ch');
|
||||
},
|
||||
isunit: isunit,
|
||||
unit: function (val, unit) {
|
||||
if (!(val instanceof Dimension)) {
|
||||
|
||||
@@ -42,7 +42,7 @@ Unit.prototype.is = function (unitString) {
|
||||
return this.toString().toUpperCase() === unitString.toUpperCase();
|
||||
};
|
||||
Unit.prototype.isLength = function () {
|
||||
return Boolean(this.toCSS().match(/px|em|%|in|cm|mm|pc|pt|ex/));
|
||||
return RegExp('^(px|em|rem|in|cm|mm|pc|pt|ex|vw|vh|vmin|vmax)$', 'g').test(this.toCSS());
|
||||
};
|
||||
Unit.prototype.isEmpty = function () {
|
||||
return this.numerator.length === 0 && this.denominator.length === 0;
|
||||
|
||||
@@ -150,6 +150,12 @@
|
||||
pixel: true;
|
||||
percent: true;
|
||||
em: true;
|
||||
rem: true;
|
||||
vw: true;
|
||||
vh: true;
|
||||
vmin: true;
|
||||
vmax: true;
|
||||
ch: true;
|
||||
cat: true;
|
||||
no-unit-is-empty: true;
|
||||
case-insensitive-1: true;
|
||||
|
||||
@@ -134,11 +134,11 @@
|
||||
|
||||
fade-out: fadeout(red, 5%); // support fadeOut and fadeout
|
||||
fade-in: fadein(fadeout(red, 10%), 5%);
|
||||
fade-out-relative: fadeout(red, 5%,relative);
|
||||
fade-out-relative: fadeout(red, 5%,relative);
|
||||
fade-in-relative: fadein(fadeout(red, 10%, relative), 5%, relative);
|
||||
fade-out2: fadeout(fadeout(red, 50%), 50%);
|
||||
fade-out2: fadeout(fadeout(red, 50%), 50%);
|
||||
fade-out2-relative: fadeout(fadeout(red, 50%, relative), 50%, relative);
|
||||
|
||||
|
||||
hsv: hsv(5, 50%, 30%);
|
||||
hsva: hsva(3, 50%, 30%, 0.2);
|
||||
|
||||
@@ -163,6 +163,12 @@
|
||||
pixel: ispixel(32px);
|
||||
percent: ispercentage(32%);
|
||||
em: isem(32em);
|
||||
rem: isrem(32rem);
|
||||
vw: isvw(32vw);
|
||||
vh: isvh(32vh);
|
||||
vmin: isvmin(32vmin);
|
||||
vmax: isvmax(32vmax);
|
||||
ch: isch(32ch);
|
||||
cat: isunit(32cat, cat);
|
||||
no-unit-is-empty: isunit(32, '');
|
||||
case-insensitive-1: isunit(32CAT, cat);
|
||||
|
||||
Reference in New Issue
Block a user