SassyLists 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +36 -35
  3. data/lib/SassyLists.rb +13 -15
  4. data/stylesheets/SassyLists/_chunk.scss +41 -41
  5. data/stylesheets/SassyLists/_contain.scss +17 -18
  6. data/stylesheets/SassyLists/_count-values.scss +18 -18
  7. data/stylesheets/SassyLists/_debug.scss +96 -94
  8. data/stylesheets/SassyLists/_explode.scss +49 -48
  9. data/stylesheets/SassyLists/_first.scss +23 -24
  10. data/stylesheets/SassyLists/_flatten.scss +35 -36
  11. data/stylesheets/SassyLists/_insert-nth.scss +46 -45
  12. data/stylesheets/SassyLists/_intersection.scss +28 -26
  13. data/stylesheets/SassyLists/_is-symmetrical.scss +18 -19
  14. data/stylesheets/SassyLists/_last-index.scss +20 -21
  15. data/stylesheets/SassyLists/_last.scss +17 -24
  16. data/stylesheets/SassyLists/_loop.scss +35 -36
  17. data/stylesheets/SassyLists/_prepend.scss +20 -20
  18. data/stylesheets/SassyLists/_purge.scss +27 -28
  19. data/stylesheets/SassyLists/_random-value.scss +29 -31
  20. data/stylesheets/SassyLists/_remove-duplicates.scss +24 -26
  21. data/stylesheets/SassyLists/_remove-nth.scss +19 -20
  22. data/stylesheets/SassyLists/_remove.scss +20 -21
  23. data/stylesheets/SassyLists/_replace-nth.scss +24 -25
  24. data/stylesheets/SassyLists/_replace.scss +29 -27
  25. data/stylesheets/SassyLists/_reverse.scss +29 -30
  26. data/stylesheets/SassyLists/_shuffle.scss +29 -31
  27. data/stylesheets/SassyLists/_slice.scss +48 -48
  28. data/stylesheets/SassyLists/_sort.scss +40 -41
  29. data/stylesheets/SassyLists/_sum.scss +28 -28
  30. data/stylesheets/SassyLists/_tail.scss +19 -0
  31. data/stylesheets/SassyLists/_to-string.scss +25 -26
  32. data/stylesheets/SassyLists/_union.scss +21 -24
  33. data/stylesheets/SassyLists/_walk.scss +24 -0
  34. data/stylesheets/SassyLists/helpers/_str-compare.scss +24 -26
  35. data/stylesheets/SassyLists/helpers/_true.scss +10 -14
  36. data/stylesheets/_SassyLists.scss +38 -38
  37. metadata +16 -20
