Created
April 27, 2014 11:15
-
-
Save pascalduez/11343148 to your computer and use it in GitHub Desktop.
Sass, testing for empty values.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ---- | |
// Sass (v3.3.5) | |
// Compass (v1.0.0.alpha.18) | |
// ---- | |
// testing for empty values | |
// In Sass "", 0, () evaluate to true... | |
@function empty($value) { | |
@if not $value | |
or $value == "" | |
or $value == 0 | |
or $value == () | |
or length($value) == 0 { | |
@return true; | |
} | |
@return false; | |
} | |
// Test | |
sass { | |
/* | |
empty() | |
*/ | |
@each $test in false, null, "", 0, (), ("",), ("": "") { | |
#{inspect($test)}: empty($test); | |
} | |
/* | |
core | |
*/ | |
test: "" == false; | |
test: 0 == false; | |
test: () == false; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sass { | |
/* | |
empty() | |
*/ | |
false: true; | |
null: true; | |
"": true; | |
0: true; | |
(): true; | |
("",): false; | |
("": ""): false; | |
/* | |
core | |
*/ | |
test: false; | |
test: false; | |
test: false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment