ListFunctions 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. data/lib/ListFunctions.rb +29 -29
  2. data/stylesheets/ListFunctions/_chunk.scss +32 -32
  3. data/stylesheets/ListFunctions/_count-values.scss +32 -32
  4. data/stylesheets/ListFunctions/_debug.scss +34 -34
  5. data/stylesheets/ListFunctions/_first.scss +12 -12
  6. data/stylesheets/ListFunctions/_insert-nth.scss +51 -51
  7. data/stylesheets/ListFunctions/_is-symmetrical.scss +22 -22
  8. data/stylesheets/ListFunctions/_last-index.scss +24 -24
  9. data/stylesheets/ListFunctions/_last.scss +12 -12
  10. data/stylesheets/ListFunctions/_loop.scss +20 -20
  11. data/stylesheets/ListFunctions/_prepend.scss +15 -15
  12. data/stylesheets/ListFunctions/_purge.scss +20 -20
  13. data/stylesheets/ListFunctions/_remove-duplicates.scss +29 -29
  14. data/stylesheets/ListFunctions/_remove-nth.scss +22 -22
  15. data/stylesheets/ListFunctions/_remove.scss +18 -18
  16. data/stylesheets/ListFunctions/_replace-nth.scss +49 -49
  17. data/stylesheets/ListFunctions/_replace.scss +31 -31
  18. data/stylesheets/ListFunctions/_reverse.scss +29 -29
  19. data/stylesheets/ListFunctions/_slice.scss +59 -59
  20. data/stylesheets/ListFunctions/_sort.scss +42 -0
  21. data/stylesheets/ListFunctions/_sum.scss +32 -32
  22. data/stylesheets/ListFunctions/_to-string.scss +28 -28
  23. data/stylesheets/_ListFunctions.scss +94 -90
  24. data/templates/project/sass/ListFunctions/_chunk.scss +32 -32
  25. data/templates/project/sass/ListFunctions/_count-values.scss +32 -32
  26. data/templates/project/sass/ListFunctions/_debug.scss +34 -34
  27. data/templates/project/sass/ListFunctions/_first.scss +12 -12
  28. data/templates/project/sass/ListFunctions/_insert-nth.scss +51 -51
  29. data/templates/project/sass/ListFunctions/_is-symmetrical.scss +22 -22
  30. data/templates/project/sass/ListFunctions/_last-index.scss +24 -24
  31. data/templates/project/sass/ListFunctions/_last.scss +12 -12
  32. data/templates/project/sass/ListFunctions/_loop.scss +20 -20
  33. data/templates/project/sass/ListFunctions/_prepend.scss +15 -15
  34. data/templates/project/sass/ListFunctions/_purge.scss +20 -20
  35. data/templates/project/sass/ListFunctions/_remove-duplicates.scss +29 -29
  36. data/templates/project/sass/ListFunctions/_remove-nth.scss +22 -22
  37. data/templates/project/sass/ListFunctions/_remove.scss +18 -18
  38. data/templates/project/sass/ListFunctions/_replace-nth.scss +49 -49
  39. data/templates/project/sass/ListFunctions/_replace.scss +31 -31
  40. data/templates/project/sass/ListFunctions/_reverse.scss +29 -29
  41. data/templates/project/sass/ListFunctions/_slice.scss +59 -59
  42. data/templates/project/sass/ListFunctions/_sum.scss +32 -32
  43. data/templates/project/sass/ListFunctions/_to-string.scss +28 -28
  44. data/templates/project/sass/_ListFunctions.scss +90 -90
  45. metadata +18 -11
  46. checksums.yaml +0 -7