@@ -1,21 +1,20 @@
1
- // Removes value from $list at index $index
2
- // -------------------------------------------------------------------------------
3
- // @documentation http://sassylists.com/documentation/#remove-nth
4
- // -------------------------------------------------------------------------------
5
- // @alias `without-nth()`
6
- // -------------------------------------------------------------------------------
7
- // @dependence `replace-nth()`
8
- // -------------------------------------------------------------------------------
9
- // @param $list [List] : list
10
- // @param $index [Number] : index to remove
11
- // -------------------------------------------------------------------------------
12
- // @return [List] | false
13
-
14
- @function remove-nth($list, $index) {
15
- @return replace-nth($list, $index, "");
16
- }
17
-
18
- // Alias
19
- @function without-nth($list, $index) {
20
- @return remove-nth($list, $index);
1
+ // Removes value from $list at index $index
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation/#remove-nth
4
+ //
5
+ // @requires replace-nth
6
+ //
7
+ // @param {List} $list - list to remove value from
8
+ // @param {Number} $index - index to remove
9
+ //
10
+ // @return {List | Bool}
11
+
12
+ @function remove-nth($list, $index) {
13
+ @return replace-nth($list, $index, "");
14
+ }
15
+
16
+ // @alias remove-nth
17
+
18
+ @function without-nth($list, $index) {
19
+ @return remove-nth($list, $index);
21
20
  }
@@ -1,22 +1,21 @@
1
- // Removes value(s) $value from $list
2
- // -------------------------------------------------------------------------------
3
- // @documentation http://sassylists.com/documentation/#remove
4
- // -------------------------------------------------------------------------------
5
- // @alias `without()`
6
- // -------------------------------------------------------------------------------
7
- // @dependence `replace()`
8
- // -------------------------------------------------------------------------------
9
- // @param $list [List] : list
10
- // @param $value [Literal] : value to remove
11
- // @param $recursive [Boolean] : enable / disable recursivity
12
- // -------------------------------------------------------------------------------
13
- // @return [List]
14
-
15
- @function remove($list, $value) {
16
- @return replace($list, $value, null);
17
- }
18
-
19
- // Alias
20
- @function without($list, $value) {
21
- @return remove($list, $value);
1
+ // Removes value(s) $value from $list
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation/#remove
4
+ //
5
+ // @requires replace
6
+ //
7
+ // @param {List} $list - list to update
8
+ // @param {*} $value - value to remove
9
+ // @param {Bool} $recursive - enable/disable recursion
10
+ //
11
+ // @return {List}
12
+
13
+ @function remove($list, $value) {
14
+ @return replace($list, $value, null);
15
+ }
16
+
17
+ // @alias remove
18
+
19
+ @function without($list, $value) {
20
+ @return remove($list, $value);
22
21
  }
@@ -1,25 +1,24 @@
1
- // Replaces value at $index from $list by $value
2
- // -------------------------------------------------------------------------------
3
- // @documentation http://sassylists.com/documentation/#replace-nth
4
- // -------------------------------------------------------------------------------
5
- // @dependence `purge()`
6
- // -------------------------------------------------------------------------------
7
- // @param $list [List] : list
8
- // @param $index [Number] : index to update
9
- // @param $value [Literal] : new value for index $index
10
- // -------------------------------------------------------------------------------
11
- // @raise [Error] if $index isn't an integer
12
- // @raise [Error] if $index is 0
13
- // @raise [Error] if abs value of $index is strictly greater than length of $list
14
- // -------------------------------------------------------------------------------
15
- // @return [List] | false
16
-
17
- @function replace-nth($list, $index, $value) {
18
- @if type-of($index) != "number" or $index == 0 or abs($index) > length($list) {
19
- @warn "Invalid index (#{$index}) for `replace-nth`.";
20
- @return false;
21
- }
22
-
23
- $list: set-nth($list, $index, $value);
24
- @return if(not is-true($value), purge($list), $list);
25
- }
1
+ // Replaces value at $index from $list by $value
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation/#replace-nth
4
+ //
5
+ // @requires purge
6
+ // @requires is-true
7
+ //
8
+ // @param {List} $list - list to update
9
+ // @param {Number} $index - index to update
10
+ // @param {*} $value - new value for index
11
+ //
12
+ // @throws Invalid index $index for `replace-nth`.
13
+ //
14
+ // @return {List | Bool}
15
+
16
+ @function replace-nth($list, $index, $value) {
17
+ @if type-of($index) != "number" or $index == 0 or abs($index) > length($list) {
18
+ @warn "Invalid index (#{$index}) for `replace-nth`.";
19
+ @return false;
20
+ }
21
+
22
+ $list: set-nth($list, $index, $value);
23
+ @return if(not is-true($value), purge($list), $list);
24
+ }
@@ -1,28 +1,30 @@
1
- // Replaces $old by $new in $list
2
- // -------------------------------------------------------------------------------
3
- // @documentation http://sassylists.com/documentation.html#replace
4
- // -------------------------------------------------------------------------------
5
- // @param $list [List] : list
6
- // @param $old [Literal] : value to replace
7
- // @param $value [Literal] : new value for $old
8
- // -------------------------------------------------------------------------------
9
- // @return [List]
10
-
11
- @function replace($list, $old, $value) {
12
- $running: true;
13
-
14
- @while $running {
15
- $index: index($list, $old);
16
-
17
- @if not $index {
18
- $running: false;
19
- }
20
-
21
- @else {
22
- $list: set-nth($list, $index, $value);
23
- }
24
-
25
- }
26
-
27
- @return if(not is-true($value), purge($list), $list);
1
+ // Replaces $old by $new in $list
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation.html#replace
4
+ //
5
+ // @requires is-true
6
+ //
7
+ // @param {List} $list - list to update
8
+ // @param {*} $old - value to replace
9
+ // @param {*} $value - new value for $old
10
+ //
11
+ // @return {List}
12
+
13
+ @function replace($list, $old, $value) {
14
+ $running: true;
15
+
16
+ @while $running {
17
+ $index: index($list, $old);
18
+
19
+ @if not $index {
20
+ $running: false;
21
+ }
22
+
23
+ @else {
24
+ $list: set-nth($list, $index, $value);
25
+ }
26
+
27
+ }
28
+
29
+ @return if(not is-true($value), purge($list), $list);
28
30
  }
@@ -1,31 +1,30 @@
1
- // Reverses the order of $list
2
- // -------------------------------------------------------------------------------
3
- // @documentation http://sassylists.com/documentation/#reverse
4
- // -------------------------------------------------------------------------------
5
- // @alias `mirror()`
6
- // -------------------------------------------------------------------------------
7
- // @param $list [List] : list
8
- // -------------------------------------------------------------------------------
9
- // @return [List]
10
-
11
- @function reverse($list) {
12
- $length: length($list);
13
- $end: floor($length/2);
14
-
15
- @if $length < 2 {
16
- @return $list;
17
- }
18
-
19
- @for $i from 1 through $end {
20
- $tmp: nth($list, $i);
21
- $list: set-nth($list, $i, nth($list, -$i));
22
- $list: set-nth($list, -$i, $tmp);
23
- }
24
-
25
- @return $list;
26
- }
27
-
28
- // Alias
29
- @function mirror($list) {
30
- @return reverse($list);
1
+ // Reverses the order of $list
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation/#reverse
4
+ //
5
+ // @param {List} $list - list to revers
6
+ //
7
+ // @return {List}
8
+
9
+ @function reverse($list) {
10
+ $length: length($list);
11
+ $end: floor($length/2);
12
+
13
+ @if $length < 2 {
14
+ @return $list;
15
+ }
16
+
17
+ @for $i from 1 through $end {
18
+ $tmp: nth($list, $i);
19
+ $list: set-nth($list, $i, nth($list, -$i));
20
+ $list: set-nth($list, -$i, $tmp);
21
+ }
22
+
23
+ @return $list;
24
+ }
25
+
26
+ // @alias reverse
27
+
28
+ @function mirror($list) {
29
+ @return reverse($list);
31
30
  }
@@ -1,31 +1,29 @@
1
- // Shuffle function using Fisher-Yates method
2
- // -------------------------------------------------------------------------------
3
- // @documentation http://sassylists.com/documentation/#shuffle
4
- // -------------------------------------------------------------------------------
5
- // @alias `randomize()`
6
- // -------------------------------------------------------------------------------
7
- // @param $list [List] : list
8
- // -------------------------------------------------------------------------------
9
- // @return [List]
10
-
11
- @function shuffle($list) {
12
- $length: length($list);
13
-
14
- @if $length < 2 {
15
- @return $list;
16
- }
17
-
18
- @for $i from -1 * $length through -1 {
19
- $i: abs($i);
20
- $j: random($length - 1) + 1;
21
- $tmp: nth($list, $i);
22
- $list: set-nth($list, $i, nth($list, $j));
23
- $list: set-nth($list, $j, $tmp);
24
- }
25
- @return $list;
26
- }
27
-
28
- // Alias
29
- @function randomize($list) {
30
- @return shuffle($list);
31
- }
1
+ // Shuffle function using Fisher-Yates method
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation/#shuffle
4
+ //
5
+ // @param {List} $list - list to shuffle
6
+ //
7
+ // @return {List}
8
+
9
+ @function shuffle($list) {
10
+ $length: length($list);
11
+
12
+ @if $length < 2 {
13
+ @return $list;
14
+ }
15
+
16
+ @for $i from $length through 1 {
17
+ $j: random($length - 1) + 1;
18
+ $tmp: nth($list, $i);
19
+ $list: set-nth($list, $i, nth($list, $j));
20
+ $list: set-nth($list, $j, $tmp);
21
+ }
22
+ @return $list;
23
+ }
24
+
25
+ // @alias shuffle
26
+
27
+ @function randomize($list) {
28
+ @return shuffle($list);
29
+ }
@@ -1,49 +1,49 @@
1
- // Slices $list between $start and $end
2
- // -------------------------------------------------------------------------------
3
- // @documentation http://sassylists.com/documentation/#slice
4
- // -------------------------------------------------------------------------------
5
- // @param $list [List] : list
6
- // @param $start [Number] : start index
7
- // @param $end [Number] : end index
8
- // -------------------------------------------------------------------------------
9
- // @raise [Error] if $start or $end aren't integers
10
- // @raise [Error] if $start is greater than $end
11
- // @raise [Error] if $start or $end is strictly lesser than 1
12
- // @raise [Error] if $start is strictly greater than length of $list
13
- // @raise [Error] if $end is strictly greater than length of $list
14
- // -------------------------------------------------------------------------------
15
- // @return [List] | false
16
-
17
- @function slice($list, $start: 1, $end: length($list)) {
18
- @if type-of($start) != "number" or type-of($end) != "number" {
19
- @warn "List indexes #{$start} and #{$end} must be numbers for `slice`.";
20
- @return false;
21
- }
22
-
23
- @if $start > $end {
24
- @warn "Start index is #{$start} but has to be lesser than or equals to the end index (#{$end}) for `slice`.";
25
- @return false;
26
- }
27
-
28
- @if $start < 1 or $end < 1 {
29
- @warn "List indexes must be non-zero integers for `slice`.";
30
- @return false;
31
- }
32
-
33
- @if $start > length($list) {
34
- @warn "Start index is #{$start} but list is only #{length($list)} items long for `slice`.";
35
- @return false;
36
- }
37
-
38
- @if $end > length($list) {
39
- @warn "End index is #{$end} but list is only #{length($list)} items long for `slice`.";
40
- @return false;
41
- }
42
-
43
- $result: ();
44
- @for $i from $start through $end {
45
- $result: append($result, nth($list, $i), list-separator($list));
46
- }
47
-
48
- @return $result;
1
+ // Slices $list between $start and $end
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation/#slice
4
+ //
5
+ // @param {List} $list - list to slice
6
+ // @param {Number} $start (1) - start index
7
+ // @param {Number} $end (length($list)) - end index
8
+ //
9
+ // @throws List indexes $start and $end must be numbers for `slice`.
10
+ // @throws Start index has to be lesser than or equals to the end index for `slice`.
11
+ // @throws List indexes must be non-zero integers for `slice`.
12
+ // @throws Start index has to be lesser than or equal to list length for `slice`.
13
+ // @throws End index has to be lesser than or equal to list length for `slice`.
14
+ //
15
+ // @return {List | Bool}
16
+
17
+ @function slice($list, $start: 1, $end: length($list)) {
18
+ @if type-of($start) != "number" or type-of($end) != "number" {
19
+ @warn "List indexes #{$start} and #{$end} must be numbers for `slice`.";
20
+ @return false;
21
+ }
22
+
23
+ @if $start > $end {
24
+ @warn "Start index is #{$start} but has to be lesser than or equals to the end index (#{$end}) for `slice`.";
25
+ @return false;
26
+ }
27
+
28
+ @if $start < 1 or $end < 1 {
29
+ @warn "List indexes must be non-zero integers for `slice`.";
30
+ @return false;
31
+ }
32
+
33
+ @if $start > length($list) {
34
+ @warn "Start index is #{$start} but list is only #{length($list)} items long for `slice`.";
35
+ @return false;
36
+ }
37
+
38
+ @if $end > length($list) {
39
+ @warn "End index is #{$end} but list is only #{length($list)} items long for `slice`.";
40
+ @return false;
41
+ }
42
+
43
+ $result: ();
44
+ @for $i from $start through $end {
45
+ $result: append($result, nth($list, $i), list-separator($list));
46
+ }
47
+
48
+ @return $result;
49
49
  }
@@ -1,41 +1,40 @@
1
- // Sorts values of $list using quick-sort algorithm
2
- // -------------------------------------------------------------------------------
3
- // @documentation http://sassylists.com/documentation/#sort
4
- // -------------------------------------------------------------------------------
5
- // @alias `order()`
6
- // -------------------------------------------------------------------------------
7
- // @dependence `str-compare()`
8
- // -------------------------------------------------------------------------------
9
- // @param $list [List] : list
10
- // @param $order [List] : order
11
- // -------------------------------------------------------------------------------
12
- // @return [List]
13
-
14
- @function sort($list, $order: "!" "#" "$" "%" "&" "'" "(" ")" "*" "+" "," "-" "." "/" "[" "\\" "]" "^" "_" "{" "|" "}" "~" "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z") {
15
- $less: ();
16
- $equal: ();
17
- $large: ();
18
- $length: length($list);
19
-
20
- @if $length > 1 {
21
- $seed: nth($list, ceil($length / 2));
22
- @each $item in $list {
23
- @if $item == $seed {
24
- $equal: append($equal, $item, list-separator($list));
25
- }
26
- @else if str-compare($item, $seed, $order) {
27
- $less: append($less, $item, list-separator($list));
28
- }
29
- @else if not str-compare($item, $seed, $order) {
30
- $large: append($large, $item, list-separator($list));
31
- }
32
- }
33
- @return join(join(sort($less, $order), $equal), sort($large, $order));
34
- }
35
- @return $list;
36
- }
37
-
38
- // Alias
39
- @function order($list) {
40
- @return sort($list);
41
- }
1
+ // Sorts values of $list using quick-sort algorithm
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation/#sort
4
+ //
5
+ // @requires str-compare
6
+ //
7
+ // @param {List} $list - list to sort
8
+ // @param {List} $order - order to respect
9
+ //
10
+ // @return {List}
11
+
12
+ @function sort($list, $order: "!" "#" "$" "%" "&" "'" "(" ")" "*" "+" "," "-" "." "/" "[" "\\" "]" "^" "_" "{" "|" "}" "~" "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z") {
13
+ $less: ();
14
+ $equal: ();
15
+ $large: ();
16
+ $length: length($list);
17
+
18
+ @if $length > 1 {
19
+ $seed: nth($list, ceil($length / 2));
20
+ @each $item in $list {
21
+ @if $item == $seed {
22
+ $equal: append($equal, $item, list-separator($list));
23
+ }
24
+ @else if str-compare($item, $seed, $order) {
25
+ $less: append($less, $item, list-separator($list));
26
+ }
27
+ @else if not str-compare($item, $seed, $order) {
28
+ $large: append($large, $item, list-separator($list));
29
+ }
30
+ }
31
+ @return join(join(sort($less, $order), $equal), sort($large, $order));
32
+ }
33
+ @return $list;
34
+ }
35
+
36
+ // @alias sort
37
+
38
+ @function order($list) {
39
+ @return sort($list);
40
+ }
@@ -1,28 +1,28 @@
1
- // Sums up all numeric values in $list
2
- // -------------------------------------------------------------------------------
3
- // @documentation http://sassylists.com/documentation/#sum
4
- // -------------------------------------------------------------------------------
5
- // @param $list [List] : list
6
- // @param $force [Boolean] : enable / disable parseInt
7
- // -------------------------------------------------------------------------------
8
- // @return [Number]
9
-
10
- @function sum($list, $force: false) {
11
- $result: 0;
12
-
13
- @each $item in $list {
14
- @if type-of($item) == number {
15
-
16
- @if $force and not unitless($item) {
17
- $item: $item / ($item * 0 + 1);
18
- }
19
-
20
- @if unitless($item) {
21
- $result: $result + $item;
22
- }
23
-
24
- }
25
- }
26
-
27
- @return $result;
28
- }
1
+ // Sums up all numeric values in $list
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation/#sum
4
+ //
5
+ // @param {List} $list - list
6
+ // @param {Boolean} $force (false) - enable/disable parseInt
7
+ //
8
+ // @return {Number}
9
+
10
+ @function sum($list, $force: false) {
11
+ $result: 0;
12
+
13
+ @each $item in $list {
14
+ @if type-of($item) == number {
15
+
16
+ @if $force and not unitless($item) {
17
+ $item: $item / ($item * 0 + 1);
18
+ }
19
+
20
+ @if unitless($item) {
21
+ $result: $result + $item;
22
+ }
23
+
24
+ }
25
+ }
26
+
27
+ @return $result;
28
+ }
@@ -0,0 +1,19 @@
1
+ // Returns the tail of $list: all items except the first (head)
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation/#tail
4
+ //
5
+ // @requires slice
6
+ //
7
+ // @param {List} $list - list to retrieve tail from
8
+ //
9
+ // @return {List | Bool}
10
+
11
+ @function tail($list) {
12
+ @return slice($list, 2);
13
+ }
14
+
15
+ // @alias tail
16
+
17
+ @function rest($list) {
18
+ @return tail($list);
19
+ }
@@ -1,27 +1,26 @@
1
- // Joins all elements of $list with $glue
2
- // -------------------------------------------------------------------------------
3
- // @documentation http://sassylists.com/documentation/#to-string
4
- // -------------------------------------------------------------------------------
5
- // @alias `stringify()`
6
- // -------------------------------------------------------------------------------
7
- // @param $list [List] : list
8
- // @param $glue [String] : value to use as a join string
9
- // -------------------------------------------------------------------------------
10
- // @return [String]
11
-
12
- @function to-string($list, $glue: '') {
13
- $result: '';
14
- $length: length($list);
15
-
16
- @for $i from 1 through $length {
17
- $item: nth($list, $i);
18
- $result: $result + if(length($item) > 1, to-string($item, $glue), $item + $glue);
19
- }
20
-
21
- @return quote(str-slice($result, 1, str-length($glue) * -1 - 1));
22
- }
23
-
24
- // Alias
25
- @function stringify($list, $glue: '') {
26
- @return to-string($list, $glue);
1
+ // Joins all elements of $list with $glue
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation/#to-string
4
+ //
5
+ // @param {List} $list - list to cast
6
+ // @param {String} $glue ('') - value to use as a join string
7
+ //
8
+ // @return {String}
9
+
10
+ @function to-string($list, $glue: '') {
11
+ $result: '';
12
+ $length: length($list);
13
+
14
+ @for $i from 1 through $length {
15
+ $item: nth($list, $i);
16
+ $result: $result + if(length($item) > 1, to-string($item, $glue), $item + $glue);
17
+ }
18
+
19
+ @return quote(str-slice($result, 1, str-length($glue) * -1 - 1));
20
+ }
21
+
22
+ // @alias to-string
23
+
24
+ @function stringify($list, $glue: '') {
25
+ @return to-string($list, $glue);
27
26
  }