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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +36 -35
- data/lib/SassyLists.rb +13 -15
- data/stylesheets/SassyLists/_chunk.scss +41 -41
- data/stylesheets/SassyLists/_contain.scss +17 -18
- data/stylesheets/SassyLists/_count-values.scss +18 -18
- data/stylesheets/SassyLists/_debug.scss +96 -94
- data/stylesheets/SassyLists/_explode.scss +49 -48
- data/stylesheets/SassyLists/_first.scss +23 -24
- data/stylesheets/SassyLists/_flatten.scss +35 -36
- data/stylesheets/SassyLists/_insert-nth.scss +46 -45
- data/stylesheets/SassyLists/_intersection.scss +28 -26
- data/stylesheets/SassyLists/_is-symmetrical.scss +18 -19
- data/stylesheets/SassyLists/_last-index.scss +20 -21
- data/stylesheets/SassyLists/_last.scss +17 -24
- data/stylesheets/SassyLists/_loop.scss +35 -36
- data/stylesheets/SassyLists/_prepend.scss +20 -20
- data/stylesheets/SassyLists/_purge.scss +27 -28
- data/stylesheets/SassyLists/_random-value.scss +29 -31
- data/stylesheets/SassyLists/_remove-duplicates.scss +24 -26
- data/stylesheets/SassyLists/_remove-nth.scss +19 -20
- data/stylesheets/SassyLists/_remove.scss +20 -21
- data/stylesheets/SassyLists/_replace-nth.scss +24 -25
- data/stylesheets/SassyLists/_replace.scss +29 -27
- data/stylesheets/SassyLists/_reverse.scss +29 -30
- data/stylesheets/SassyLists/_shuffle.scss +29 -31
- data/stylesheets/SassyLists/_slice.scss +48 -48
- data/stylesheets/SassyLists/_sort.scss +40 -41
- data/stylesheets/SassyLists/_sum.scss +28 -28
- data/stylesheets/SassyLists/_tail.scss +19 -0
- data/stylesheets/SassyLists/_to-string.scss +25 -26
- data/stylesheets/SassyLists/_union.scss +21 -24
- data/stylesheets/SassyLists/_walk.scss +24 -0
- data/stylesheets/SassyLists/helpers/_str-compare.scss +24 -26
- data/stylesheets/SassyLists/helpers/_true.scss +10 -14
- data/stylesheets/_SassyLists.scss +38 -38
- metadata +16 -20
@@ -1,21 +1,20 @@
|
|
1
|
-
// Removes value from $list at index $index
|
2
|
-
//
|
3
|
-
// @
|
4
|
-
//
|
5
|
-
// @
|
6
|
-
//
|
7
|
-
// @
|
8
|
-
//
|
9
|
-
//
|
10
|
-
// @
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
@
|
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
|
-
// @
|
4
|
-
//
|
5
|
-
// @
|
6
|
-
//
|
7
|
-
// @
|
8
|
-
//
|
9
|
-
// @param $
|
10
|
-
//
|
11
|
-
// @
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@
|
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
|
-
// @
|
4
|
-
//
|
5
|
-
// @
|
6
|
-
//
|
7
|
-
//
|
8
|
-
// @param $
|
9
|
-
// @param $
|
10
|
-
//
|
11
|
-
//
|
12
|
-
// @
|
13
|
-
//
|
14
|
-
//
|
15
|
-
|
16
|
-
|
17
|
-
@
|
18
|
-
|
19
|
-
@
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
-
// @
|
4
|
-
//
|
5
|
-
// @
|
6
|
-
//
|
7
|
-
// @param $
|
8
|
-
//
|
9
|
-
// @
|
10
|
-
|
11
|
-
@
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
-
// @
|
4
|
-
//
|
5
|
-
// @
|
6
|
-
//
|
7
|
-
// @
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
$
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
@
|
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
|
-
// @
|
4
|
-
//
|
5
|
-
// @
|
6
|
-
//
|
7
|
-
// @
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
$length
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
$
|
20
|
-
$
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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
|
-
// @
|
4
|
-
//
|
5
|
-
// @param $list
|
6
|
-
// @param $start
|
7
|
-
// @param $end
|
8
|
-
//
|
9
|
-
// @
|
10
|
-
// @
|
11
|
-
// @
|
12
|
-
// @
|
13
|
-
// @
|
14
|
-
//
|
15
|
-
// @return
|
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
|
-
// @
|
4
|
-
//
|
5
|
-
// @
|
6
|
-
//
|
7
|
-
// @
|
8
|
-
//
|
9
|
-
//
|
10
|
-
// @
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
$
|
16
|
-
$
|
17
|
-
|
18
|
-
$length
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
@
|
40
|
-
|
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
|
-
// @
|
4
|
-
//
|
5
|
-
// @param $list
|
6
|
-
// @param $force
|
7
|
-
//
|
8
|
-
// @return
|
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
|
-
// @
|
4
|
-
//
|
5
|
-
// @
|
6
|
-
//
|
7
|
-
//
|
8
|
-
// @
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
$length
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
@
|
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
|
}
|