SassyLists 0.4.9 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +8 -0
- data/lib/SassyLists.rb +2 -2
- data/stylesheets/SassyLists/_chunk.scss +27 -32
- data/stylesheets/SassyLists/_contain.scss +2 -5
- data/stylesheets/SassyLists/_count-values.scss +9 -22
- data/stylesheets/SassyLists/_debug.scss +64 -66
- data/stylesheets/SassyLists/_explode.scss +49 -0
- data/stylesheets/SassyLists/_first.scss +10 -5
- data/stylesheets/SassyLists/_flatten.scss +16 -13
- data/stylesheets/SassyLists/_insert-nth.scss +22 -25
- data/stylesheets/SassyLists/_intersection.scss +12 -13
- data/stylesheets/SassyLists/_is-symmetrical.scss +2 -7
- data/stylesheets/SassyLists/_last-index.scss +7 -9
- data/stylesheets/SassyLists/_last.scss +10 -5
- data/stylesheets/SassyLists/_loop.scss +19 -12
- data/stylesheets/SassyLists/_prepend.scss +7 -8
- data/stylesheets/SassyLists/_purge.scss +8 -9
- data/stylesheets/SassyLists/_random-value.scss +12 -7
- data/stylesheets/SassyLists/_remove-duplicates.scss +8 -17
- data/stylesheets/SassyLists/_remove-nth.scss +2 -12
- data/stylesheets/SassyLists/_remove.scss +4 -9
- data/stylesheets/SassyLists/_replace-nth.scss +7 -29
- data/stylesheets/SassyLists/_replace.scss +14 -23
- data/stylesheets/SassyLists/_reverse.scss +14 -20
- data/stylesheets/SassyLists/_shuffle.scss +14 -10
- data/stylesheets/SassyLists/_slice.scss +25 -33
- data/stylesheets/SassyLists/_sort.scss +25 -39
- data/stylesheets/SassyLists/_sum.scss +12 -17
- data/stylesheets/SassyLists/_to-string.scss +10 -21
- data/stylesheets/SassyLists/_union.scss +3 -2
- data/stylesheets/SassyLists/helpers/_str-compare.scss +27 -0
- data/stylesheets/SassyLists/helpers/_true.scss +15 -0
- data/stylesheets/_SassyLists.scss +3 -0
- metadata +5 -2
@@ -4,27 +4,34 @@
|
|
4
4
|
// -------------------------------------------------------------------------------
|
5
5
|
// @alias `shift-indexes()`
|
6
6
|
// -------------------------------------------------------------------------------
|
7
|
-
// @example loop(a b c d e) => e, a, b, c, d
|
8
|
-
// @example loop(a b c d e, 2) => d, e, a, b, c
|
9
|
-
// @example loop(a b c d e, -2) => c, d, e, a, b
|
10
|
-
// -------------------------------------------------------------------------------
|
11
7
|
// @param $list [List] : list
|
12
8
|
// @param $value [Number] : number of position between old and new indexes
|
13
9
|
// -------------------------------------------------------------------------------
|
14
|
-
// @
|
10
|
+
// @raise [Error] if $value isn't an integer
|
11
|
+
// -------------------------------------------------------------------------------
|
12
|
+
// @return [List] | false
|
15
13
|
|
16
14
|
@function loop($list, $value: 1) {
|
17
|
-
|
18
|
-
$
|
15
|
+
@if type-of($value) != "number" {
|
16
|
+
@warn "#{$value} is not a number for `loop`.";
|
17
|
+
@return false;
|
18
|
+
}
|
19
|
+
|
20
|
+
@if length($list) < 2 {
|
21
|
+
@return $list;
|
22
|
+
}
|
23
|
+
|
24
|
+
$result: ();
|
25
|
+
$length: length($list);
|
19
26
|
|
20
|
-
|
21
|
-
|
22
|
-
|
27
|
+
@for $i from 0 to $length {
|
28
|
+
$result: append($result, nth($list, ($i - $value) % $length + 1), list-separator($list));
|
29
|
+
}
|
23
30
|
|
24
|
-
|
31
|
+
@return $result;
|
25
32
|
}
|
26
33
|
|
27
34
|
// Alias
|
28
35
|
@function shift-indexes($list, $value: 1) {
|
29
|
-
|
36
|
+
@return loop($list, $value);
|
30
37
|
}
|
@@ -2,8 +2,7 @@
|
|
2
2
|
// -------------------------------------------------------------------------------
|
3
3
|
// @documentation http://sassylists.com/documentation/#prepend
|
4
4
|
// -------------------------------------------------------------------------------
|
5
|
-
// @
|
6
|
-
// @example prepend(a b c, y z) => y z, a, b, c
|
5
|
+
// @dependence `is-true()`
|
7
6
|
// -------------------------------------------------------------------------------
|
8
7
|
// @param $list [List] : list
|
9
8
|
// @param $value [Literal] : value to prepend to the list
|
@@ -11,11 +10,11 @@
|
|
11
10
|
// @return [List]
|
12
11
|
|
13
12
|
@function prepend($list, $value) {
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
@if is-true($value) {
|
14
|
+
@return join($value, $list, list-separator($list));
|
15
|
+
}
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
@else {
|
18
|
+
@return $list;
|
19
|
+
}
|
21
20
|
}
|
@@ -4,26 +4,25 @@
|
|
4
4
|
// -------------------------------------------------------------------------------
|
5
5
|
// @alias `clean()`
|
6
6
|
// -------------------------------------------------------------------------------
|
7
|
-
// @
|
8
|
-
// @example purge(a b c '') => a, b, c
|
7
|
+
// @dependence `is-true()`
|
9
8
|
// -------------------------------------------------------------------------------
|
10
9
|
// @param $list [List] : list
|
11
10
|
// -------------------------------------------------------------------------------
|
12
11
|
// @return [List]
|
13
12
|
|
14
13
|
@function purge($list) {
|
15
|
-
|
14
|
+
$result: ();
|
16
15
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
}
|
16
|
+
@each $item in $list {
|
17
|
+
@if is-true($item) {
|
18
|
+
$result: append($result, $item, list-separator($list));
|
21
19
|
}
|
20
|
+
}
|
22
21
|
|
23
|
-
|
22
|
+
@return $result;
|
24
23
|
}
|
25
24
|
|
26
25
|
// Alias
|
27
26
|
@function clean($list) {
|
28
|
-
|
27
|
+
@return purge($list);
|
29
28
|
}
|
@@ -5,23 +5,28 @@
|
|
5
5
|
// @alias `roll()`
|
6
6
|
// @alias `luck()`
|
7
7
|
// -------------------------------------------------------------------------------
|
8
|
-
// @dependence `
|
9
|
-
// -------------------------------------------------------------------------------
|
10
|
-
// @example random-value(a b c d e) => c
|
8
|
+
// @dependence `random()` (Ruby)
|
11
9
|
// -------------------------------------------------------------------------------
|
12
10
|
// @param $list [List] : List
|
13
11
|
// -------------------------------------------------------------------------------
|
14
|
-
// @
|
12
|
+
// @raise [Error] if $list is empty
|
13
|
+
// -------------------------------------------------------------------------------
|
14
|
+
// @return [Literal] | false
|
15
15
|
|
16
16
|
@function random-value($list) {
|
17
|
-
|
17
|
+
@if length($list) == 0 {
|
18
|
+
@warn "Cannot find a random value in an empty list.";
|
19
|
+
@return false;
|
20
|
+
}
|
21
|
+
|
22
|
+
@return nth($list, random(length($list)) + 1);
|
18
23
|
}
|
19
24
|
|
20
25
|
// Aliases
|
21
26
|
@function roll($list) {
|
22
|
-
|
27
|
+
@return random-value($list);
|
23
28
|
}
|
24
29
|
|
25
30
|
@function luck($list) {
|
26
|
-
|
31
|
+
@return random-value($list);
|
27
32
|
}
|
@@ -4,33 +4,24 @@
|
|
4
4
|
// -------------------------------------------------------------------------------
|
5
5
|
// @alias `unique()`
|
6
6
|
// -------------------------------------------------------------------------------
|
7
|
-
// @example remove-duplicates(a b a c b d c e) => a, b, c, d, e
|
8
|
-
// @example remove-duplicates(a b (c c c), true) => a, b, c
|
9
|
-
// -------------------------------------------------------------------------------
|
10
7
|
// @param $list [List] : list
|
11
8
|
// @param $recursive [Boolean] : enable / disable recursivity
|
12
9
|
// -------------------------------------------------------------------------------
|
13
10
|
// @return [List]
|
14
11
|
|
15
|
-
@function remove-duplicates($list
|
16
|
-
|
17
|
-
|
18
|
-
@each $item in $list {
|
19
|
-
@if not index($result, $item) {
|
20
|
-
@if length($item) > 1 and $recursive {
|
21
|
-
$result: append($result, remove-duplicates($item, $recursive));
|
22
|
-
}
|
12
|
+
@function remove-duplicates($list) {
|
13
|
+
$result: ();
|
23
14
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
}
|
15
|
+
@each $item in $list {
|
16
|
+
@if not index($result, $item) {
|
17
|
+
$result: append($result, $item, list-separator($list));
|
28
18
|
}
|
19
|
+
}
|
29
20
|
|
30
|
-
|
21
|
+
@return $result;
|
31
22
|
}
|
32
23
|
|
33
24
|
// Alias
|
34
25
|
@function unique($list, $recursive: false) {
|
35
|
-
|
26
|
+
@return remove-duplicates($list, $recursive);
|
36
27
|
}
|
@@ -6,26 +6,16 @@
|
|
6
6
|
// -------------------------------------------------------------------------------
|
7
7
|
// @dependence `replace-nth()`
|
8
8
|
// -------------------------------------------------------------------------------
|
9
|
-
// @example remove-nth(a b c, 2) => a, c
|
10
|
-
// @example remove-nth(a b c, 0) => error
|
11
|
-
// @example remove-nth(a b c, -1) => a, b
|
12
|
-
// @example remove-nth(a b c, 10) => error
|
13
|
-
// @example remove-nth(a b c, -10) => error
|
14
|
-
// -------------------------------------------------------------------------------
|
15
9
|
// @param $list [List] : list
|
16
10
|
// @param $index [Number] : index to remove
|
17
11
|
// -------------------------------------------------------------------------------
|
18
|
-
// @raise [Error] if $index isn't an integer
|
19
|
-
// @raise [Error] if $index is 0
|
20
|
-
// @raise [Error] if abs value of $index is strictly greater then length of $list
|
21
|
-
// -------------------------------------------------------------------------------
|
22
12
|
// @return [List] | false
|
23
13
|
|
24
14
|
@function remove-nth($list, $index) {
|
25
|
-
|
15
|
+
@return replace-nth($list, $index, "");
|
26
16
|
}
|
27
17
|
|
28
18
|
// Alias
|
29
19
|
@function without-nth($list, $index) {
|
30
|
-
|
20
|
+
@return remove-nth($list, $index);
|
31
21
|
}
|
@@ -6,22 +6,17 @@
|
|
6
6
|
// -------------------------------------------------------------------------------
|
7
7
|
// @dependence `replace()`
|
8
8
|
// -------------------------------------------------------------------------------
|
9
|
-
// @example remove(a b c, b) => a, c
|
10
|
-
// @example remove(a b c, z) => a, b, c
|
11
|
-
// @example remove(a b c b, b) => a, c b
|
12
|
-
// @example remove(a b c b, b, true) => a, c
|
13
|
-
// -------------------------------------------------------------------------------
|
14
9
|
// @param $list [List] : list
|
15
10
|
// @param $value [Literal] : value to remove
|
16
11
|
// @param $recursive [Boolean] : enable / disable recursivity
|
17
12
|
// -------------------------------------------------------------------------------
|
18
13
|
// @return [List]
|
19
14
|
|
20
|
-
@function remove($list, $value
|
21
|
-
|
15
|
+
@function remove($list, $value) {
|
16
|
+
@return replace($list, $value, null);
|
22
17
|
}
|
23
18
|
|
24
19
|
// Alias
|
25
|
-
@function without($list, $value
|
26
|
-
|
20
|
+
@function without($list, $value) {
|
21
|
+
@return remove($list, $value);
|
27
22
|
}
|
@@ -2,11 +2,7 @@
|
|
2
2
|
// -------------------------------------------------------------------------------
|
3
3
|
// @documentation http://sassylists.com/documentation/#replace-nth
|
4
4
|
// -------------------------------------------------------------------------------
|
5
|
-
// @
|
6
|
-
// @example replace-nth(a b c, 0, z) => error
|
7
|
-
// @example replace-nth(a b c, 10, z) => error
|
8
|
-
// @example replace-nth(a b c, -1, z) => a, b, z
|
9
|
-
// @example replace-nth(a b c, -10, z) => error
|
5
|
+
// @dependence `purge()`
|
10
6
|
// -------------------------------------------------------------------------------
|
11
7
|
// @param $list [List] : list
|
12
8
|
// @param $index [Number] : index to update
|
@@ -19,29 +15,11 @@
|
|
19
15
|
// @return [List] | false
|
20
16
|
|
21
17
|
@function replace-nth($list, $index, $value) {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
18
|
+
@if type-of($index) != "number" or $index == 0 or abs($index) > length($list) {
|
19
|
+
@warn "Invalid index (#{$index}) for `replace-nth`.";
|
20
|
+
@return false;
|
21
|
+
}
|
26
22
|
|
27
|
-
|
28
|
-
|
29
|
-
@return false;
|
30
|
-
}
|
31
|
-
|
32
|
-
@if abs($index) > length($list) {
|
33
|
-
@warn "List index is #{$index} but list is only #{length($list)} item long for `replace-nth`/`remove-nth`.";
|
34
|
-
@return false;
|
35
|
-
}
|
36
|
-
|
37
|
-
$result: ();
|
38
|
-
$index: if($index < 0, length($list) + $index + 1, $index);
|
39
|
-
|
40
|
-
@for $i from 1 through length($list) {
|
41
|
-
@if $value and $value != "" and $value != () {
|
42
|
-
$result: append($result, if($i == $index, $value, nth($list, $i)));
|
43
|
-
}
|
44
|
-
}
|
45
|
-
|
46
|
-
@return $result;
|
23
|
+
$list: set-nth($list, $index, $value);
|
24
|
+
@return if(not is-true($value), purge($list), $list);
|
47
25
|
}
|
@@ -1,37 +1,28 @@
|
|
1
|
-
// Replaces $old
|
1
|
+
// Replaces $old by $new in $list
|
2
2
|
// -------------------------------------------------------------------------------
|
3
3
|
// @documentation http://sassylists.com/documentation.html#replace
|
4
4
|
// -------------------------------------------------------------------------------
|
5
|
-
// @example replace( (a, b, c), b, z ) => a, z, c
|
6
|
-
// @example replace( (a, b, c), y, z ) => a, b, c
|
7
|
-
// @example replace( (a, b, c a), a, z ) => z, b, c z
|
8
|
-
// @example replace( (a, b, c a), a, z, true ) => z, b, c z
|
9
|
-
// -------------------------------------------------------------------------------
|
10
5
|
// @param $list [List] : list
|
11
6
|
// @param $old [Literal] : value to replace
|
12
|
-
// @param $value [Literal] : new value for $old
|
13
|
-
// @param $recursive [Boolean] : enable / disable recursivity
|
7
|
+
// @param $value [Literal] : new value for $old
|
14
8
|
// -------------------------------------------------------------------------------
|
15
9
|
// @return [List]
|
16
10
|
|
17
|
-
@function replace($list, $old, $value
|
18
|
-
|
11
|
+
@function replace($list, $old, $value) {
|
12
|
+
$running: true;
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
@if $value and $value != '' and $value != () {
|
23
|
-
$result: append($result, $value);
|
24
|
-
}
|
25
|
-
}
|
14
|
+
@while $running {
|
15
|
+
$index: index($list, $old);
|
26
16
|
|
27
|
-
|
28
|
-
|
29
|
-
|
17
|
+
@if not $index {
|
18
|
+
$running: false;
|
19
|
+
}
|
30
20
|
|
31
|
-
|
32
|
-
|
33
|
-
}
|
21
|
+
@else {
|
22
|
+
$list: set-nth($list, $index, $value);
|
34
23
|
}
|
35
24
|
|
36
|
-
|
25
|
+
}
|
26
|
+
|
27
|
+
@return if(not is-true($value), purge($list), $list);
|
37
28
|
}
|
@@ -4,34 +4,28 @@
|
|
4
4
|
// -------------------------------------------------------------------------------
|
5
5
|
// @alias `mirror()`
|
6
6
|
// -------------------------------------------------------------------------------
|
7
|
-
// @example reverse(a b c) => c, b, a
|
8
|
-
// @example reverse(a b (c a)) => c a, b, a
|
9
|
-
// @example reverse(a b (c a), true) => a c, b, a
|
10
|
-
// -------------------------------------------------------------------------------
|
11
7
|
// @param $list [List] : list
|
12
|
-
// @param $recursive [Boolean] : enable / disable recursivity
|
13
8
|
// -------------------------------------------------------------------------------
|
14
9
|
// @return [List]
|
15
10
|
|
16
|
-
@function reverse($list
|
17
|
-
|
18
|
-
|
19
|
-
@for $i from length($list) * -1 through -1 {
|
20
|
-
$item: nth($list, abs($i));
|
11
|
+
@function reverse($list) {
|
12
|
+
$length: length($list);
|
13
|
+
$end: floor($length/2);
|
21
14
|
|
22
|
-
|
23
|
-
|
24
|
-
|
15
|
+
@if $length < 2 {
|
16
|
+
@return $list;
|
17
|
+
}
|
25
18
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
19
|
+
@for $i from 1 through $end {
|
20
|
+
$tmp: nth($list, $i);
|
21
|
+
$list: set-nth($list, $i, nth($list, -$i));
|
22
|
+
$list: set-nth($list, -$i, $tmp);
|
23
|
+
}
|
30
24
|
|
31
|
-
|
25
|
+
@return $list;
|
32
26
|
}
|
33
27
|
|
34
28
|
// Alias
|
35
|
-
@function mirror($list
|
36
|
-
|
29
|
+
@function mirror($list) {
|
30
|
+
@return reverse($list);
|
37
31
|
}
|
@@ -4,24 +4,28 @@
|
|
4
4
|
// -------------------------------------------------------------------------------
|
5
5
|
// @alias `randomize()`
|
6
6
|
// -------------------------------------------------------------------------------
|
7
|
-
// @example shuffle(a b c d e) => b d c e a
|
8
|
-
// -------------------------------------------------------------------------------
|
9
7
|
// @param $list [List] : list
|
10
8
|
// -------------------------------------------------------------------------------
|
11
9
|
// @return [List]
|
12
10
|
|
13
11
|
@function shuffle($list) {
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
$tmp: nth($list, $i);
|
18
|
-
$list: set-nth($list, $i, nth($list, $j));
|
19
|
-
$list: set-nth($list, $j, $tmp);
|
20
|
-
}
|
12
|
+
$length: length($list);
|
13
|
+
|
14
|
+
@if $length < 2 {
|
21
15
|
@return $list;
|
16
|
+
}
|
17
|
+
|
18
|
+
@for $i from -1 * $length through -1 {
|
19
|
+
$i: abs($i);
|
20
|
+
$j: random($length - 1) + 1;
|
21
|
+
$tmp: nth($list, $i);
|
22
|
+
$list: set-nth($list, $i, nth($list, $j));
|
23
|
+
$list: set-nth($list, $j, $tmp);
|
24
|
+
}
|
25
|
+
@return $list;
|
22
26
|
}
|
23
27
|
|
24
28
|
// Alias
|
25
29
|
@function randomize($list) {
|
26
|
-
|
30
|
+
@return shuffle($list);
|
27
31
|
}
|
@@ -2,13 +2,6 @@
|
|
2
2
|
// -------------------------------------------------------------------------------
|
3
3
|
// @documentation http://sassylists.com/documentation/#slice
|
4
4
|
// -------------------------------------------------------------------------------
|
5
|
-
// @example slice(a b c d, 2, 3) => b, c
|
6
|
-
// @example slice(a b c d, 3, 2) => error
|
7
|
-
// @example slice(a b c d, 3, 5) => error
|
8
|
-
// @example slice(a b c d, -1, 3) => error
|
9
|
-
// @example slice(a b c d, 0, 3) => error
|
10
|
-
// @example slice(a b c d, 3, 3) => c
|
11
|
-
// -------------------------------------------------------------------------------
|
12
5
|
// @param $list [List] : list
|
13
6
|
// @param $start [Number] : start index
|
14
7
|
// @param $end [Number] : end index
|
@@ -22,36 +15,35 @@
|
|
22
15
|
// @return [List] | false
|
23
16
|
|
24
17
|
@function slice($list, $start: 1, $end: length($list)) {
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
+
}
|
29
22
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
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
|
+
}
|
34
27
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
28
|
+
@if $start < 1 or $end < 1 {
|
29
|
+
@warn "List indexes must be non-zero integers for `slice`.";
|
30
|
+
@return false;
|
31
|
+
}
|
39
32
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
+
}
|
44
37
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
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
|
+
}
|
49
42
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
}
|
43
|
+
$result: ();
|
44
|
+
@for $i from $start through $end {
|
45
|
+
$result: append($result, nth($list, $i), list-separator($list));
|
46
|
+
}
|
55
47
|
|
56
|
-
|
48
|
+
@return $result;
|
57
49
|
}
|
@@ -1,55 +1,41 @@
|
|
1
|
-
// Sorts
|
1
|
+
// Sorts values of $list using quick-sort algorithm
|
2
2
|
// -------------------------------------------------------------------------------
|
3
3
|
// @documentation http://sassylists.com/documentation/#sort
|
4
4
|
// -------------------------------------------------------------------------------
|
5
5
|
// @alias `order()`
|
6
6
|
// -------------------------------------------------------------------------------
|
7
|
-
// @
|
8
|
-
// @example sort(5 12 4.7 "8" 6 14px 69 6) => 4.7, 5, 6, 6, 12, 69
|
7
|
+
// @dependence `str-compare()`
|
9
8
|
// -------------------------------------------------------------------------------
|
10
9
|
// @param $list [List] : list
|
11
|
-
// @param $
|
12
|
-
// -------------------------------------------------------------------------------
|
13
|
-
// @raise [Warning] if not-number found
|
10
|
+
// @param $order [List] : order
|
14
11
|
// -------------------------------------------------------------------------------
|
15
12
|
// @return [List]
|
16
13
|
|
17
|
-
@function sort($list) {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
@else {
|
37
|
-
$large: append($large, $item);
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
@else {
|
42
|
-
@warn "Not integer value found. Omitted.";
|
43
|
-
}
|
44
|
-
}
|
45
|
-
|
46
|
-
@return join(join(sort($less), $equal), sort($large));
|
14
|
+
@function sort($list, $order: "!" "#" "$" "%" "&" "'" "(" ")" "*" "+" "," "-" "." "/" "[" "\\" "]" "^" "_" "{" "|" "}" "~" "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v" "w" "x" "y" "z") {
|
15
|
+
$less: ();
|
16
|
+
$equal: ();
|
17
|
+
$large: ();
|
18
|
+
$length: length($list);
|
19
|
+
|
20
|
+
@if $length > 1 {
|
21
|
+
$seed: nth($list, ceil($length / 2));
|
22
|
+
@each $item in $list {
|
23
|
+
@if $item == $seed {
|
24
|
+
$equal: append($equal, $item, list-separator($list));
|
25
|
+
}
|
26
|
+
@else if str-compare($item, $seed, $order) {
|
27
|
+
$less: append($less, $item, list-separator($list));
|
28
|
+
}
|
29
|
+
@else if not str-compare($item, $seed, $order) {
|
30
|
+
$large: append($large, $item, list-separator($list));
|
31
|
+
}
|
47
32
|
}
|
48
|
-
|
49
|
-
|
33
|
+
@return join(join(sort($less, $order), $equal), sort($large, $order));
|
34
|
+
}
|
35
|
+
@return $list;
|
50
36
|
}
|
51
37
|
|
52
38
|
// Alias
|
53
39
|
@function order($list) {
|
54
|
-
|
40
|
+
@return sort($list);
|
55
41
|
}
|
@@ -1,33 +1,28 @@
|
|
1
|
-
// Sums up all
|
1
|
+
// Sums up all numeric values in $list
|
2
2
|
// -------------------------------------------------------------------------------
|
3
3
|
// @documentation http://sassylists.com/documentation/#sum
|
4
4
|
// -------------------------------------------------------------------------------
|
5
|
-
// @example sum(1 2 3 4 5) => 15
|
6
|
-
// @example sum(1 a 2 b 3) => 6
|
7
|
-
// @example sum(10px 3em 5%) => 0
|
8
|
-
// @example sum(10px 3em 5%, true) => 18
|
9
|
-
// -------------------------------------------------------------------------------
|
10
5
|
// @param $list [List] : list
|
11
6
|
// @param $force [Boolean] : enable / disable parseInt
|
12
7
|
// -------------------------------------------------------------------------------
|
13
8
|
// @return [Number]
|
14
9
|
|
15
10
|
@function sum($list, $force: false) {
|
16
|
-
|
11
|
+
$result: 0;
|
17
12
|
|
18
|
-
|
19
|
-
|
13
|
+
@each $item in $list {
|
14
|
+
@if type-of($item) == number {
|
20
15
|
|
21
|
-
|
22
|
-
|
23
|
-
|
16
|
+
@if $force and not unitless($item) {
|
17
|
+
$item: $item / ($item * 0 + 1);
|
18
|
+
}
|
24
19
|
|
25
|
-
|
26
|
-
|
27
|
-
|
20
|
+
@if unitless($item) {
|
21
|
+
$result: $result + $item;
|
22
|
+
}
|
28
23
|
|
29
|
-
}
|
30
24
|
}
|
25
|
+
}
|
31
26
|
|
32
|
-
|
27
|
+
@return $result;
|
33
28
|
}
|