ListFunctions 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +7 -0
  2. data/lib/ListFunctions.rb +30 -0
  3. data/stylesheets/ListFunctions/_chunk.scss +32 -0
  4. data/stylesheets/ListFunctions/_count-values.scss +33 -0
  5. data/stylesheets/ListFunctions/_debug.scss +34 -0
  6. data/stylesheets/ListFunctions/_first.scss +13 -0
  7. data/stylesheets/ListFunctions/_insert-nth.scss +52 -0
  8. data/stylesheets/ListFunctions/_is-symmetrical.scss +23 -0
  9. data/stylesheets/ListFunctions/_last-index.scss +24 -0
  10. data/stylesheets/ListFunctions/_last.scss +13 -0
  11. data/stylesheets/ListFunctions/_loop.scss +21 -0
  12. data/stylesheets/ListFunctions/_prepend.scss +16 -0
  13. data/stylesheets/ListFunctions/_purge.scss +21 -0
  14. data/stylesheets/ListFunctions/_remove-duplicates.scss +30 -0
  15. data/stylesheets/ListFunctions/_remove-nth.scss +23 -0
  16. data/stylesheets/ListFunctions/_remove.scss +19 -0
  17. data/stylesheets/ListFunctions/_replace-nth.scss +50 -0
  18. data/stylesheets/ListFunctions/_replace.scss +32 -0
  19. data/stylesheets/ListFunctions/_reverse.scss +30 -0
  20. data/stylesheets/ListFunctions/_slice.scss +60 -0
  21. data/stylesheets/ListFunctions/_sum.scss +32 -0
  22. data/stylesheets/ListFunctions/_to-string.scss +29 -0
  23. data/stylesheets/_ListFunctions.scss +90 -0
  24. data/templates/project/css/ListFunctions.css +351 -0
  25. data/templates/project/sass/ListFunctions/_chunk.scss +32 -0
  26. data/templates/project/sass/ListFunctions/_count-values.scss +33 -0
  27. data/templates/project/sass/ListFunctions/_debug.scss +34 -0
  28. data/templates/project/sass/ListFunctions/_first.scss +13 -0
  29. data/templates/project/sass/ListFunctions/_insert-nth.scss +52 -0
  30. data/templates/project/sass/ListFunctions/_is-symmetrical.scss +23 -0
  31. data/templates/project/sass/ListFunctions/_last-index.scss +24 -0
  32. data/templates/project/sass/ListFunctions/_last.scss +13 -0
  33. data/templates/project/sass/ListFunctions/_loop.scss +21 -0
  34. data/templates/project/sass/ListFunctions/_prepend.scss +16 -0
  35. data/templates/project/sass/ListFunctions/_purge.scss +21 -0
  36. data/templates/project/sass/ListFunctions/_remove-duplicates.scss +30 -0
  37. data/templates/project/sass/ListFunctions/_remove-nth.scss +23 -0
  38. data/templates/project/sass/ListFunctions/_remove.scss +19 -0
  39. data/templates/project/sass/ListFunctions/_replace-nth.scss +50 -0
  40. data/templates/project/sass/ListFunctions/_replace.scss +32 -0
  41. data/templates/project/sass/ListFunctions/_reverse.scss +30 -0
  42. data/templates/project/sass/ListFunctions/_slice.scss +60 -0
  43. data/templates/project/sass/ListFunctions/_sum.scss +32 -0
  44. data/templates/project/sass/ListFunctions/_to-string.scss +29 -0
  45. data/templates/project/sass/_ListFunctions.scss +90 -0
  46. metadata +115 -0
