Skip to content

Instantly share code, notes, and snippets.

@cahnory
Created July 21, 2015 09:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cahnory/f19aa3c15f18bea80cb6 to your computer and use it in GitHub Desktop.
Save cahnory/f19aa3c15f18bea80cb6 to your computer and use it in GitHub Desktop.
Generated by SassMeister.com.
// ----
// 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));
}
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