@@ -1,30 +1,30 @@
1
- /**
2
- * Reverses the order of $list
3
- * -------------------------------------------------------------------------------
4
- * @example reverse( (a, b, c) ) => c, b, a
5
- * @example reverse( (a, b, c a) ) => c a, b, a
6
- * @example reverse( (a, b, c a), true ) => a c, b, a
7
- * @example reverse( a ) => a
8
- * -------------------------------------------------------------------------------
9
- * @param $list [List] : list
10
- * @param $recursive [Boolean] : enable / disable recursivity
11
- * -------------------------------------------------------------------------------
12
- * @return [List]
13
- */
14
- @function reverse($list, $recursive: false) {
15
- $result: ();
16
-
17
- @for $i from length($list) * -1 through -1 {
18
- $item: nth($list, abs($i));
19
-
20
- @if length($item) > 1 and $recursive {
21
- $result: append($result, reverse($item, $recursive));
22
- }
23
-
24
- @else {
25
- $result: append($result, $item);
26
- }
27
- }
28
-
29
- @return $result;
1
+ /**
2
+ * Reverses the order of $list
3
+ * -------------------------------------------------------------------------------
4
+ * @example reverse( (a, b, c) ) => c, b, a
5
+ * @example reverse( (a, b, c a) ) => c a, b, a
6
+ * @example reverse( (a, b, c a), true ) => a c, b, a
7
+ * @example reverse( a ) => a
8
+ * -------------------------------------------------------------------------------
9
+ * @param $list [List] : list
10
+ * @param $recursive [Boolean] : enable / disable recursivity
11
+ * -------------------------------------------------------------------------------
12
+ * @return [List]
13
+ */
14
+ @function reverse($list, $recursive: false) {
15
+ $result: ();
16
+
17
+ @for $i from length($list) * -1 through -1 {
18
+ $item: nth($list, abs($i));
19
+
20
+ @if length($item) > 1 and $recursive {
21
+ $result: append($result, reverse($item, $recursive));
22
+ }
23
+
24
+ @else {
25
+ $result: append($result, $item);
26
+ }
27
+ }
28
+
29
+ @return $result;
30
30
  }
@@ -1,60 +1,60 @@
1
- /**
2
- * Slices $list between $start and $end
3
- * -------------------------------------------------------------------------------
4
- * @example slice( (a, b, c, d), 2, 3 ) => b, c
5
- * @example slice( (a, b, c, d), 3, 2 ) => error
6
- * @example slice( (a, b, c, d), 3, 5 ) => error
7
- * @example slice( (a, b, c, d), -1, 3 ) => error
8
- * @example slice( (a, b, c, d), 0, 3 ) => error
9
- * @example slice( (a, b, c, d), 3, 3 ) => c
10
- * -------------------------------------------------------------------------------
11
- * @param $list [List] : list
12
- * @param $start [Number] : start index
13
- * @param $end [Number] : end index
14
- * -------------------------------------------------------------------------------
15
- * @raise [Error] if $start or $end aren't integers
16
- * @raise [Error] if $start is greater than $end
17
- * @raise [Error] if $start or $end is strictly lesser than 1
18
- * @raise [Error] if $start is strictly greater than length of $list
19
- * @raise [Error] if $end is strictly greater than length of $list
20
- * -------------------------------------------------------------------------------
21
- * @return [List] | false
22
- */
23
- @function slice($list, $start: 1, $end: length($list)) {
24
- $result: false;
25
-
26
- @if type-of($start) != number or type-of($end) != number {
27
- @warn "Either $start or $end are not a number for `slice`.";
28
- @return $result;
29
- }
30
-
31
- @else if $start > $end {
32
- @warn "The start index has to be lesser than or equals to the end index for `slice`.";
33
- @return $result;
34
- }
35
-
36
- @else if $start < 1 or $end < 1 {
37
- @warn "List indexes must be non-zero integers for `slice`.";
38
- @return $result;
39
- }
40
-
41
- @else if $start > length($list) {
42
- @warn "List index is #{$start} but list is only #{length($list)} item long for `slice`.";
43
- @return $result;
44
- }
45
-
46
- @else if $end > length($list) {
47
- @warn "List index is #{$end} but list is only #{length($list)} item long for `slice`.";
48
- @return $result;
49
- }
50
-
51
- @else {
52
- $result: ();
53
-
54
- @for $i from $start through $end {
55
- $result: append($result, nth($list, $i));
56
- }
57
- }
58
-
59
- @return $result;
1
+ /**
2
+ * Slices $list between $start and $end
3
+ * -------------------------------------------------------------------------------
4
+ * @example slice( (a, b, c, d), 2, 3 ) => b, c
5
+ * @example slice( (a, b, c, d), 3, 2 ) => error
6
+ * @example slice( (a, b, c, d), 3, 5 ) => error
7
+ * @example slice( (a, b, c, d), -1, 3 ) => error
8
+ * @example slice( (a, b, c, d), 0, 3 ) => error
9
+ * @example slice( (a, b, c, d), 3, 3 ) => c
10
+ * -------------------------------------------------------------------------------
11
+ * @param $list [List] : list
12
+ * @param $start [Number] : start index
13
+ * @param $end [Number] : end index
14
+ * -------------------------------------------------------------------------------
15
+ * @raise [Error] if $start or $end aren't integers
16
+ * @raise [Error] if $start is greater than $end
17
+ * @raise [Error] if $start or $end is strictly lesser than 1
18
+ * @raise [Error] if $start is strictly greater than length of $list
19
+ * @raise [Error] if $end is strictly greater than length of $list
20
+ * -------------------------------------------------------------------------------
21
+ * @return [List] | false
22
+ */
23
+ @function slice($list, $start: 1, $end: length($list)) {
24
+ $result: false;
25
+
26
+ @if type-of($start) != number or type-of($end) != number {
27
+ @warn "Either $start or $end are not a number for `slice`.";
28
+ @return $result;
29
+ }
30
+
31
+ @else if $start > $end {
32
+ @warn "The start index has to be lesser than or equals to the end index for `slice`.";
33
+ @return $result;
34
+ }
35
+
36
+ @else if $start < 1 or $end < 1 {
37
+ @warn "List indexes must be non-zero integers for `slice`.";
38
+ @return $result;
39
+ }
40
+
41
+ @else if $start > length($list) {
42
+ @warn "List index is #{$start} but list is only #{length($list)} item long for `slice`.";
43
+ @return $result;
44
+ }
45
+
46
+ @else if $end > length($list) {
47
+ @warn "List index is #{$end} but list is only #{length($list)} item long for `slice`.";
48
+ @return $result;
49
+ }
50
+
51
+ @else {
52
+ $result: ();
53
+
54
+ @for $i from $start through $end {
55
+ $result: append($result, nth($list, $i));
56
+ }
57
+ }
58
+
59
+ @return $result;
60
60
  }
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Sort numeric values of $list
3
+ * -------------------------------------------------------------------------------
4
+ * @dependence `last()`
5
+ * @dependence `insert-nth()`
6
+ * -------------------------------------------------------------------------------
7
+ * @example sort( (5, 12, 4.7, 6, 69, 6) ) => 4.7, 5, 6, 6, 12, 69
8
+ * @example sort( (5, 12, 4.7, "8", 6, 14px, 69, 6) ) => 4.7, 5, 6, 6, 12, 69
9
+ * @example sort( 1 ) => 1
10
+ * -------------------------------------------------------------------------------
11
+ * @param $list [List] : list
12
+ * -------------------------------------------------------------------------------
13
+ * @return [List]
14
+ */
15
+ @function sort($list) {
16
+ $result : nth($list, 1);
17
+
18
+ @if length($list) > 1 {
19
+ @for $i from 2 through length($list) {
20
+ $item: nth($list, $i);
21
+ @if type-of($item) == number and unitless($item) {
22
+ @if $item > last($result) {
23
+ $result: append($result, $item);
24
+ }
25
+ @else {
26
+ $index: 0;
27
+ @for $i from 1 through length($result) {
28
+ @if $item <= nth($result, $i) {
29
+ $index: $i;
30
+ }
31
+ }
32
+ $result: insert-nth($result, $index, $item);
33
+ }
34
+ }
35
+ @else {
36
+ @warn "Not unitless number found. Omitted.";
37
+ }
38
+ }
39
+ }
40
+
41
+ @return $result;
42
+ }
@@ -1,32 +1,32 @@
1
- /**
2
- * Sum up all unitless values in $list
3
- * -------------------------------------------------------------------------------
4
- * @example sum( (1 2 3 4 5) ) => 15
5
- * @example sum( (1 a 2 b 3) ) => 6
6
- * @example sum( (10px 3em 5%) ) => 0
7
- * @example sum( (10px 3em 5%, true) ) => 18
8
- * -------------------------------------------------------------------------------
9
- * @param $list [List] : list
10
- * @param $force [Boolean] : enable / disable parseInt
11
- * -------------------------------------------------------------------------------
12
- * @return [Number]
13
- */
14
- @function sum($list, $force: false) {
15
- $result: 0;
16
-
17
- @each $item in $list {
18
- @if type-of($item) == number {
19
-
20
- @if $force and unit($item) {
21
- $item: $item / ($item * 0 + 1);
22
- }
23
-
24
- @if unitless($item) {
25
- $result: $result + $item;
26
- }
27
-
28
- }
29
- }
30
-
31
- @return $result;
32
- }
1
+ /**
2
+ * Sum up all unitless values in $list
3
+ * -------------------------------------------------------------------------------
4
+ * @example sum( (1 2 3 4 5) ) => 15
5
+ * @example sum( (1 a 2 b 3) ) => 6
6
+ * @example sum( (10px 3em 5%) ) => 0
7
+ * @example sum( (10px 3em 5%, true) ) => 18
8
+ * -------------------------------------------------------------------------------
9
+ * @param $list [List] : list
10
+ * @param $force [Boolean] : enable / disable parseInt
11
+ * -------------------------------------------------------------------------------
12
+ * @return [Number]
13
+ */
14
+ @function sum($list, $force: false) {
15
+ $result: 0;
16
+
17
+ @each $item in $list {
18
+ @if type-of($item) == number {
19
+
20
+ @if $force and unit($item) {
21
+ $item: $item / ($item * 0 + 1);
22
+ }
23
+
24
+ @if unitless($item) {
25
+ $result: $result + $item;
26
+ }
27
+
28
+ }
29
+ }
30
+
31
+ @return $result;
32
+ }
@@ -1,29 +1,29 @@
1
- /**
2
- * Joins all elements of $list with $glue
3
- * -------------------------------------------------------------------------------
4
- * @example to-string( (a, b, c) ) => abc
5
- * @example to-string( (a, b, c), '-' ) => a-b-c
6
- * @example to-string( (a, b c, d) ) => abcd
7
- * -------------------------------------------------------------------------------
8
- * @param $list [List] : list
9
- * @param $glue [String] : value to use as a join string
10
- * @param $is-nested [Boolean] : strictly internal boolean for recursivity
11
- * -------------------------------------------------------------------------------
12
- * @return [String]
13
- */
14
- @function to-string($list, $glue: '', $is-nested: false) {
15
- $result: null;
16
-
17
- @each $item in $list {
18
- @if length($item) > 1 {
19
- $result: $result#{to-string($item, $glue, true)};
20
- }
21
-
22
- @else {
23
- $condition: index($list, item) != length($list) or $is-nested;
24
- $result: if($condition, $result#{$item}#{$glue}, $result#{$item});
25
- }
26
- }
27
-
28
- @return $result;
1
+ /**
2
+ * Joins all elements of $list with $glue
3
+ * -------------------------------------------------------------------------------
4
+ * @example to-string( (a, b, c) ) => abc
5
+ * @example to-string( (a, b, c), '-' ) => a-b-c
6
+ * @example to-string( (a, b c, d) ) => abcd
7
+ * -------------------------------------------------------------------------------
8
+ * @param $list [List] : list
9
+ * @param $glue [String] : value to use as a join string
10
+ * @param $is-nested [Boolean] : strictly internal boolean for recursivity
11
+ * -------------------------------------------------------------------------------
12
+ * @return [String]
13
+ */
14
+ @function to-string($list, $glue: '', $is-nested: false) {
15
+ $result: null;
16
+
17
+ @each $item in $list {
18
+ @if length($item) > 1 {
19
+ $result: $result#{to-string($item, $glue, true)};
20
+ }
21
+
22
+ @else {
23
+ $condition: index($list, item) != length($list) or $is-nested;
24
+ $result: if($condition, $result#{$item}#{$glue}, $result#{$item});
25
+ }
26
+ }
27
+
28
+ @return $result;
29
29
  }
@@ -1,90 +1,94 @@
1
- /* ------------------------------------------------------------------------------- *
2
- * A couple of advanced Sass list functions
3
- * ------------------------------------------------------------------------------- *
4
- *
5
- * chunk($list, $size)
6
- * Chunk $list into $size large lists
7
- *
8
- * count-values($list)
9
- * Count the number of occurrences of each value of $list
10
- *
11
- * debug($list)
12
- * Returns $list as a string
13
- *
14
- * first($list)
15
- * Return first element of $list
16
- *
17
- * insert-nth($list, $index, $value)
18
- * Add $value at $index in $list
19
- *
20
- * is-symmetrical($list)
21
- * Check if $list is symmetrical
22
- *
23
- * last($list)
24
- * Return last element of $list
25
- *
26
- * last-index($list, $value)
27
- * Return last index of $value in $list
28
- *
29
- * loop($list, $value: 1)
30
- * Shift indexes from $list of $value
31
- *
32
- * prepend($list, $value)
33
- * Add $value as first index of $list
34
- *
35
- * purge($list)
36
- * Remove all false and null values from $list
37
- *
38
- * remove($list, $value, $recursive: false)
39
- * Remove value(s) $value from $list
40
- *
41
- * remove-duplicates($list, $recursive: false)
42
- * Remove duplicate values from $list
43
- *
44
- * remove-nth($list, $index)
45
- * Remove value from $list at index $index
46
- *
47
- * replace($list, $old-value, $new-value, $recursive: false)
48
- * Replace $old-value by $new-value in $list
49
- *
50
- * replace-nth($list, $index, $value)
51
- * Replace value at $index from $list by $value
52
- *
53
- * reverse($list, $recursive: false)
54
- * Reverse the order of $list
55
- *
56
- * slice($list, $start: 1, $end: length($list))
57
- * Slice $list between $start and $end
58
- *
59
- * sum($list, $force: false)
60
- * Sum up all unitless values in $list
61
- *
62
- * to-string($list, $glue: '', $is-nested: false)
63
- * Join all elements of $list with $glue
64
- *
65
- * ------------------------------------------------------------------------------- *
66
- * CodePen (SCSS): http://codepen.io/HugoGiraudel/pen/loAgq
67
- * CodePen (Sass): http://codepen.io/HugoGiraudel/pen/BskrE
68
- * Repository: https://github.com/Team-Sass/Sass-ListFunctions/
69
- * ------------------------------------------------------------------------------- */
70
-
71
- @import "ListFunctions/chunk";
72
- @import "ListFunctions/count-values";
73
- @import "ListFunctions/debug";
74
- @import "ListFunctions/first";
75
- @import "ListFunctions/insert-nth";
76
- @import "ListFunctions/is-symmetrical";
77
- @import "ListFunctions/last";
78
- @import "ListFunctions/last-index";
79
- @import "ListFunctions/loop";
80
- @import "ListFunctions/prepend";
81
- @import "ListFunctions/purge";
82
- @import "ListFunctions/remove";
83
- @import "ListFunctions/remove-duplicates";
84
- @import "ListFunctions/remove-nth";
85
- @import "ListFunctions/replace";
86
- @import "ListFunctions/replace-nth";
87
- @import "ListFunctions/reverse";
88
- @import "ListFunctions/slice";
89
- @import "ListFunctions/sum";
90
- @import "ListFunctions/to-string";
1
+ /* ------------------------------------------------------------------------------- *
2
+ * A couple of advanced Sass list functions
3
+ * ------------------------------------------------------------------------------- *
4
+ *
5
+ * chunk($list, $size)
6
+ * Chunk $list into $size large lists
7
+ *
8
+ * count-values($list)
9
+ * Count the number of occurrences of each value of $list
10
+ *
11
+ * debug($list)
12
+ * Returns $list as a string
13
+ *
14
+ * first($list)
15
+ * Return first element of $list
16
+ *
17
+ * insert-nth($list, $index, $value)
18
+ * Add $value at $index in $list
19
+ *
20
+ * is-symmetrical($list)
21
+ * Check if $list is symmetrical
22
+ *
23
+ * last($list)
24
+ * Return last element of $list
25
+ *
26
+ * last-index($list, $value)
27
+ * Return last index of $value in $list
28
+ *
29
+ * loop($list, $value: 1)
30
+ * Shift indexes from $list of $value
31
+ *
32
+ * prepend($list, $value)
33
+ * Add $value as first index of $list
34
+ *
35
+ * purge($list)
36
+ * Remove all false and null values from $list
37
+ *
38
+ * remove($list, $value, $recursive: false)
39
+ * Remove value(s) $value from $list
40
+ *
41
+ * remove-duplicates($list, $recursive: false)
42
+ * Remove duplicate values from $list
43
+ *
44
+ * remove-nth($list, $index)
45
+ * Remove value from $list at index $index
46
+ *
47
+ * replace($list, $old-value, $new-value, $recursive: false)
48
+ * Replace $old-value by $new-value in $list
49
+ *
50
+ * replace-nth($list, $index, $value)
51
+ * Replace value at $index from $list by $value
52
+ *
53
+ * reverse($list, $recursive: false)
54
+ * Reverse the order of $list
55
+ *
56
+ * slice($list, $start: 1, $end: length($list))
57
+ * Slice $list between $start and $end
58
+ *
59
+ * sort($list)
60
+ * Sort all numeric values in $list
61
+ *
62
+ * sum($list, $force: false)
63
+ * Sum up all unitless values in $list
64
+ *
65
+ * to-string($list, $glue: '', $is-nested: false)
66
+ * Join all elements of $list with $glue
67
+ *
68
+ * ------------------------------------------------------------------------------- *
69
+ * CodePen (SCSS): http://codepen.io/HugoGiraudel/pen/loAgq
70
+ * CodePen (Sass): http://codepen.io/HugoGiraudel/pen/BskrE
71
+ * Repository: https://github.com/Team-Sass/Sass-ListFunctions/
72
+ * ------------------------------------------------------------------------------- */
73
+
74
+ @import "ListFunctions/chunk";
75
+ @import "ListFunctions/count-values";
76
+ @import "ListFunctions/debug";
77
+ @import "ListFunctions/first";
78
+ @import "ListFunctions/insert-nth";
79
+ @import "ListFunctions/is-symmetrical";
80
+ @import "ListFunctions/last";
81
+ @import "ListFunctions/last-index";
82
+ @import "ListFunctions/loop";
83
+ @import "ListFunctions/prepend";
84
+ @import "ListFunctions/purge";
85
+ @import "ListFunctions/remove";
86
+ @import "ListFunctions/remove-duplicates";
87
+ @import "ListFunctions/remove-nth";
88
+ @import "ListFunctions/replace";
89
+ @import "ListFunctions/replace-nth";
90
+ @import "ListFunctions/reverse";
91
+ @import "ListFunctions/slice";
92
+ @import "ListFunctions/sort";
93
+ @import "ListFunctions/sum";
94
+ @import "ListFunctions/to-string";