Created
July 21, 2015 09:53
-
-
Save cahnory/f19aa3c15f18bea80cb6 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
This file contains hidden or 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.4.14) | |
// Compass (v1.0.3) | |
// ---- | |
// ASSERT ------------------------------------------------------ | |
/// Call multiple asserts at once | |
/// @param {*} $value | |
/// @param {List} $asserts | |
@function assert($value, $asserts) { | |
@each $name, $params in $asserts { | |
$value: call('assert-#{$name}', join(($value), $params)...); | |
} | |
@return $value; | |
} | |
/// Assert that $value type equal $type | |
/// @access public | |
/// @group assert | |
/// @param {*} $value | |
/// @param {String} $type | |
@function assert-type($value, $type) { | |
@return if($type == type-of($value), $value, null); | |
} | |
/// Assert that $value is not in $excluded | |
/// @access public | |
/// @group assert | |
/// @param {*} $value | |
/// @param {*...} $excluded | |
@function assert-not($value, $excluded...) { | |
@each $exc in $excluded { | |
@if $value == $exc { | |
@return null; | |
} | |
} | |
@return $value; | |
} | |
@function assert-default($value, $default) { | |
@return if(null != $value, $value, $default); | |
} | |
// DEMO -------------------------------------------------------- | |
$foo: red; | |
$type: 'color'; | |
$not: red, green, blue; | |
$def: pink; | |
foo { | |
a: assert($foo, ()); | |
b: assert($foo, ('type': $type)); | |
c: assert($foo, ('type': $type, 'not': $not)); | |
d: assert($foo, ('type': $type, 'not': $not, 'default': $def)); | |
} |
This file contains hidden or 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
foo { | |
a: red; | |
b: red; | |
d: pink; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment