Created
January 31, 2015 18:58
-
-
Save davidkpiano/405d9cb5c8755077bae8 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.9) | |
// Compass (v1.0.1) | |
// ---- | |
@function is-integer($value: null) { | |
@return (type-of($value) == 'number' and round($value) == $value); | |
} | |
/// From https://lodash.com/docs#range | |
/// | |
/// Creates a list of numbers (positive and/or negative) progressing from | |
/// `start` up to, but not including, `end`. If `start` is less than `end` a | |
/// zero-length range is created unless a negative `step` is specified. | |
/// | |
/// @param {number} $start The start of the range. | |
/// @param {number} $end The end of the range. | |
/// @param {number} $step The value to increment or decrement by. | |
/// @returns {list} Returns the new list of numbers. | |
/// @example | |
/// | |
/// _range(4); | |
/// // => (0, 1, 2, 3) | |
/// | |
/// _range(1, 5); | |
/// // => (1, 2, 3, 4) | |
/// | |
/// _range(0, 20, 5); | |
/// // => (0, 5, 10, 15) | |
/// | |
/// _range(0, -4, -1); | |
/// // => (0, -1, -2, -3) | |
/// | |
/// _range(1, 4, 0); | |
/// // => (1, 1, 1) | |
/// | |
/// _range(0); | |
/// // => () | |
/// | |
@function _range($start, $end: null, $step: null) { | |
$start: if(is-integer($start), $start, if($start, 1, 0)); | |
$step: if($step == null, 1, if(is-integer($step), $step, if($step, 1, 0))); | |
@if ($end == null) { | |
$end: $start; | |
$start: 0; | |
} @else { | |
// JS: end = +end || 0; | |
$end: if(is-integer($end), $end, if($end, 1, 0)); | |
} | |
$index: 1; | |
// JS: length = nativeMax(ceil((end - start) / (step || 1)), 0), | |
$length: max(ceil(($end - $start) / (if($step == 0, 1, $step))), 0); | |
$result: (); | |
@while ($index <= $length) { | |
$result: append($result, $start); | |
$start: $start + $step; | |
$index: $index + 1; | |
} | |
@return $result; | |
} | |
.ranges { | |
call: "_range(4)"; | |
result: _range(4); | |
call: "_range(1, 5)"; | |
result: _range(1, 5); | |
call: "_range(0, 20, 5)"; | |
result: _range(0, 20, 5); | |
call: "_range(0, -4, -1)"; | |
result: _range(0, -4, -1); | |
call: "_range(1, 4, 0)"; | |
result: _range(1, 4, 0); | |
call: "_range(0)"; | |
result: inspect(_range(0)); | |
} |
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
.ranges { | |
call: "_range(4)"; | |
result: 0 1 2 3; | |
call: "_range(1, 5)"; | |
result: 1 2 3 4; | |
call: "_range(0, 20, 5)"; | |
result: 0 5 10 15; | |
call: "_range(0, -4, -1)"; | |
result: 0 -1 -2 -3; | |
call: "_range(1, 4, 0)"; | |
result: 1 1 1; | |
call: "_range(0)"; | |
result: (); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment