sass-aleksi 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +44 -0
- data/lib/sass-aleksi.rb +31 -0
- data/stylesheets/_aleksi.scss +23 -0
- data/stylesheets/aleksi/_colors.scss +0 -0
- data/stylesheets/aleksi/_config.scss +11 -0
- data/stylesheets/aleksi/_general.scss +11 -0
- data/stylesheets/aleksi/_lengths.scss +8 -0
- data/stylesheets/aleksi/_lists.scss +16 -0
- data/stylesheets/aleksi/_maps.scss +21 -0
- data/stylesheets/aleksi/_math.scss +10 -0
- data/stylesheets/aleksi/_sides.scss +11 -0
- data/stylesheets/aleksi/config/_constants.scss +73 -0
- data/stylesheets/aleksi/general/_apply.scss +42 -0
- data/stylesheets/aleksi/general/_css-rule.scss +88 -0
- data/stylesheets/aleksi/general/_default-to.scss +35 -0
- data/stylesheets/aleksi/general/_is-of-type.scss +72 -0
- data/stylesheets/aleksi/general/_throw.scss +125 -0
- data/stylesheets/aleksi/lengths/_convert.scss +100 -0
- data/stylesheets/aleksi/lengths/_strip-unit.scss +37 -0
- data/stylesheets/aleksi/lists/_contained-in.scss +34 -0
- data/stylesheets/aleksi/lists/_depth.scss +46 -0
- data/stylesheets/aleksi/lists/_get-nth.scss +44 -0
- data/stylesheets/aleksi/lists/_is-list.scss +35 -0
- data/stylesheets/aleksi/lists/_list-filter.scss +48 -0
- data/stylesheets/aleksi/lists/_next.scss +47 -0
- data/stylesheets/aleksi/lists/_prepend.scss +40 -0
- data/stylesheets/aleksi/lists/_previous.scss +47 -0
- data/stylesheets/aleksi/lists/_set-list-separator.scss +173 -0
- data/stylesheets/aleksi/lists/_walk.scss +96 -0
- data/stylesheets/aleksi/lists/_wrap-in-list.scss +42 -0
- data/stylesheets/aleksi/maps/_debug-map.scss +39 -0
- data/stylesheets/aleksi/maps/_is-map.scss +31 -0
- data/stylesheets/aleksi/maps/_map-clean.scss +45 -0
- data/stylesheets/aleksi/maps/_map-depth.scss +46 -0
- data/stylesheets/aleksi/maps/_map-extend.scss +50 -0
- data/stylesheets/aleksi/maps/_map-filter.scss +84 -0
- data/stylesheets/aleksi/maps/_map-find.scss +95 -0
- data/stylesheets/aleksi/maps/_map-get-tuple.scss +33 -0
- data/stylesheets/aleksi/maps/_map-has-keys.scss +92 -0
- data/stylesheets/aleksi/maps/_map-merge-deep.scss +54 -0
- data/stylesheets/aleksi/maps/_map-select.scss +56 -0
- data/stylesheets/aleksi/maps/_map-sort.scss +125 -0
- data/stylesheets/aleksi/maps/_map-unique.scss +46 -0
- data/stylesheets/aleksi/maps/_map-walk.scss +79 -0
- data/stylesheets/aleksi/maps/_map-zip.scss +64 -0
- data/stylesheets/aleksi/math/_add.scss +66 -0
- data/stylesheets/aleksi/math/_divide.scss +66 -0
- data/stylesheets/aleksi/math/_multiply.scss +66 -0
- data/stylesheets/aleksi/math/_subtract.scss +66 -0
- data/stylesheets/aleksi/sides/_output-sides.scss +71 -0
- data/stylesheets/aleksi/sides/_reduce-sides.scss +74 -0
- data/stylesheets/aleksi/sides/_side-name.scss +48 -0
- data/stylesheets/aleksi/sides/_side-value.scss +83 -0
- data/stylesheets/aleksi/sides/_sides-shorthand.scss +64 -0
- data/stylesheets/aleksi/sides/_to-sides-list.scss +63 -0
- data/stylesheets/aleksi/sides/_to-sides-map.scss +57 -0
- metadata +199 -0
@@ -0,0 +1,54 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - MAP-MERGE-DEEP
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-maps
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "sassy-maps";
|
9
|
+
@import "aleksi/general/throw";
|
10
|
+
@import "aleksi/maps/is-map";
|
11
|
+
|
12
|
+
// =map-merge-deep( $map-a, $map-b )
|
13
|
+
// -----------------------------------------------------------------------------
|
14
|
+
/// Deeply merges two maps together. Works with nested maps.
|
15
|
+
///
|
16
|
+
/// @param {map} $map-a - The first map to merge.
|
17
|
+
/// @param {map} $map-b - The map to merge into `$map-a`.
|
18
|
+
///
|
19
|
+
/// @return {map} - A new map with nested maps merged
|
20
|
+
/// @throw Error if `$map-a` or `$map-b` is not a map
|
21
|
+
///
|
22
|
+
/// @example scss
|
23
|
+
/// $foo: map-merge-deep('a': 10, 'b': ('ba': false, 'bb': 'bar'), 'c': 'foo'), ('a': 20, 'b': ('bb': 'baz', 'bc': 'wiz')));
|
24
|
+
/// // => ('a': 20, 'b': ('ba': false, 'bb': 'baz', 'bc': 'wiz'), 'c': 'foo')
|
25
|
+
///
|
26
|
+
/// @access public
|
27
|
+
/// @since 0.1.0
|
28
|
+
|
29
|
+
@function map-merge-deep( $map-a, $map-b )
|
30
|
+
{
|
31
|
+
@if not is-map($map-a) {
|
32
|
+
@return throw-error('map-merge-deep():: `$map-a` must be a map. Was #{inspect($map-a)}.');
|
33
|
+
}
|
34
|
+
|
35
|
+
@if not is-map($map-b) {
|
36
|
+
@return throw-error('map-merge-deep():: `$map-b` must be a map. Was #{inspect($map-b)}.');
|
37
|
+
}
|
38
|
+
|
39
|
+
$res: $map-a;
|
40
|
+
|
41
|
+
@each $key, $value in $map-b {
|
42
|
+
// if we are merging a nested map
|
43
|
+
// ('map-get()' will return'null' if $res does not have $key so it
|
44
|
+
// is safe not to verify)
|
45
|
+
@if type-of($value) == 'map' and type-of(map-get($res, $key)) == 'map' {
|
46
|
+
// merge nested maps before setting the value
|
47
|
+
$value: map-merge-deep(map-get($res, $key), $value);
|
48
|
+
}
|
49
|
+
|
50
|
+
$res: map-set($res, $key, $value);
|
51
|
+
}
|
52
|
+
|
53
|
+
@return $res;
|
54
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - MAP-SELECT
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-maps
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "sassy-maps/map-set";
|
9
|
+
@import "aleksi/general/throw";
|
10
|
+
@import "aleksi/maps/is-map";
|
11
|
+
|
12
|
+
// =map-select( $map, $keys )
|
13
|
+
// -----------------------------------------------------------------------------
|
14
|
+
/// Reduces a map's by selecting some of its keys only.
|
15
|
+
///
|
16
|
+
/// @param {map} $map - The map to reduce.
|
17
|
+
/// @param {list} $keys - The keys to keep in the resulting map.
|
18
|
+
///
|
19
|
+
/// @return {map} - `$map` with only the keys present in `$keys`.
|
20
|
+
/// @throw Error if `$map` is not a map.
|
21
|
+
///
|
22
|
+
/// @example scss
|
23
|
+
/// $foo: map-select( ('a': 'foo', 'b': 'bar', 'c': 'baz'), 'a' 'c');
|
24
|
+
/// // => ('a': 'foo', 'c': 'baz')
|
25
|
+
///
|
26
|
+
/// @access public
|
27
|
+
/// @since 0.1.0
|
28
|
+
|
29
|
+
@function map-select-keys( $map, $keys )
|
30
|
+
{
|
31
|
+
@if not is-map($map) {
|
32
|
+
@return throw-error('map-select():: $map must be a map, was #{inspect($map)}.');
|
33
|
+
}
|
34
|
+
|
35
|
+
$res: ();
|
36
|
+
|
37
|
+
@each $key, $value in $map {
|
38
|
+
@if index($keys, $key) {
|
39
|
+
$res: map-set($res, $key, $value);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
@return $res;
|
44
|
+
}
|
45
|
+
|
46
|
+
// =map-select( $map, $keys )
|
47
|
+
// -----------------------------------------------------------------------------
|
48
|
+
/// @alias map-select-keys
|
49
|
+
///
|
50
|
+
/// @access public
|
51
|
+
/// @since 0.1.0
|
52
|
+
|
53
|
+
@function map-select( $map, $keys )
|
54
|
+
{
|
55
|
+
@return map-select-keys( $map, $keys );
|
56
|
+
}
|
@@ -0,0 +1,125 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - MAP-SORT
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-maps
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "SassyLists";
|
9
|
+
@import "sassy-maps";
|
10
|
+
@import "aleksi/general/throw";
|
11
|
+
@import "aleksi/general/default-to";
|
12
|
+
@import "aleksi/maps/is-map";
|
13
|
+
|
14
|
+
// =map-sort-values( $map[, $order ])
|
15
|
+
// -----------------------------------------------------------------------------
|
16
|
+
/// Orders a map's keys according to a given, ordered list of values. If no
|
17
|
+
/// order is specified, the alphabetic order of the map's values will be used.
|
18
|
+
/// **Note**: items with a value that is not in the ordered list will be added
|
19
|
+
/// at the end of the resulting map, in the same order as in the original map.
|
20
|
+
///
|
21
|
+
/// @param {type|...} $name [default] - Description
|
22
|
+
///
|
23
|
+
/// @return {type|...} - Description
|
24
|
+
/// @throw Error if `$map` is not a map
|
25
|
+
///
|
26
|
+
/// @access public
|
27
|
+
/// @since 0.1.0
|
28
|
+
///
|
29
|
+
/// @todo Manage duplicated values.
|
30
|
+
|
31
|
+
@function map-sort-values( $map, $order: null )
|
32
|
+
{
|
33
|
+
@if not is-map($map) {
|
34
|
+
@return throw-error('map-sort-keys():: $map must be a map, was #{inspect($map)}.');
|
35
|
+
}
|
36
|
+
|
37
|
+
$keys: map-keys($map);
|
38
|
+
$values: map-values($map);
|
39
|
+
$order: default-to($order, sl-sort($values));
|
40
|
+
|
41
|
+
@each $val in $order {
|
42
|
+
$i: index($values, $val);
|
43
|
+
|
44
|
+
@if index($values, $val) {
|
45
|
+
$res: map-set( $res, nth($keys, $i), $val);
|
46
|
+
$keys: sl-remove-nth($keys, $i);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
// include leftovers at the end
|
51
|
+
@each $key in $keys {
|
52
|
+
$res: map-set($res, $key, map-get($map, $key));
|
53
|
+
}
|
54
|
+
|
55
|
+
@return $res;
|
56
|
+
}
|
57
|
+
|
58
|
+
// =map-sort-keys( $map[, $order ])
|
59
|
+
// -----------------------------------------------------------------------------
|
60
|
+
/// Orders a map's keys according to a given, ordered list of keys. If no order
|
61
|
+
/// is specified, the keys will be ordered alphabetically.
|
62
|
+
/// **Note**: keys that are not in the ordered list will be added at the end of
|
63
|
+
/// the resulting map, in the same order as in the original map.
|
64
|
+
///
|
65
|
+
/// @param {map} $map - The map to order.
|
66
|
+
/// @param {list} $order (alphabetic order) - An ordered list of key names.
|
67
|
+
///
|
68
|
+
/// @return {type|...} - The map with it's keys in the same order as `$order`.
|
69
|
+
/// @throw Error if `$map` is not a map.
|
70
|
+
/// @throw Error if `$order` is not a list, a string, null or false.
|
71
|
+
///
|
72
|
+
/// @access public
|
73
|
+
/// @since 0.1.0
|
74
|
+
|
75
|
+
@function map-sort-keys( $map, $order: null )
|
76
|
+
{
|
77
|
+
@if not is-map($map) {
|
78
|
+
@return throw-error('map-sort-keys():: $map must be a map, was #{inspect($map)}.');
|
79
|
+
}
|
80
|
+
|
81
|
+
// allow lists and single strings for `$order`
|
82
|
+
@if not is-of-type($order, 'list' 'string' 'null') {
|
83
|
+
@return throw-error('map-sort-keys():: $order must be a list or a single string. Was #{inspect($order)}.');
|
84
|
+
}
|
85
|
+
|
86
|
+
$keys: map-keys($map);
|
87
|
+
$order: default-to($order, sl-sort($keys));
|
88
|
+
$res: ();
|
89
|
+
|
90
|
+
@each $key in $order {
|
91
|
+
@if index($keys, $key) {
|
92
|
+
$res: map-set($res, $key, map-get($map, $key));
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
// include leftovers at the end
|
97
|
+
@if length($res) < length($map) {
|
98
|
+
$res: map-merge($res, $map);
|
99
|
+
}
|
100
|
+
|
101
|
+
@return $res;
|
102
|
+
}
|
103
|
+
|
104
|
+
// =map-sort( $map[, $order ])
|
105
|
+
// -----------------------------------------------------------------------------
|
106
|
+
/// @alias map-sort-keys
|
107
|
+
///
|
108
|
+
/// @access public
|
109
|
+
/// @since 0.1.0
|
110
|
+
|
111
|
+
@function map-sort($map, $order: null)
|
112
|
+
{
|
113
|
+
@if type-of($map) != 'map' {
|
114
|
+
@return throw-error('map-sort():: $map must be a map, was #{inspect($map)}.');
|
115
|
+
}
|
116
|
+
|
117
|
+
$keys: sl-sort(map-keys($map));
|
118
|
+
$res: ();
|
119
|
+
|
120
|
+
@each $key in $keys {
|
121
|
+
$res: map-set($res, $key, map-get($map, $key));
|
122
|
+
}
|
123
|
+
|
124
|
+
@return $res;
|
125
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - MAP-UNIQUE
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-maps
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "SassyLists";
|
9
|
+
@import "sassy-maps";
|
10
|
+
@import "aleksi/general/throw";
|
11
|
+
@import "aleksi/maps/is-map";
|
12
|
+
|
13
|
+
// =map-unique( $map )
|
14
|
+
// -----------------------------------------------------------------------------
|
15
|
+
/// removes all duplicate values inside a map.
|
16
|
+
///
|
17
|
+
/// @param {map} $map - The map from which to remove duplicate values
|
18
|
+
///
|
19
|
+
/// @return {map} - New map without duplicates
|
20
|
+
/// @throw Error if `$map` is not a map.
|
21
|
+
///
|
22
|
+
/// @example scss
|
23
|
+
/// $foo: map-unique('a': 'foo', 'b': 'bar', 'c': 'foo', 'd': 'baz');
|
24
|
+
/// // => ('a': 'foo', 'b': 'bar', 'd': 'baz')
|
25
|
+
///
|
26
|
+
/// @access public
|
27
|
+
/// @since 0.1.0
|
28
|
+
|
29
|
+
@function map-unique( $map )
|
30
|
+
{
|
31
|
+
@if not is-map($map) {
|
32
|
+
@return throw-error('map-unique():: $map must be a map, was #{inspect($map)}.');
|
33
|
+
}
|
34
|
+
|
35
|
+
$unique-values: ();
|
36
|
+
$res: ();
|
37
|
+
|
38
|
+
@each $key, $val in $map {
|
39
|
+
@if not sl-contain($unique-values, $val) {
|
40
|
+
$unique-values: append($unique-values, $val);
|
41
|
+
$res: map-set($res, $key, $val);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
@return $res;
|
46
|
+
}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - MAP-WALK
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-maps
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "sassy-maps";
|
9
|
+
@import "aleksi/general/throw";
|
10
|
+
@import "aleksi/maps/is-map";
|
11
|
+
|
12
|
+
// =map-walk( $map, $func[, $args... ])
|
13
|
+
// -----------------------------------------------------------------------------
|
14
|
+
/// Applies the given function to all values inside a map. The map's current
|
15
|
+
/// value is passed as first argument to the function.
|
16
|
+
///
|
17
|
+
/// @param {map} $map - The map to walk over.
|
18
|
+
/// @param {string} $func - The name of the function to apply to each value.
|
19
|
+
/// @param {arglist} $args... - Additional arguments passed to '$func`.
|
20
|
+
///
|
21
|
+
/// @return {map} - The map with modified values.
|
22
|
+
/// @throw Error `$map` must be a map.
|
23
|
+
///
|
24
|
+
/// @example scss
|
25
|
+
/// $foo: map-walk(('foo': 'bar', 'bar': 'baz'), 'to-upper-case');
|
26
|
+
/// // => ('foo': 'BAR', 'bar': 'BAZ')
|
27
|
+
///
|
28
|
+
/// @access public
|
29
|
+
/// @since 0.1.0
|
30
|
+
|
31
|
+
@function map-walk( $map, $func, $args... )
|
32
|
+
{
|
33
|
+
@if not is-map($map) {
|
34
|
+
$e: throw-error('map-walk():: $map must be a map, was #{inspect($map)}.');
|
35
|
+
}
|
36
|
+
|
37
|
+
$res: ();
|
38
|
+
|
39
|
+
@each $key, $val in $map {
|
40
|
+
$new: if( length($args) == 0, call($func, $val), call($func, $val, $args...) );
|
41
|
+
$res: map-set($res, $key, $new);
|
42
|
+
}
|
43
|
+
|
44
|
+
@return $res;
|
45
|
+
}
|
46
|
+
|
47
|
+
// =map-walk-keys( $map, $func[, $args... ])
|
48
|
+
// -----------------------------------------------------------------------------
|
49
|
+
/// Applies the given function to all keys inside a map. The map's current
|
50
|
+
/// key is passed as first argument to the function.
|
51
|
+
///
|
52
|
+
/// @param {map} $map - The map to walk over.
|
53
|
+
/// @param {string} $func - The name of the function to apply to each key.
|
54
|
+
/// @param {arglist} $args... - Additional arguments passed to '$func`.
|
55
|
+
///
|
56
|
+
/// @return {map} - The map with modified keys.
|
57
|
+
/// @throw Error `$map` must be a map.
|
58
|
+
///
|
59
|
+
/// @example scss
|
60
|
+
/// $foo: map-walk(('foo': 'bar', 'bar': 'baz'), 'to-upper-case');
|
61
|
+
/// // => ('FOO': 'bar', 'BAR': 'baz')
|
62
|
+
///
|
63
|
+
/// @access public
|
64
|
+
/// @since 0.1.0
|
65
|
+
|
66
|
+
@function map-walk-keys( $map, $func, $args... )
|
67
|
+
{
|
68
|
+
@if not is-map($map) {
|
69
|
+
$e: throw-error('map-walk-keys():: $map must be a map, was #{inspect($map)}.');
|
70
|
+
}
|
71
|
+
|
72
|
+
$res: ();
|
73
|
+
|
74
|
+
@each $key, $val in $map {
|
75
|
+
$res: map-set($res, call($func, $key, $args...), $val);
|
76
|
+
}
|
77
|
+
|
78
|
+
@return $res;
|
79
|
+
}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - MAP_ZIP
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-maps
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "aleksi/general/throw";
|
9
|
+
@import "aleksi/lists/wrap-in-list";
|
10
|
+
@import "aleksi/maps/is-map";
|
11
|
+
|
12
|
+
// =map-zip( $keys, $values)
|
13
|
+
// -----------------------------------------------------------------------------
|
14
|
+
/// Builds a map based on a list of keys, and a list of values. Equivalent of
|
15
|
+
/// sass's native `zip` function but for maps.
|
16
|
+
/// **Note**: in case `$keys` and `$values` are not the same length, additional
|
17
|
+
/// values will be discarded and it will throw a warning.
|
18
|
+
/// @author [Hugo Giraudel](http://hugogiraudel.com)
|
19
|
+
///
|
20
|
+
/// @param {list} $keys - The keys for the built map.
|
21
|
+
/// @param {list} $values - The values for the built map, in same order.
|
22
|
+
///
|
23
|
+
/// @return {map} - A new map pairing `$keys` with `$values`.
|
24
|
+
///
|
25
|
+
/// @example scss
|
26
|
+
/// $foo: map-zip('a' 'b' 'c', 10 true 'foo');
|
27
|
+
/// // => ('a': 10, 'b': true, 'c': 'foo')
|
28
|
+
/// $bar: map-zip('a' 'b' 'c', 10 'foo');
|
29
|
+
/// // => ('a': 10, 'b': 'foo')
|
30
|
+
/// $baz: map-zip('a', 'b', 10 true 'foo');
|
31
|
+
/// // => ('a': 10, 'b': true)
|
32
|
+
///
|
33
|
+
/// @see http://sass-lang.com/documentation/Sass/Script/Functions.html#zip-instance_method
|
34
|
+
///
|
35
|
+
/// @access public
|
36
|
+
/// @since 0.1.0
|
37
|
+
|
38
|
+
@function map-zip($keys, $values)
|
39
|
+
{
|
40
|
+
// allow creating a single-item map with a nested map
|
41
|
+
@if is-map($values) and length($keys) == 1 {
|
42
|
+
$values: wrap-in-list($values);
|
43
|
+
}
|
44
|
+
|
45
|
+
$l-keys: length($keys);
|
46
|
+
$l-values: length($values);
|
47
|
+
$min: min($l-keys, $l-values);
|
48
|
+
$map: ();
|
49
|
+
|
50
|
+
@if $l-keys != $l-values {
|
51
|
+
$e: throw-warning('map-zip():: Received #{$l-keys} key(s) for #{$l-values} value(s). Resulting map will only have #{$min} pairs.');
|
52
|
+
}
|
53
|
+
|
54
|
+
// return empty map if one of the passed lists is empty
|
55
|
+
@if $min == 0 {
|
56
|
+
@return $map;
|
57
|
+
}
|
58
|
+
|
59
|
+
@for $i from 1 through $min {
|
60
|
+
$map: map-merge($map, (nth($keys, $i): nth($values, $i)));
|
61
|
+
}
|
62
|
+
|
63
|
+
@return $map;
|
64
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - ADD
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-math
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "SassyLists";
|
9
|
+
@import "aleksi/general/throw";
|
10
|
+
@import "aleksi/general/is-of-type";
|
11
|
+
|
12
|
+
// =add( $terms... )
|
13
|
+
// -----------------------------------------------------------------------------
|
14
|
+
/// Calculates the sum between two or more numbers. Usefull when relying on
|
15
|
+
/// `call()`, `walk()` or `apply()` for mathematical operations.
|
16
|
+
/// **Note**: passing more then 2 arguments will add them successively.
|
17
|
+
/// **Note**: if one of the terms is not a number, it will return `null`.
|
18
|
+
///
|
19
|
+
/// @param {arglist} $terms - The operators in the addition.
|
20
|
+
///
|
21
|
+
/// @return {number|null} - The sum resulting from adding `$terms`.
|
22
|
+
/// @throw Warning if one of the terms is not a number.
|
23
|
+
///
|
24
|
+
/// @example scss
|
25
|
+
/// $foo: add(10, 5);
|
26
|
+
/// // => 15
|
27
|
+
/// $bar: add(10, 'hello')
|
28
|
+
/// // => null
|
29
|
+
/// $baz: add(10 5, 3)
|
30
|
+
/// // => null
|
31
|
+
/// $wiz: add(10, 5, 3)
|
32
|
+
/// // => 18
|
33
|
+
///
|
34
|
+
/// @access public
|
35
|
+
/// @since 0.1.0
|
36
|
+
|
37
|
+
@function add( $terms... )
|
38
|
+
{
|
39
|
+
@if not sl-every($terms, 'is-of-type', 'number') {
|
40
|
+
@return throw-warning('add():: all $terms must be numbers — returning null.');
|
41
|
+
}
|
42
|
+
|
43
|
+
@if length($terms) < 2 {
|
44
|
+
@return thow-error('add():: wrong number of arguments, 1 instead of 2 or more.');
|
45
|
+
}
|
46
|
+
|
47
|
+
$sum: nth($terms, 1);
|
48
|
+
|
49
|
+
@each $term in sl-slice($terms, 2) {
|
50
|
+
$sum: $sum + $term;
|
51
|
+
}
|
52
|
+
|
53
|
+
@return $sum;
|
54
|
+
}
|
55
|
+
|
56
|
+
// =sum( $terms... )
|
57
|
+
// -----------------------------------------------------------------------------
|
58
|
+
/// @alias add
|
59
|
+
///
|
60
|
+
/// @access public
|
61
|
+
/// @since 0.1.0
|
62
|
+
|
63
|
+
@function sum( $terms... )
|
64
|
+
{
|
65
|
+
@return add($terms...);
|
66
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - DIVIDE
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-math
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "SassyLists";
|
9
|
+
@import "aleksi/general/throw";
|
10
|
+
@import "aleksi/general/is-of-type";
|
11
|
+
|
12
|
+
// =divide( $terms... )
|
13
|
+
// -----------------------------------------------------------------------------
|
14
|
+
/// Calculates the quotient between two or more numbers. Usefull when relying on
|
15
|
+
/// `call()`, `walk()` or `apply()` for mathematical operations.
|
16
|
+
/// **Note**: passing more then 2 arguments will divide them successively.
|
17
|
+
/// **Note**: if one of the terms is not a number, it will return `null`.
|
18
|
+
///
|
19
|
+
/// @param {arglist} $terms - The operators in the division.
|
20
|
+
///
|
21
|
+
/// @return {number|null} - The quotient resulting from dividing `$terms`.
|
22
|
+
/// @throw Warning if one of the terms is not a number.
|
23
|
+
///
|
24
|
+
/// @example scss
|
25
|
+
/// $foo: divide(10, 5);
|
26
|
+
/// // => 50
|
27
|
+
/// $bar: divide(10, 'hello')
|
28
|
+
/// // => null
|
29
|
+
/// $baz: divide(10 5, 3)
|
30
|
+
/// // => null
|
31
|
+
/// $wiz: divide(10, 5, 3)
|
32
|
+
/// // => 0.66667
|
33
|
+
///
|
34
|
+
/// @access public
|
35
|
+
/// @since 0.1.0
|
36
|
+
|
37
|
+
@function divide( $terms... )
|
38
|
+
{
|
39
|
+
@if not sl-every($terms, 'is-of-type', 'number') {
|
40
|
+
@return throw-warning('divide():: all $terms must be numbers — returning null.');
|
41
|
+
}
|
42
|
+
|
43
|
+
@if length($terms) < 2 {
|
44
|
+
@return thow-error('divide():: wrong number of arguments, 1 instead of 2 or more.');
|
45
|
+
}
|
46
|
+
|
47
|
+
$quot: nth($terms, 1);
|
48
|
+
|
49
|
+
@each $term in sl-slice($terms, 2) {
|
50
|
+
$quot: $quot / $term;
|
51
|
+
}
|
52
|
+
|
53
|
+
@return $quot;
|
54
|
+
}
|
55
|
+
|
56
|
+
// =div( $terms... )
|
57
|
+
// -----------------------------------------------------------------------------
|
58
|
+
/// @alias divide
|
59
|
+
///
|
60
|
+
/// @access public
|
61
|
+
/// @since 0.1.0
|
62
|
+
|
63
|
+
@function div( $terms... )
|
64
|
+
{
|
65
|
+
@return divide( $terms... );
|
66
|
+
}
|
@@ -0,0 +1,66 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - MULTIPLY
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-math
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "SassyLists";
|
9
|
+
@import "aleksi/general/throw";
|
10
|
+
@import "aleksi/general/is-of-type";
|
11
|
+
|
12
|
+
// =multiply( $terms... )
|
13
|
+
// -----------------------------------------------------------------------------
|
14
|
+
/// Calculates the product between two or more numbers. Usefull when relying on
|
15
|
+
/// `call()`, `walk()` or `apply()` for mathematical operations.
|
16
|
+
/// **Note**: passing more then 2 arguments will multiply them successively.
|
17
|
+
/// **Note**: if one of the terms is not a number, it will return `null`.
|
18
|
+
///
|
19
|
+
/// @param {arglist} $terms - The operators in the multiplication.
|
20
|
+
///
|
21
|
+
/// @return {number|null} - The product resulting from multiplying `$terms`.
|
22
|
+
/// @throw Warning if one of the terms is not a number.
|
23
|
+
///
|
24
|
+
/// @example scss
|
25
|
+
/// $foo: multiply(10, 5);
|
26
|
+
/// // => 50
|
27
|
+
/// $bar: multiply(10, 'hello')
|
28
|
+
/// // => null
|
29
|
+
/// $baz: multiply(10 5, 3)
|
30
|
+
/// // => null
|
31
|
+
/// $wiz: multiply(10, 5, 3)
|
32
|
+
/// // => 150
|
33
|
+
///
|
34
|
+
/// @access public
|
35
|
+
/// @since 0.1.0
|
36
|
+
|
37
|
+
@function multiply( $terms... )
|
38
|
+
{
|
39
|
+
@if not sl-every($terms, 'is-of-type', 'number') {
|
40
|
+
@return throw-warning('multiply():: all $terms must be numbers — returning null.');
|
41
|
+
}
|
42
|
+
|
43
|
+
@if length($terms) < 2 {
|
44
|
+
@return thow-error('multiply():: wrong number of arguments, 1 instead of 2 or more.');
|
45
|
+
}
|
46
|
+
|
47
|
+
$prod: nth($terms, 1);
|
48
|
+
|
49
|
+
@each $term in sl-slice($terms, 2) {
|
50
|
+
$prod: $prod * $term;
|
51
|
+
}
|
52
|
+
|
53
|
+
@return $prod;
|
54
|
+
}
|
55
|
+
|
56
|
+
// =mult( $terms... )
|
57
|
+
// -----------------------------------------------------------------------------
|
58
|
+
/// @alias multiply
|
59
|
+
///
|
60
|
+
/// @access public
|
61
|
+
/// @since 0.1.0
|
62
|
+
|
63
|
+
@function mult( $terms... )
|
64
|
+
{
|
65
|
+
@return multiply( $terms... );
|
66
|
+
}
|