SassyLists 2.1.1 → 2.2.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 (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/README.md +8 -4
  4. data/lib/SassyLists.rb +2 -2
  5. data/stylesheets/SassyLists/_chunk.scss +15 -3
  6. data/stylesheets/SassyLists/_contain.scss +1 -0
  7. data/stylesheets/SassyLists/_debug.scss +10 -4
  8. data/stylesheets/SassyLists/_explode.scss +11 -6
  9. data/stylesheets/SassyLists/_first.scss +6 -1
  10. data/stylesheets/SassyLists/_flatten.scss +8 -6
  11. data/stylesheets/SassyLists/_has-multiple-values.scss +11 -0
  12. data/stylesheets/SassyLists/_has-values.scss +11 -0
  13. data/stylesheets/SassyLists/_insert-nth.scss +2 -2
  14. data/stylesheets/SassyLists/_intersection.scss +3 -3
  15. data/stylesheets/SassyLists/_is-empty.scss +1 -1
  16. data/stylesheets/SassyLists/_is-single.scss +11 -0
  17. data/stylesheets/SassyLists/_is-symmetrical.scss +1 -0
  18. data/stylesheets/SassyLists/_last-index.scss +1 -3
  19. data/stylesheets/SassyLists/_last.scss +5 -1
  20. data/stylesheets/SassyLists/_loop.scss +7 -2
  21. data/stylesheets/SassyLists/_prepend.scss +4 -5
  22. data/stylesheets/SassyLists/_purge.scss +4 -2
  23. data/stylesheets/SassyLists/_random-value.scss +8 -2
  24. data/stylesheets/SassyLists/_range.scss +40 -0
  25. data/stylesheets/SassyLists/_remove-duplicates.scss +8 -3
  26. data/stylesheets/SassyLists/_remove-nth.scss +1 -0
  27. data/stylesheets/SassyLists/_remove.scss +1 -0
  28. data/stylesheets/SassyLists/_replace-nth.scss +6 -3
  29. data/stylesheets/SassyLists/_replace.scss +5 -2
  30. data/stylesheets/SassyLists/_reverse.scss +7 -2
  31. data/stylesheets/SassyLists/_shuffle.scss +6 -1
  32. data/stylesheets/SassyLists/_slice.scss +0 -4
  33. data/stylesheets/SassyLists/_sort.scss +12 -5
  34. data/stylesheets/SassyLists/_sum.scss +17 -11
  35. data/stylesheets/SassyLists/_tail.scss +1 -0
  36. data/stylesheets/SassyLists/_to-list.scss +13 -2
  37. data/stylesheets/SassyLists/_to-map.scss +11 -21
  38. data/stylesheets/SassyLists/_to-string.scss +13 -5
  39. data/stylesheets/SassyLists/_union.scss +1 -1
  40. data/stylesheets/SassyLists/_walk.scss +10 -5
  41. data/stylesheets/SassyLists/helpers/_is-number.scss +11 -0
  42. data/stylesheets/_SassyLists.scss +5 -0
  43. metadata +7 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5eaa4083a1a28198d2f0c464963ee950330bcf2a
4
- data.tar.gz: 49dabd33892af67244430c144a7b025313f61381
3
+ metadata.gz: 3bc911e8854740e20b09b1b091700972ff4f048d
4
+ data.tar.gz: 051110d6e5cce8ce43953e29f12e1c5922e3a949
5
5
  SHA512:
6
- metadata.gz: 92100eddaf4fbabfc5688ddff79c89100d9cfdf799bbd2bc1a24114729abacbddd1b6778588f28e08e9ca0d4b23d1a2adf8d3ec4860f4e1b335d86c7825c5d57
7
- data.tar.gz: 4b218a6e01215c618f35fa460e9a1cb07659364cb552b7c176c3c9e801b42817ac906bd3df06fdeed231367444aabf889e8e180110af6f328c1fac9b7bd316f3
6
+ metadata.gz: b2baf6768c31fa2a54b5d339ccd43e9a1d0907277dc03a4a1ba265abf8d6623298699b7ab964ef1236f76a59085807613fa34871ab802202e505fef782b387cb
7
+ data.tar.gz: e3ad19705d8548916c12456c1312e93496d7a1963d265fa1cf54efb7b41799aa0abc016ea9d3c5d6494d4a7d2ef561822162acc29a8f07650e03d2e391b382d1
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ * `2.2.0`:
4
+ * adding `sl-range()`, `sl-is-single()`, `sl-has-values()`, `sl-has-multiple-values()`
5
+ * updating `sl-sum()` and `sl-to-map()`
6
+ * making the whole library depending on most of the previously created helpers
7
+ * making most functions returning `list` type, even when returning a single value
3
8
  * `2.1.1`: fixing a tiny issue with dependency checker in `preprend()`
4
9
  * `2.1.0`: adding `sl-is-empty()`, `sl-to-list()` and `sl-comma-list()`
5
10
  * `2.0.0`:
data/README.md CHANGED
@@ -21,18 +21,22 @@ Here is a powerful toolbox providing you all the functions you need to manipulat
21
21
  * `sl-debug()`: returns list as a string
22
22
  * `sl-every()`: returns whether all items from list pass test from given function
23
23
  * `sl-explode()`: explodes a string into a list using a string as a delimiter
24
- * `sl-first()`: returns first item in list
24
+ * `sl-first()`: returns first value in list
25
25
  * `sl-flatten()`: turns multidimensional list into a one-level list
26
+ * `sl-has-values()`: checks if list is not empty
27
+ * `sl-has-multiple-values()`: checks if list has more than one value
26
28
  * `sl-insert-nth()`: inserts value at index
27
29
  * `sl-intersection()`: returns a list of shared values across all given lists
28
30
  * `sl-is-empty()`: checks if list is empty
31
+ * `sl-is-single()`: checks if list has a single value
29
32
  * `sl-is-symmetrical()`: checks if list is symmetrical
30
- * `sl-last()`: returns last item in list
33
+ * `sl-last()`: returns last value in list
31
34
  * `sl-last-index()`: returns last index of value in list
32
35
  * `sl-loop()`: shifts indexes in list
33
36
  * `sl-prepend()`: prepends value to list
34
37
  * `sl-purge()`: removes all `false` and `null` values from list
35
38
  * `sl-random-value()`: returns random value from list
39
+ * `sl-range()`: returns a list of values between 1 and given value
36
40
  * `sl-remove()`: removes value in list
37
41
  * `sl-remove-duplicates()`: removes duplicate values from list
38
42
  * `sl-remove-nth()`: removes value at index
@@ -42,14 +46,14 @@ Here is a powerful toolbox providing you all the functions you need to manipulat
42
46
  * `sl-shuffle()`: shuffles list
43
47
  * `sl-slice()`: slices list
44
48
  * `sl-sort()`: sorts list
45
- * `sl-some()`: returns whether some items from list pass test from given function
49
+ * `sl-some()`: returns whether some values from list pass test from given function
46
50
  * `sl-sum()`: sums all unitless values in list
47
51
  * `sl-tail()`: returns anything but the first element in list
48
52
  * `sl-to-list()`: casts value as list
49
53
  * `sl-to-map()`: casts list as map using indexes as keys
50
54
  * `sl-to-string()`: casts list as string (JS `.join()`)
51
55
  * `sl-union()`: returns a list of values from given lists minus duplicates
52
- * `sl-walk()`: applies a function to every item of list
56
+ * `sl-walk()`: applies a function to every value of list
53
57
 
54
58
  If you feel like an explorer, you can have a look at the code [here](https://github.com/Team-Sass/SassyLists/tree/master/stylesheets).
55
59
 
data/lib/SassyLists.rb CHANGED
@@ -15,7 +15,7 @@ end
15
15
  # Version is a number. If a version contains alphas, it will be created as a prerelease version
16
16
  # Date is in the form of YYYY-MM-DD
17
17
  module SassyLists
18
- VERSION = "2.1.1"
19
- DATE = "2014-07-02"
18
+ VERSION = "2.2.0"
19
+ DATE = "2014-07-03"
20
20
  end
21
21
 
@@ -7,16 +7,20 @@
7
7
  //
8
8
  // @throws $size is not a number for `sl-chunk`.
9
9
  //
10
+ // @requires sl-to-list
11
+ //
10
12
  // @return {List | Null}
11
13
 
12
14
  @function sl-chunk($list, $size) {
15
+ @if sl-missing-dependencies(sl-to-list) == true { @return null; }
16
+
13
17
  @if type-of($size) != "number" {
14
- @warn "#{$size} is not a number for `sl-chunk`.";
18
+ @warn "#{inspect($size)} is not a number for `sl-chunk`.";
15
19
  @return null;
16
20
  }
17
21
 
18
22
  @if $size >= length($list) {
19
- @return $list;
23
+ @return sl-to-list($list);
20
24
  }
21
25
 
22
26
  $index: 1;
@@ -30,8 +34,16 @@
30
34
  @for $j from 1 through $size {
31
35
  @if $index <= $length {
32
36
  $is-orphan: $length % $size == 1 and $j == 1;
33
- $tmp: if($is-orphan, nth($list, $index), append($tmp, nth($list, $index)));
37
+
38
+ @if $is-orphan {
39
+ $tmp: nth($list, $index);
40
+ }
41
+
42
+ @else {
43
+ $tmp: append($tmp, nth($list, $index), list-separator($list));
44
+ }
34
45
  }
46
+
35
47
  $index: $index + 1;
36
48
  }
37
49
 
@@ -11,6 +11,7 @@
11
11
  @return not not index($list, $value);
12
12
  }
13
13
 
14
+ // @requires sl-contain
14
15
  // @alias sl-contain
15
16
 
16
17
  @function sl-include($list, $value) {
@@ -6,14 +6,20 @@
6
6
  // @param {Bool} $pre (false) - enable/disable variables type and proper indentation
7
7
  // @param {Number} $level (1) - internal variable for recursion
8
8
  //
9
+ // @requires sl-is-empty
10
+ // @requires sl-is-single
11
+ // @requires sl-has-multiple-values
12
+ //
9
13
  // @return {String}
10
14
 
11
15
  @function sl-debug($list, $pre: false, $level: 1) {
12
- @if length($list) == 0 {
16
+ @if sl-missing-dependencies(sl-is-empty, sl-is-single, sl-has-multiple-values) == true { @return null; }
17
+
18
+ @if sl-is-empty($list) {
13
19
  @return "( )";
14
20
  }
15
21
 
16
- @if length($list) == 1 {
22
+ @if sl-is-single($list) {
17
23
  @return if($pre, "(" + type-of($list) + ") ", "") + $list;
18
24
  }
19
25
 
@@ -32,7 +38,7 @@
32
38
  $item: nth($list, $i);
33
39
  $result: $result + if($pre, $indent + $tab, " ");
34
40
 
35
- @if length($item) > 1 {
41
+ @if sl-has-multiple-values($item) {
36
42
  $result: $result
37
43
  + if($pre, "(list: " + length($item) + ") ", "")
38
44
  + sl-debug($item, $pre, $level + 1);
@@ -43,7 +49,7 @@
43
49
  $result: $result + "(" + type-of($item) + ") ";
44
50
  }
45
51
 
46
- @if length($item) == 0 {
52
+ @if sl-is-empty($item) {
47
53
  $result: $result + "( )";
48
54
  }
49
55
 
@@ -2,15 +2,16 @@
2
2
  //
3
3
  // @ignore Documentation: http://sassylists.com/documentation.html#sl-explode
4
4
  //
5
- // @param {String} $string - string to explode
6
- // @param {String} $separator ('') - string to use as a delimiter
5
+ // @param {String} $string - string to explode
6
+ // @param {String} $delimiter ('') - string to use as a delimiter
7
+ // @param {String} $separator ('space') - list separator
7
8
  //
8
9
  // @throws $string is not a string for `sl-explode`.
9
10
  // @throws $delimiter is not a string for `sl-explode`.
10
11
  //
11
12
  // @return {List | Null}
12
13
 
13
- @function sl-explode($string, $delimiter: '') {
14
+ @function sl-explode($string, $delimiter: '', $separator: "space") {
14
15
  @if type-of($string) != "string" {
15
16
  @warn "`sl-explode` function expecting a string; #{type-of($string)} given.";
16
17
  @return null;
@@ -23,6 +24,10 @@
23
24
 
24
25
  $result: ();
25
26
  $length: str-length($string);
27
+
28
+ @if not index("space" "comma", $separator) {
29
+ $separator: "space";
30
+ }
26
31
 
27
32
  @if str-length($delimiter) == 0 {
28
33
  @for $i from 1 through $length {
@@ -38,16 +43,16 @@
38
43
  @while $running {
39
44
  $index: str-index($remaining, $delimiter);
40
45
 
41
- @if not $index or $index == 0 {
46
+ @if not $index {
42
47
  $running: false;
43
48
  }
44
49
 
45
50
  @else {
46
51
  $slice: str-slice($remaining, 1, $index - 1);
47
- $result: append($result, $slice);
52
+ $result: append($result, $slice, $separator);
48
53
  $remaining: str-slice($remaining, $index + str-length($delimiter));
49
54
  }
50
55
  }
51
56
 
52
- @return append($result, $remaining);
57
+ @return append($result, $remaining, $separator);
53
58
  }
@@ -6,10 +6,14 @@
6
6
  //
7
7
  // @throws Cannot find first item of empty list.
8
8
  //
9
+ // @requires sl-is-empty
10
+ //
9
11
  // @return {*}
10
12
 
11
13
  @function sl-first($list) {
12
- @if length($list) == 0 {
14
+ @if sl-missing-dependencies(sl-is-empty) == true { @return null; }
15
+
16
+ @if sl-is-empty($list) {
13
17
  @warn "Cannot find first item of empty list.";
14
18
  @return null;
15
19
  }
@@ -17,6 +21,7 @@
17
21
  @return nth($list, 1);
18
22
  }
19
23
 
24
+ // @requires sl-first
20
25
  // @alias sl-first
21
26
 
22
27
  @function sl-head($list) {
@@ -3,19 +3,20 @@
3
3
  // @ignore Documentation: http://sassylists.com/documentation.html#flatten
4
4
  //
5
5
  // @param {List} $list - list to flatten
6
- //
6
+ //
7
+ // @requires sl-has-multiple-values
8
+ //
7
9
  // @return {List}
8
10
 
9
11
  @function sl-flatten($list) {
10
- $result: ();
12
+ @if sl-missing-dependencies(sl-has-multiple-values) == true { @return null; }
11
13
 
12
- @if length($list) == 1 {
13
- @return $list;
14
- }
14
+ $result: ();
15
15
 
16
16
  @each $item in $list {
17
- @if length($item) > 1 {
17
+ @if sl-has-multiple-values($item) {
18
18
  $flatten: sl-flatten($item);
19
+
19
20
  @each $i in $flatten {
20
21
  $result: append($result, $i, list-separator($list));
21
22
  }
@@ -29,6 +30,7 @@
29
30
  @return $result;
30
31
  }
31
32
 
33
+ // @requires sl-flatten
32
34
  // @alias sl-flatten
33
35
 
34
36
  @function sl-unfold($list) {
@@ -0,0 +1,11 @@
1
+ // Tests whether `$list` has at least 2 values.
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation.html#sl-has-multiple-values
4
+ //
5
+ // @param {List} $list - list to run test against
6
+ //
7
+ // @return {Bool}
8
+
9
+ @function sl-has-multiple-values($list) {
10
+ @return length($list) > 1;
11
+ }
@@ -0,0 +1,11 @@
1
+ // Tests whether `$list` is not empty.
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation.html#sl-has-values
4
+ //
5
+ // @param {List} $list - list to run test against
6
+ //
7
+ // @return {Bool}
8
+
9
+ @function sl-has-values($list) {
10
+ @return length($list) > 0;
11
+ }
@@ -18,8 +18,8 @@
18
18
 
19
19
  $length: length($list);
20
20
 
21
- @if type-of($index) != number {
22
- @warn "List index #{$index} is not a number for `sl-insert-nth`.";
21
+ @if type-of($index) != "number" {
22
+ @warn "List index #{inspect($index)} is not a number for `sl-insert-nth`.";
23
23
  @return null;
24
24
  }
25
25
 
@@ -3,6 +3,7 @@
3
3
  // @ignore Documentation: http://sassylists.com/documentation.html#sl-intersection
4
4
  //
5
5
  // @requires sl-remove-duplicates
6
+ // @requires sl-to-list
6
7
  //
7
8
  // @param {List} $list - first list
8
9
  // @param {ArgList} $lists - other lists
@@ -26,6 +27,5 @@
26
27
  $result: $temp;
27
28
  }
28
29
 
29
- $result: sl-remove-duplicates($result);
30
- @return if(length($result) == 1, nth($result, 1), $result);
31
- }
30
+ @return sl-remove-duplicates($result);
31
+ }
@@ -15,4 +15,4 @@
15
15
 
16
16
  @function sl-empty($list) {
17
17
  @return sl-is-empty($list);
18
- }
18
+ }
@@ -0,0 +1,11 @@
1
+ // Tests whether `$list` has a single item.
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation.html#sl-is-single
4
+ //
5
+ // @param {List} $list - list to run test against
6
+ //
7
+ // @return {Bool}
8
+
9
+ @function sl-is-single($list) {
10
+ @return length($list) == 1;
11
+ }
@@ -14,6 +14,7 @@
14
14
  @return $list == sl-reverse($list);
15
15
  }
16
16
 
17
+ // @requires sl-is-symmetrical
17
18
  // @alias sl-is-symmetrical
18
19
 
19
20
  @function sl-is-mirror($list) {
@@ -8,9 +8,7 @@
8
8
  // @return {Number | Null}
9
9
 
10
10
  @function sl-last-index($list, $value) {
11
- $length: length($list);
12
-
13
- @for $i from $length through 1 {
11
+ @for $i from length($list) through 1 {
14
12
  @if nth($list, $i) == $value {
15
13
  @return $i;
16
14
  }
@@ -6,10 +6,14 @@
6
6
  //
7
7
  // @throws Cannot find last item of empty list.
8
8
  //
9
+ // @requires sl-is-empty
10
+ //
9
11
  // @return {*}
10
12
 
11
13
  @function sl-last($list) {
12
- @if length($list) == 0 {
14
+ @if sl-missing-dependencies(sl-is-empty) == true { @return null; }
15
+
16
+ @if sl-is-empty($list) {
13
17
  @warn "Cannot find last item of empty list.";
14
18
  @return null;
15
19
  }
@@ -9,15 +9,19 @@
9
9
  //
10
10
  // @throws $value is not a number for `loop`.
11
11
  //
12
+ // @requires sl-has-multiple-values
13
+ //
12
14
  // @return {List | Null}
13
15
 
14
16
  @function sl-loop($list, $value: 1) {
17
+ @if sl-missing-dependencies(sl-has-multiple-values) == true { @return null; }
18
+
15
19
  @if type-of($value) != "number" {
16
- @warn "#{$value} is not a number for `sl-loop`.";
20
+ @warn "#{inspect($value)} is not a number for `sl-loop`.";
17
21
  @return null;
18
22
  }
19
23
 
20
- @if length($list) < 2 {
24
+ @if not sl-has-multiple-values($list) {
21
25
  @return $list;
22
26
  }
23
27
 
@@ -31,6 +35,7 @@
31
35
  @return $result;
32
36
  }
33
37
 
38
+ // @requires sl-loop
34
39
  // @alias sl-loop
35
40
 
36
41
  @function sl-shift-indexes($list, $value: 1) {
@@ -3,6 +3,7 @@
3
3
  // @ignore Documentation: http://sassylists.com/documentation.html#sl-prepend
4
4
  //
5
5
  // @requires sl-is-true
6
+ // @requires sl-to-list
6
7
  //
7
8
  // @param {List} $list - list to preprend value to
8
9
  // @param {*} $value - value to prepend to the list
@@ -10,13 +11,11 @@
10
11
  // @return {List}
11
12
 
12
13
  @function sl-prepend($list, $value) {
13
- @if sl-missing-dependencies(sl-is-true) == true { @return null; }
14
+ @if sl-missing-dependencies(sl-is-true, sl-to-list) == true { @return null; }
14
15
 
15
16
  @if sl-is-true($value) {
16
- @return join($value, $list, list-separator($list));
17
+ $list: join($value, $list, list-separator($list));
17
18
  }
18
19
 
19
- @else {
20
- @return $list;
21
- }
20
+ @return sl-to-list($list);
22
21
  }
@@ -3,13 +3,14 @@
3
3
  // @ignore Documentation: http://sassylists.com/documentation.html#purge
4
4
  //
5
5
  // @requires sl-is-true
6
+ // @requires sl-to-list
6
7
  //
7
8
  // @param {List} $list - list to purge
8
9
  //
9
10
  // @return {List}
10
11
 
11
12
  @function sl-purge($list) {
12
- @if sl-missing-dependencies(sl-is-true) == true { @return null; }
13
+ @if sl-missing-dependencies(sl-is-true, sl-to-list) == true { @return null; }
13
14
 
14
15
  $result: ();
15
16
 
@@ -19,9 +20,10 @@
19
20
  }
20
21
  }
21
22
 
22
- @return $result;
23
+ @return sl-to-list($result);
23
24
  }
24
25
 
26
+ // @requires sl-purge
25
27
  // @alias sl-purge
26
28
 
27
29
  @function sl-clean($list) {
@@ -6,23 +6,29 @@
6
6
  //
7
7
  // @throws Cannot find a random value in an empty list.
8
8
  //
9
+ // @requires sl-is-empty
10
+ //
9
11
  // @return {*}
10
12
 
11
13
  @function sl-random-value($list) {
12
- @if length($list) == 0 {
14
+ @if sl-missing-dependencies(sl-is-empty) == true { @return null; }
15
+
16
+ @if sl-is-empty($list) {
13
17
  @warn "Cannot find a random value in an empty list.";
14
18
  @return null;
15
19
  }
16
20
 
17
- @return nth($list, random(length($list)));
21
+ @return nth($list, random(length($list) - 1) + 1);
18
22
  }
19
23
 
24
+ // @requires sl-random-value
20
25
  // @alias sl-random-value
21
26
 
22
27
  @function sl-roll($list) {
23
28
  @return sl-random-value($list);
24
29
  }
25
30
 
31
+ // @requires sl-random-value
26
32
  // @alias sl-random-value
27
33
 
28
34
  @function sl-luck($list) {
@@ -0,0 +1,40 @@
1
+ // Build a list of values from 1 through `$n`.
2
+ //
3
+ // @ignore Documentation: http://sassylists.com/documentation.html#sl-range
4
+ //
5
+ // @param {Number} $n - maximum value
6
+ //
7
+ // @throws `$n` is not a number for `sl-range`.
8
+ // @throws `$n` is not unitless for `sl-range`.
9
+ // @throws `$n` is not greater than 0 for `sl-range`.
10
+ //
11
+ // @return {List | Number | Null}
12
+
13
+ @function sl-range($n) {
14
+ @if type-of($n) != "number" {
15
+ @warn "`#{inspect($n)}` is not a number for `sl-range`.";
16
+ @return null;
17
+ }
18
+
19
+ @if not unitless($n) {
20
+ @warn "`#{$n}` is not unitless for `sl-range`.";
21
+ @return null;
22
+ }
23
+
24
+ @if $n < 1 {
25
+ @warn "`#{$n}` is not greater than 0 for `sl-range`.";
26
+ @return null;
27
+ }
28
+
29
+ @if $n == 1 {
30
+ @return $n;
31
+ }
32
+
33
+ $range: ();
34
+
35
+ @for $i from 1 through $n {
36
+ $range: append($range, $i);
37
+ }
38
+
39
+ @return $range;
40
+ }
@@ -4,9 +4,13 @@
4
4
  //
5
5
  // @param {List} $list - list to remove duplicates from
6
6
  //
7
+ // @requires sl-to-list
8
+ //
7
9
  // @return {List}
8
10
 
9
11
  @function sl-remove-duplicates($list) {
12
+ @if sl-missing-dependencies(sl-to-list) == true { @return null; }
13
+
10
14
  $result: ();
11
15
 
12
16
  @each $item in $list {
@@ -15,11 +19,12 @@
15
19
  }
16
20
  }
17
21
 
18
- @return $result;
22
+ @return sl-to-list($result);
19
23
  }
20
24
 
25
+ // @requires sl-remove-duplicates
21
26
  // @alias sl-remove-duplicates
22
27
 
23
- @function sl-unique($list, $recursive: false) {
24
- @return sl-remove-duplicates($list, $recursive);
28
+ @function sl-unique($list) {
29
+ @return sl-remove-duplicates($list);
25
30
  }
@@ -15,6 +15,7 @@
15
15
  @return sl-replace-nth($list, $index, "");
16
16
  }
17
17
 
18
+ // @requires sl-remove-nth
18
19
  // @alias sl-remove-nth
19
20
 
20
21
  @function sl-without-nth($list, $index) {
@@ -16,6 +16,7 @@
16
16
  @return sl-replace($list, $value, null);
17
17
  }
18
18
 
19
+ // @requires sl-remove
19
20
  // @alias sl-remove
20
21
 
21
22
  @function sl-without($list, $value) {
@@ -4,6 +4,7 @@
4
4
  //
5
5
  // @requires sl-purge
6
6
  // @requires sl-is-true
7
+ // @requires sl-to-list
7
8
  //
8
9
  // @param {List} $list - list to update
9
10
  // @param {Number} $index - index to update
@@ -14,13 +15,15 @@
14
15
  // @return {List | Null}
15
16
 
16
17
  @function sl-replace-nth($list, $index, $value) {
17
- @if sl-missing-dependencies(sl-purge, sl-is-true) == true { @return null; }
18
+ @if sl-missing-dependencies(sl-purge, sl-is-true, sl-to-list) == true { @return null; }
18
19
 
19
20
  @if type-of($index) != "number" or $index == 0 or abs($index) > length($list) {
20
- @warn "Invalid index (#{$index}) for `sl-replace-nth`.";
21
+ @warn "Invalid index (#{inspect($index)}) for `sl-replace-nth`.";
21
22
  @return null;
22
23
  }
23
24
 
24
25
  $list: set-nth($list, $index, $value);
25
- @return if(not sl-is-true($value), sl-purge($list), $list);
26
+ $list: if(sl-is-true($value), $list, sl-purge($list));
27
+
28
+ @return sl-to-list($list);
26
29
  }
@@ -4,6 +4,7 @@
4
4
  //
5
5
  // @requires sl-is-true
6
6
  // @requires sl-purge
7
+ // @requires sl-to-list
7
8
  //
8
9
  // @param {List} $list - list to update
9
10
  // @param {*} $old - value to replace
@@ -12,7 +13,7 @@
12
13
  // @return {List}
13
14
 
14
15
  @function sl-replace($list, $old, $value) {
15
- @if sl-missing-dependencies(sl-is-true, sl-purge) == true { @return null; }
16
+ @if sl-missing-dependencies(sl-is-true, sl-purge, sl-to-list) == true { @return null; }
16
17
 
17
18
  $running: true;
18
19
 
@@ -29,5 +30,7 @@
29
30
 
30
31
  }
31
32
 
32
- @return if(not sl-is-true($value), sl-purge($list), $list);
33
+ $list: if(sl-is-true($value), $list, sl-purge($list));
34
+
35
+ @return sl-to-list($list);
33
36
  }
@@ -4,11 +4,15 @@
4
4
  //
5
5
  // @param {List} $list - list to reverse
6
6
  //
7
+ // @requires sl-to-list
8
+ //
7
9
  // @return {List}
8
10
 
9
11
  @function sl-reverse($list) {
12
+ @if sl-missing-dependencies(sl-to-list) == true { @return null; }
13
+
10
14
  $length: length($list);
11
- $end: floor($length/2);
15
+ $end: floor($length / 2);
12
16
 
13
17
  @if $length < 2 {
14
18
  @return $list;
@@ -20,9 +24,10 @@
20
24
  $list: set-nth($list, -$i, $tmp);
21
25
  }
22
26
 
23
- @return $list;
27
+ @return sl-to-list($list);
24
28
  }
25
29
 
30
+ // @requires sl-reverse
26
31
  // @alias sl-reverse
27
32
 
28
33
  @function sl-mirror($list) {
@@ -4,9 +4,13 @@
4
4
  //
5
5
  // @param {List} $list - list to shuffle
6
6
  //
7
+ // @requires sl-to-list
8
+ //
7
9
  // @return {List}
8
10
 
9
11
  @function sl-shuffle($list) {
12
+ @if sl-missing-dependencies(sl-to-list) == true { @return null; }
13
+
10
14
  $length: length($list);
11
15
 
12
16
  @if $length < 2 {
@@ -20,9 +24,10 @@
20
24
  $list: set-nth($list, $j, $tmp);
21
25
  }
22
26
 
23
- @return $list;
27
+ @return sl-to-list($list);
24
28
  }
25
29
 
30
+ // @requires sl-shuffle
26
31
  // @alias sl-shuffle
27
32
 
28
33
  @function sl-randomize($list) {
@@ -40,10 +40,6 @@
40
40
  @return null;
41
41
  }
42
42
 
43
- @if $start == $end {
44
- @return nth($list, $start);
45
- }
46
-
47
43
  $result: ();
48
44
 
49
45
  @for $i from $start through $end {
@@ -3,6 +3,8 @@
3
3
  // @ignore Documentation: http://sassylists.com/documentation.html#sl-sort
4
4
  //
5
5
  // @requires sl-str-compare
6
+ // @requires sl-has-multiple-values
7
+ // @requires sl-to-list
6
8
  //
7
9
  // @param {List} $list - list to sort
8
10
  // @param {List} $order - order to respect
@@ -10,31 +12,36 @@
10
12
  // @return {List}
11
13
 
12
14
  @function sl-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
- @if sl-missing-dependencies(sl-str-compare) == true { @return null; }
15
+ @if sl-missing-dependencies(sl-str-compare, sl-has-multiple-values, sl-to-list) == true { @return null; }
14
16
 
15
17
  $less: ();
16
18
  $equal: ();
17
19
  $large: ();
18
- $length: length($list);
19
20
 
20
- @if $length > 1 {
21
- $seed: nth($list, ceil($length / 2));
21
+ @if sl-has-multiple-values($list) {
22
+ $seed: nth($list, ceil(length($list) / 2));
23
+
22
24
  @each $item in $list {
23
25
  @if $item == $seed {
24
26
  $equal: append($equal, $item, list-separator($list));
25
27
  }
28
+
26
29
  @else if sl-str-compare($item, $seed, $order) {
27
30
  $less: append($less, $item, list-separator($list));
28
31
  }
32
+
29
33
  @else if not sl-str-compare($item, $seed, $order) {
30
34
  $large: append($large, $item, list-separator($list));
31
35
  }
32
36
  }
37
+
33
38
  @return join(join(sl-sort($less, $order), $equal), sl-sort($large, $order));
34
39
  }
35
- @return $list;
40
+
41
+ @return sl-to-list($list);
36
42
  }
37
43
 
44
+ // @requires sl-sort
38
45
  // @alias sl-sort
39
46
 
40
47
  @function sl-order($list) {
@@ -2,27 +2,33 @@
2
2
  //
3
3
  // @ignore Documentation: http://sassylists.com/documentation.html#sl-sum
4
4
  //
5
- // @param {List} $list - list
5
+ // @param {List} $list - list
6
6
  // @param {Bool} $force (false) - enable/disable parseInt
7
7
  //
8
+ // @requires sl-every
9
+ // @requires sl-is-number
10
+ //
11
+ // @throws All items from list are not numbers for `sl-sum`.
12
+ //
8
13
  // @return {Number}
9
14
 
10
15
  @function sl-sum($list, $force: false) {
11
16
  $result: 0;
12
17
 
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
- }
18
+ @if not sl-every($list, sl-is-number) {
19
+ @warn "All items from list are not numbers for `sl-sum`.";
20
+ @return null;
21
+ }
19
22
 
20
- @if unitless($item) {
21
- $result: $result + $item;
22
- }
23
+ @each $item in $list {
24
+ @if not unitless($item) and $force {
25
+ $item: $item / ($item * 0 + 1);
26
+ }
23
27
 
28
+ @if unitless($item) {
29
+ $result: $result + $item;
24
30
  }
25
31
  }
26
32
 
27
33
  @return $result;
28
- }
34
+ }
@@ -14,6 +14,7 @@
14
14
  @return sl-slice($list, 2);
15
15
  }
16
16
 
17
+ // @requires sl-tail
17
18
  // @alias sl-tail
18
19
 
19
20
  @function sl-rest($list) {
@@ -3,11 +3,22 @@
3
3
  // @ignore Documentation: http://sassylists.com/documentation.html#sl-to-list
4
4
  //
5
5
  // @param {*} $value - value to cast to list
6
+ // @param {String} $separator (space) - separator to use
6
7
  //
7
8
  // @return {List}
8
9
 
9
- @function sl-to-list($value) {
10
- @return if(type-of($value) == "list", $value, ($value,));
10
+ @function sl-to-list($value, $separator: list-separator($value)) {
11
+ @if type-of($value) != "list" or list-separator($value) != $separator {
12
+ $new-list: if($separator == "comma", sl-comma-list(), ());
13
+
14
+ @each $item in $value {
15
+ $new-list: append($new-list, $item, $separator);
16
+ }
17
+
18
+ @return $new-list;
19
+ }
20
+
21
+ @return $value;
11
22
  }
12
23
 
13
24
  // @requires sl-to-list
@@ -1,39 +1,29 @@
1
1
  // Casts `$list` into a map, using indexes as keys (starting with `$start`).
2
2
  // Useful for iterating through a list with an index variable.
3
- // e.g. `@each $i, $value in to-map($list)`
3
+ // e.g. `@each $index, $value in to-map($list)`
4
4
  //
5
- // @author Andrey "Lolmaus" Mikhaylov
5
+ // @author Andrey "Lolmaus" Mikhaylov and Chris Eppstein
6
6
  //
7
7
  // @ignore Documentation: http://sassylists.com/documentation.html#sl-to-map
8
8
  //
9
- // @param {List} $list - list to turn into map
10
- // @param {Number} $start (1) - index to start with
9
+ // @param {List} $list - list to turn into map
10
+ //
11
+ // @requires sl-range
12
+ // @requires sl-is-empty
11
13
  //
12
14
  // @throws List cannot be empty for `sl-to-map`.
13
- // @throws $start is not a number for `sl-to-map`.
14
15
  //
15
16
  // @return {Map | Null}
16
17
 
17
- @function sl-to-map($list, $start: 1) {
18
- @if length($list) == 0 {
19
- @warn "List cannot be empty for `sl-to-map`.";
20
- @return null;
21
- }
18
+ @function sl-to-map($list) {
19
+ @if sl-missing-dependencies(sl-range, sl-is-empty) == true { @return null; }
22
20
 
23
- @if type-of($start) != "number" {
24
- @warn "$start provided to `sl-to-map` was #{type-of($start)}, but it should be a number.";
21
+ @if sl-is-empty($list) {
22
+ @warn "List cannot be empty for `sl-to-map`.";
25
23
  @return null;
26
24
  }
27
25
 
28
- $map: ();
29
-
30
- @for $index from 1 through length($list) {
31
- $key: $index + $start - 1;
32
- $value: nth($list, $index);
33
- $map: map-merge($map, ($key: $value));
34
- }
35
-
36
- @return $map;
26
+ @return zip(sl-range(length($list)), $list);
37
27
  }
38
28
 
39
29
  // @requires sl-to-map
@@ -5,20 +5,28 @@
5
5
  // @param {List} $list - list to cast
6
6
  // @param {String} $glue ('') - value to use as a join string
7
7
  //
8
+ // @requires sl-has-multiple-values
9
+ // @requires sl-last
10
+ //
8
11
  // @return {String}
9
12
 
10
13
  @function sl-to-string($list, $glue: '') {
14
+ @if sl-missing-dependencies(sl-has-multiple-values) == true { @return null; }
15
+
11
16
  $result: '';
12
- $length: length($list);
13
17
 
14
- @for $i from 1 through $length {
15
- $item: nth($list, $i);
16
- $result: $result + if(length($item) > 1, sl-to-string($item, $glue), $item + $glue);
18
+ @each $item in $list {
19
+ $result: $result + if(sl-has-multiple-values($item), sl-to-string($item, $glue), $item);
20
+
21
+ @if $item != sl-last($list) {
22
+ $result: $result + $glue;
23
+ }
17
24
  }
18
25
 
19
- @return quote(str-slice($result, 1, str-length($glue) * -1 - 1));
26
+ @return quote($result);
20
27
  }
21
28
 
29
+ // @requires sl-to-string
22
30
  // @alias sl-to-string
23
31
 
24
32
  @function sl-stringify($list, $glue: '') {
@@ -14,7 +14,7 @@
14
14
 
15
15
  $result: sl-remove-duplicates(sl-flatten($lists));
16
16
 
17
- @return if(length($result) == 1, nth($result, 1), $result);
17
+ @return $result;
18
18
  }
19
19
 
20
20
  // @alias sl-union
@@ -6,19 +6,24 @@
6
6
  // @param {String} $function - function to call on each value
7
7
  // @param {ArgList} $args - optional function arguments
8
8
  //
9
- // @throws There is no $function function.
9
+ // @throws There is no `$function` function for `sl-walk`.
10
+ //
11
+ // @requires sl-to-map
12
+ // @requires sl-to-list
10
13
  //
11
14
  // @return {List | Null}
12
15
 
13
16
  @function sl-walk($list, $function, $args...) {
17
+ @if sl-missing-dependencies(sl-to-map, sl-to-list) == true { @return null; }
18
+
14
19
  @if not function-exists($function) {
15
- @warn "There is no `#{$function}` function.";
20
+ @warn "There is no `#{$function}` function for `sl-walk`.";
16
21
  @return null;
17
22
  }
18
23
 
19
- @for $i from 1 through length($list) {
20
- $list: set-nth($list, $i, call($function, nth($list, $i), $args...));
24
+ @each $index, $value in sl-to-map($list) {
25
+ $list: set-nth($list, $index, call($function, $value, $args...));
21
26
  }
22
27
 
23
- @return $list;
28
+ @return sl-to-list($list);
24
29
  }
@@ -0,0 +1,11 @@
1
+ // Check whether value is a number
2
+ //
3
+ // @access private
4
+ //
5
+ // @param {*} $value - value to run test against
6
+ //
7
+ // @return {Bool}
8
+
9
+ @function sl-is-number($value) {
10
+ @return type-of($value) == "number";
11
+ }
@@ -7,6 +7,7 @@
7
7
  @import "SassyLists/helpers/missing-dependencies";
8
8
  @import "SassyLists/helpers/str-compare";
9
9
  @import "SassyLists/helpers/true";
10
+ @import "SassyLists/helpers/is-number";
10
11
  @import "SassyLists/chunk";
11
12
  @import "SassyLists/comma-list";
12
13
  @import "SassyLists/contain";
@@ -16,9 +17,12 @@
16
17
  @import "SassyLists/explode";
17
18
  @import "SassyLists/first";
18
19
  @import "SassyLists/flatten";
20
+ @import "SassyLists/has-values";
21
+ @import "SassyLists/has-multiple-values";
19
22
  @import "SassyLists/insert-nth";
20
23
  @import "SassyLists/intersection";
21
24
  @import "SassyLists/is-empty";
25
+ @import "SassyLists/is-single";
22
26
  @import "SassyLists/is-symmetrical";
23
27
  @import "SassyLists/last";
24
28
  @import "SassyLists/last-index";
@@ -26,6 +30,7 @@
26
30
  @import "SassyLists/prepend";
27
31
  @import "SassyLists/purge";
28
32
  @import "SassyLists/random-value";
33
+ @import "SassyLists/range";
29
34
  @import "SassyLists/remove";
30
35
  @import "SassyLists/remove-duplicates";
31
36
  @import "SassyLists/remove-nth";
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: SassyLists
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hugo Giraudel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-02 00:00:00.000000000 Z
11
+ date: 2014-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sass
@@ -44,9 +44,12 @@ files:
44
44
  - stylesheets/SassyLists/_explode.scss
45
45
  - stylesheets/SassyLists/_first.scss
46
46
  - stylesheets/SassyLists/_flatten.scss
47
+ - stylesheets/SassyLists/_has-multiple-values.scss
48
+ - stylesheets/SassyLists/_has-values.scss
47
49
  - stylesheets/SassyLists/_insert-nth.scss
48
50
  - stylesheets/SassyLists/_intersection.scss
49
51
  - stylesheets/SassyLists/_is-empty.scss
52
+ - stylesheets/SassyLists/_is-single.scss
50
53
  - stylesheets/SassyLists/_is-symmetrical.scss
51
54
  - stylesheets/SassyLists/_last-index.scss
52
55
  - stylesheets/SassyLists/_last.scss
@@ -54,6 +57,7 @@ files:
54
57
  - stylesheets/SassyLists/_prepend.scss
55
58
  - stylesheets/SassyLists/_purge.scss
56
59
  - stylesheets/SassyLists/_random-value.scss
60
+ - stylesheets/SassyLists/_range.scss
57
61
  - stylesheets/SassyLists/_remove-duplicates.scss
58
62
  - stylesheets/SassyLists/_remove-nth.scss
59
63
  - stylesheets/SassyLists/_remove.scss
@@ -71,6 +75,7 @@ files:
71
75
  - stylesheets/SassyLists/_to-string.scss
72
76
  - stylesheets/SassyLists/_union.scss
73
77
  - stylesheets/SassyLists/_walk.scss
78
+ - stylesheets/SassyLists/helpers/_is-number.scss
74
79
  - stylesheets/SassyLists/helpers/_missing-dependencies.scss
75
80
  - stylesheets/SassyLists/helpers/_str-compare.scss
76
81
  - stylesheets/SassyLists/helpers/_true.scss