@@ -0,0 +1,90 @@
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";
@@ -0,0 +1,351 @@
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
+ * Chunk $list into $size large lists
72
+ * -------------------------------------------------------------------------------
73
+ * @example chunk( (a, b, c, d, e), 2 ) => a b, c d, e
74
+ * @example chunk( (a, b, c, d, e), 3 ) => a b c, d e
75
+ * @example chunk( a, 3 ) => a
76
+ * -------------------------------------------------------------------------------
77
+ * @param $list [List] : list
78
+ * @param $size [Number] : length of lists
79
+ * -------------------------------------------------------------------------------
80
+ * @return [List]
81
+ */
82
+ /**
83
+ * Count the number of occurrences of each value of $list
84
+ * -------------------------------------------------------------------------------
85
+ * @dependence `replace-nth()`
86
+ * -------------------------------------------------------------------------------
87
+ * @example count-values( (a, b, c, d, e) ) => a 1, b 1, c 1, d 1, e 1
88
+ * @example count-values( (a, b, c, a, d, b, a, e) ) => a 3, b 2, c 1, d 1, e 1
89
+ * @example count-values( a ) => a 1
90
+ * -------------------------------------------------------------------------------
91
+ * @param $list [List] : list
92
+ * -------------------------------------------------------------------------------
93
+ * @return [List]
94
+ */
95
+ /**
96
+ * Returns $list as a string
97
+ * -------------------------------------------------------------------------------
98
+ * @example debug( (a, b, c, d, e) ) => [ a, b, c, d, e ]
99
+ * @example debug( (a b (c d e) ) ) => [ a, b, [ c, d, e ] ]
100
+ * @example debug( a ) => [ a ]
101
+ * -------------------------------------------------------------------------------
102
+ * @param $list [List] : list
103
+ * -------------------------------------------------------------------------------
104
+ * @return [String]
105
+ */
106
+ /**
107
+ * Returns first element of $list
108
+ * -------------------------------------------------------------------------------
109
+ * @example first( (a, b, c) ) => a
110
+ * @example first( a ) => a
111
+ * -------------------------------------------------------------------------------
112
+ * @param $list [List] : list
113
+ * -------------------------------------------------------------------------------
114
+ * @return [Literal]
115
+ */
116
+ /**
117
+ * Add $value at $index in $list
118
+ * -------------------------------------------------------------------------------
119
+ * @dependence `purge()`
120
+ * -------------------------------------------------------------------------------
121
+ * @example insert-nth( (a, b, c), 2, z ) => a, z, b, c
122
+ * @example insert-nth( (a, b, c), 0, z ) => error
123
+ * @example insert-nth( (a, b, c), -1, z ) => error
124
+ * @example insert-nth( (a, b, c), 10, z ) => error
125
+ * -------------------------------------------------------------------------------
126
+ * @param $list [List] : list
127
+ * @param $index [Number] : index to add
128
+ * @param $value [Literal] : value to add
129
+ * -------------------------------------------------------------------------------
130
+ * @raise [Error] if $index isn't an integer
131
+ * @raise [Error] if $index is strictly lesser than 1
132
+ * @raise [Error] if $index is strictly greater than length of $list
133
+ * -------------------------------------------------------------------------------
134
+ * @return [List] | false
135
+ */
136
+ /**
137
+ * Test if $list is symmetrical (one-level deep)
138
+ * -------------------------------------------------------------------------------
139
+ * @dependence `reverse()`
140
+ * -------------------------------------------------------------------------------
141
+ * @example is-symmetrical( (a, b, c, d, e) ) => false
142
+ * @example is-symmetrical( (a, b, c, b, a) ) => true
143
+ * @example is-symmetrical( a ) => true
144
+ * @example is-symmetrical( a, b c d, a ) => true
145
+ * -------------------------------------------------------------------------------
146
+ * @param $list [List] : list
147
+ * -------------------------------------------------------------------------------
148
+ * @return [Boolean]
149
+ */
150
+ /**
151
+ * Returns last element of $list
152
+ * -------------------------------------------------------------------------------
153
+ * @example last( (a, b, c) ) => c
154
+ * @example last( a ) => a
155
+ * -------------------------------------------------------------------------------
156
+ * @param $list [List] : list
157
+ * -------------------------------------------------------------------------------
158
+ * @return [Literal]
159
+ */
160
+ /**
161
+ * Returns last index of $value in $list
162
+ * -------------------------------------------------------------------------------
163
+ * @example last-index( (a, b, c, a), a ) => 4
164
+ * @example last-index( (a, b, c), z ) => null
165
+ * -------------------------------------------------------------------------------
166
+ * @param $list [List] : list
167
+ * @param $value [Literal] : value to be searched for
168
+ * -------------------------------------------------------------------------------
169
+ * @return [Number] | null
170
+ */
171
+ /**
172
+ * Shift indexes from $list of $value
173
+ * -------------------------------------------------------------------------------
174
+ * @example loop( (a, b, c, d, e) ) => e, a, b, c, d
175
+ * @example loop( (a, b, c, d, e), 2 ) => d, e, a, b, c
176
+ * @example loop( (a, b, c, d, e), -2 ) => c, d, e, a, b
177
+ * -------------------------------------------------------------------------------
178
+ * @param $list [List] : list
179
+ * @param $value [Number] : number of position between old and new indexes
180
+ * -------------------------------------------------------------------------------
181
+ * @return [List]
182
+ */
183
+ /**
184
+ * Add $value as first index of $list
185
+ * -------------------------------------------------------------------------------
186
+ * @dependence `purge()`
187
+ * -------------------------------------------------------------------------------
188
+ * @example prepend( (a, b, c), z ) => z, a, b, c
189
+ * @example prepend( (a, b, c), y z ) => y z, a, b, c
190
+ * -------------------------------------------------------------------------------
191
+ * @param $list [List] : list
192
+ * @param $value [Literal] : value to prepend to the list
193
+ * -------------------------------------------------------------------------------
194
+ * @return [List]
195
+ */
196
+ /**
197
+ * Remove all false and null values from $list
198
+ * -------------------------------------------------------------------------------
199
+ * @example purge( (a, null, b, false, c, null) ) => a, b, c
200
+ * @example purge( (a, b, c) ) => a, b, c
201
+ * -------------------------------------------------------------------------------
202
+ * @param $list [List] : list
203
+ * -------------------------------------------------------------------------------
204
+ * @return [List]
205
+ */
206
+ /**
207
+ * Remove value(s) $value from $list
208
+ * -------------------------------------------------------------------------------
209
+ * @dependence `replace()`
210
+ * -------------------------------------------------------------------------------
211
+ * @example remove( (a, b, c), b ) => a, c
212
+ * @example remove( (a, b, c), z ) => a, b, c
213
+ * @example remove( (a, b, c b), b ) => a, c b
214
+ * @example remove( (a, b, c b), b, true ) => a, c
215
+ * -------------------------------------------------------------------------------
216
+ * @param $list [List] : list
217
+ * @param $value [Literal] : value to remove
218
+ * @param $recursive [Boolean] : enable / disable recursivity
219
+ * -------------------------------------------------------------------------------
220
+ * @return [List]
221
+ */
222
+ /**
223
+ * Remove duplicate values from $list
224
+ * -------------------------------------------------------------------------------
225
+ * @example remove-duplicates( (a, b, a, c, b, d, c, e) ) => a, b, c, d, e
226
+ * @example remove-duplicates( (a, b, (c, c, c)) ) => a, b, c
227
+ * -------------------------------------------------------------------------------
228
+ * @param $list [List] : list
229
+ * @param $recursive [Boolean] : enable / disable recursivity
230
+ * -------------------------------------------------------------------------------
231
+ * @return [List]
232
+ */
233
+ /**
234
+ * Remove value from $list at index $index
235
+ * -------------------------------------------------------------------------------
236
+ * @dependence `replace-nth()`
237
+ * -------------------------------------------------------------------------------
238
+ * @example remove-nth( (a, b, c), 2 ) => a, c
239
+ * @example remove-nth( (a, b, c), 0 ) => error
240
+ * @example remove-nth( (a, b, c), -1 ) => a, b
241
+ * @example remove-nth( (a, b, c), 10 ) => error
242
+ * @example remove-nth( (a, b, c), -10 ) => error
243
+ * -------------------------------------------------------------------------------
244
+ * @param $list [List] : list
245
+ * @param $index [Number] : index to remove
246
+ * -------------------------------------------------------------------------------
247
+ * @raise [Error] if $index isn't an integer
248
+ * @raise [Error] if $index is 0
249
+ * @raise [Error] if abs value of $index is strictly greater then length of $list
250
+ * -------------------------------------------------------------------------------
251
+ * @return [List] | false
252
+ */
253
+ /**
254
+ * Replace $old-value by $new-value in $list
255
+ * -------------------------------------------------------------------------------
256
+ * @dependence `purge()`
257
+ * -------------------------------------------------------------------------------
258
+ * @example replace( (a, b, c), b, z ) => a, z, c
259
+ * @example replace( (a, b, c), y, z ) => a, b, c
260
+ * @example replace( (a, b, c a), a, z ) => z, b, c z
261
+ * @example replace( (a, b, c a), a, z, true ) => z, b, c z
262
+ * -------------------------------------------------------------------------------
263
+ * @param $list [List] : list
264
+ * @param $old-value [Literal] : value to replace
265
+ * @param $new-value [Literal] : new value for $old-value
266
+ * @param $recursive [Boolean] : enable / disable recursivity
267
+ * -------------------------------------------------------------------------------
268
+ * @return [List]
269
+ */
270
+ /**
271
+ * Replace value at $index from $list by $value
272
+ * -------------------------------------------------------------------------------
273
+ * @dependence `purge()`
274
+ * -------------------------------------------------------------------------------
275
+ * @example replace-nth( (a, b, c), 2, z ) => a, z, c
276
+ * @example replace-nth( (a, b, c), 0, z ) => error
277
+ * @example replace-nth( (a, b, c), -1, z ) => a, b, z
278
+ * @example replace-nth( (a, b, c), 10, z ) => error
279
+ * @example replace-nth( (a, b, c), -10, z ) => error
280
+ * -------------------------------------------------------------------------------
281
+ * @param $list [List] : list
282
+ * @param $index [Number] : index to update
283
+ * @param $value [Literal] : new value for index $index
284
+ * -------------------------------------------------------------------------------
285
+ * @raise [Error] if $index isn't an integer
286
+ * @raise [Error] if $index is 0
287
+ * @raise [Error] if abs value of $index is strictly greater than length of $list
288
+ * -------------------------------------------------------------------------------
289
+ * @return [List] | false
290
+ */
291
+ /**
292
+ * Reverses the order of $list
293
+ * -------------------------------------------------------------------------------
294
+ * @example reverse( (a, b, c) ) => c, b, a
295
+ * @example reverse( (a, b, c a) ) => c a, b, a
296
+ * @example reverse( (a, b, c a), true ) => a c, b, a
297
+ * @example reverse( a ) => a
298
+ * -------------------------------------------------------------------------------
299
+ * @param $list [List] : list
300
+ * @param $recursive [Boolean] : enable / disable recursivity
301
+ * -------------------------------------------------------------------------------
302
+ * @return [List]
303
+ */
304
+ /**
305
+ * Slices $list between $start and $end
306
+ * -------------------------------------------------------------------------------
307
+ * @example slice( (a, b, c, d), 2, 3 ) => b, c
308
+ * @example slice( (a, b, c, d), 3, 2 ) => error
309
+ * @example slice( (a, b, c, d), 3, 5 ) => error
310
+ * @example slice( (a, b, c, d), -1, 3 ) => error
311
+ * @example slice( (a, b, c, d), 0, 3 ) => error
312
+ * @example slice( (a, b, c, d), 3, 3 ) => c
313
+ * -------------------------------------------------------------------------------
314
+ * @param $list [List] : list
315
+ * @param $start [Number] : start index
316
+ * @param $end [Number] : end index
317
+ * -------------------------------------------------------------------------------
318
+ * @raise [Error] if $start or $end aren't integers
319
+ * @raise [Error] if $start is greater than $end
320
+ * @raise [Error] if $start or $end is strictly lesser than 1
321
+ * @raise [Error] if $start is strictly greater than length of $list
322
+ * @raise [Error] if $end is strictly greater than length of $list
323
+ * -------------------------------------------------------------------------------
324
+ * @return [List] | false
325
+ */
326
+ /**
327
+ * Sum up all unitless values in $list
328
+ * -------------------------------------------------------------------------------
329
+ * @example sum( (1 2 3 4 5) ) => 15
330
+ * @example sum( (1 a 2 b 3) ) => 6
331
+ * @example sum( (10px 3em 5%) ) => 0
332
+ * @example sum( (10px 3em 5%, true) ) => 18
333
+ * -------------------------------------------------------------------------------
334
+ * @param $list [List] : list
335
+ * @param $force [Boolean] : enable / disable parseInt
336
+ * -------------------------------------------------------------------------------
337
+ * @return [Number]
338
+ */
339
+ /**
340
+ * Joins all elements of $list with $glue
341
+ * -------------------------------------------------------------------------------
342
+ * @example to-string( (a, b, c) ) => abc
343
+ * @example to-string( (a, b, c), '-' ) => a-b-c
344
+ * @example to-string( (a, b c, d) ) => abcd
345
+ * -------------------------------------------------------------------------------
346
+ * @param $list [List] : list
347
+ * @param $glue [String] : value to use as a join string
348
+ * @param $is-nested [Boolean] : strictly internal boolean for recursivity
349
+ * -------------------------------------------------------------------------------
350
+ * @return [String]
351
+ */
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Chunk $list into $size large lists
3
+ * -------------------------------------------------------------------------------
4
+ * @example chunk( (a, b, c, d, e), 2 ) => a b, c d, e
5
+ * @example chunk( (a, b, c, d, e), 3 ) => a b c, d e
6
+ * @example chunk( a, 3 ) => a
7
+ * -------------------------------------------------------------------------------
8
+ * @param $list [List] : list
9
+ * @param $size [Number] : length of lists
10
+ * -------------------------------------------------------------------------------
11
+ * @return [List]
12
+ */
13
+ @function chunk($list, $size) {
14
+ $n: ceil(length($list) / $size);
15
+ $temp-index: 0;
16
+ $result: ();
17
+
18
+ @for $i from 1 through $n {
19
+ $temp-list: ();
20
+
21
+ @for $j from 1 + $temp-index through $size + $temp-index {
22
+ @if $j <= length($list) {
23
+ $temp-list: append($temp-list, nth($list, $j));
24
+ }
25
+ }
26
+
27
+ $result: append($result, $temp-list);
28
+ $temp-index: $temp-index + $size;
29
+ }
30
+
31
+ @return $result;
32
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Count the number of occurrences of each value of $list
3
+ * -------------------------------------------------------------------------------
4
+ * @dependence `replace-nth()`
5
+ * -------------------------------------------------------------------------------
6
+ * @example count-values( (a, b, c, d, e) ) => a 1, b 1, c 1, d 1, e 1
7
+ * @example count-values( (a, b, c, a, d, b, a, e) ) => a 3, b 2, c 1, d 1, e 1
8
+ * @example count-values( a ) => a 1
9
+ * -------------------------------------------------------------------------------
10
+ * @param $list [List] : list
11
+ * -------------------------------------------------------------------------------
12
+ * @return [List]
13
+ */
14
+ @function count-values($list) {
15
+ $keys : ();
16
+ $counts : ();
17
+
18
+ @each $item in $list {
19
+ $index: index($keys, $item);
20
+
21
+ @if not $index {
22
+ $keys : append($keys, $item);
23
+ $counts : append($counts, 1);
24
+ }
25
+
26
+ @else {
27
+ $count : nth($counts, $index) + 1;
28
+ $counts : replace-nth($counts, $index, $count);
29
+ }
30
+ }
31
+
32
+ @return zip($keys, $counts);
33
+ }
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Returns $list as a string
3
+ * -------------------------------------------------------------------------------
4
+ * @example debug( (a, b, c, d, e) ) => [ a, b, c, d, e ]
5
+ * @example debug( (a b (c d e) ) ) => [ a, b, [ c, d, e ] ]
6
+ * @example debug( a ) => [ a ]
7
+ * -------------------------------------------------------------------------------
8
+ * @param $list [List] : list
9
+ * -------------------------------------------------------------------------------
10
+ * @return [String]
11
+ */
12
+ @function debug($list) {
13
+ $result: #{"[ "};
14
+
15
+ @each $item in $list {
16
+
17
+ @if length($item) > 1 {
18
+ $result: $result#{debug($item)};
19
+ }
20
+
21
+ @else {
22
+ $result: $result#{$item};
23
+ }
24
+
25
+ @if index($list, $item) != length($list) {
26
+ $result: $result#{", "};
27
+ }
28
+
29
+ }
30
+
31
+ $result: $result#{" ]"};
32
+
33
+ @return $result;
34
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Returns first element of $list
3
+ * -------------------------------------------------------------------------------
4
+ * @example first( (a, b, c) ) => a
5
+ * @example first( a ) => a
6
+ * -------------------------------------------------------------------------------
7
+ * @param $list [List] : list
8
+ * -------------------------------------------------------------------------------
9
+ * @return [Literal]
10
+ */
11
+ @function first($list) {
12
+ @return nth($list, 1);
13
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Add $value at $index in $list
3
+ * -------------------------------------------------------------------------------
4
+ * @dependence `purge()`
5
+ * -------------------------------------------------------------------------------
6
+ * @example insert-nth( (a, b, c), 2, z ) => a, z, b, c
7
+ * @example insert-nth( (a, b, c), 0, z ) => error
8
+ * @example insert-nth( (a, b, c), -1, z ) => error
9
+ * @example insert-nth( (a, b, c), 10, z ) => error
10
+ * -------------------------------------------------------------------------------
11
+ * @param $list [List] : list
12
+ * @param $index [Number] : index to add
13
+ * @param $value [Literal] : value to add
14
+ * -------------------------------------------------------------------------------
15
+ * @raise [Error] if $index isn't an integer
16
+ * @raise [Error] if $index is strictly lesser than 1
17
+ * @raise [Error] if $index is strictly greater than length of $list
18
+ * -------------------------------------------------------------------------------
19
+ * @return [List] | false
20
+ */
21
+ @function insert-nth($list, $index, $value) {
22
+ $result: false;
23
+
24
+ @if type-of($index) != number {
25
+ @warn "$index: #{quote($index)} is not a number for `insert-nth`.";
26
+ @return $result;
27
+ }
28
+
29
+ @else if $index < 1 {
30
+ @warn "List index 0 must be a non-zero integer for `insert-nth`";
31
+ @return $result;
32
+ }
33
+
34
+ @else if $index > length($list) {
35
+ @warn "List index is #{$index} but list is only #{length($list)} item long for `insert-nth'.";
36
+ @return $result;
37
+ }
38
+
39
+ @else {
40
+ $result: ();
41
+
42
+ @for $i from 1 through length($list) {
43
+ @if $i == $index {
44
+ $result: append($result, $value);
45
+ }
46
+
47
+ $result: append($result, nth($list, $i));
48
+ }
49
+ }
50
+
51
+ @return purge($result);
52
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Test if $list is symmetrical (one-level deep)
3
+ * -------------------------------------------------------------------------------
4
+ * @dependence `reverse()`
5
+ * -------------------------------------------------------------------------------
6
+ * @example is-symmetrical( (a, b, c, d, e) ) => false
7
+ * @example is-symmetrical( (a, b, c, b, a) ) => true
8
+ * @example is-symmetrical( a ) => true
9
+ * @example is-symmetrical( a, b c d, a ) => true
10
+ * -------------------------------------------------------------------------------
11
+ * @param $list [List] : list
12
+ * -------------------------------------------------------------------------------
13
+ * @return [Boolean]
14
+ */
15
+ @function is-symmetrical($list) {
16
+ $result: ();
17
+
18
+ @each $item in $list {
19
+ $result: append($result, $item, space);
20
+ }
21
+
22
+ @return $result == reverse($result);
23
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Returns last index of $value in $list
3
+ * -------------------------------------------------------------------------------
4
+ * @example last-index( (a, b, c, a), a ) => 4
5
+ * @example last-index( (a, b, c), z ) => null
6
+ * -------------------------------------------------------------------------------
7
+ * @param $list [List] : list
8
+ * @param $value [Literal] : value to be searched for
9
+ * -------------------------------------------------------------------------------
10
+ * @return [Number] | null
11
+ */
12
+ @function last-index($list, $value) {
13
+
14
+ @for $i from length($list) * -1 through -1 {
15
+ $i: abs($i);
16
+
17
+ @if nth($list, $i) == $value {
18
+ @return $i;
19
+ }
20
+
21
+ }
22
+
23
+ @return null;
24
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Returns last element of $list
3
+ * -------------------------------------------------------------------------------
4
+ * @example last( (a, b, c) ) => c
5
+ * @example last( a ) => a
6
+ * -------------------------------------------------------------------------------
7
+ * @param $list [List] : list
8
+ * -------------------------------------------------------------------------------
9
+ * @return [Literal]
10
+ */
11
+ @function last($list) {
12
+ @return nth($list, length($list));
13
+ }