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,96 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - WALK
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-lists
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "SassyLists";
|
9
|
+
@import "aleksi/general/throw";
|
10
|
+
@import "aleksi/maps/map-walk";
|
11
|
+
@import "aleksi/lists/set-list-separator";
|
12
|
+
|
13
|
+
// =walk( $list, $func[, $args... ])
|
14
|
+
// -----------------------------------------------------------------------------
|
15
|
+
/// Applies the given function to each value inside a list, arglist or a map.
|
16
|
+
/// **Note**: SassyLists offers the similar `sl-walk()` function. The difference
|
17
|
+
/// is that Aleksi's `walk()` function will delegate to `map-walk()` when the
|
18
|
+
/// first argument is a map.
|
19
|
+
/// **Note**: When passed a simple value (not a list, arglist or map), it will
|
20
|
+
/// apply the function to it and return the result inside a single item list.
|
21
|
+
///
|
22
|
+
/// @param {list|map} $list [default] - The values to walk over.
|
23
|
+
/// @param {string} $func - The name of the function to apply to each value.
|
24
|
+
/// @param {arglist} $args... - Additional arguments passed to '$func`.
|
25
|
+
///
|
26
|
+
/// @return {list|map} - The list, arglist or map with modified values.
|
27
|
+
/// @throw Warning when walking over a simple value.
|
28
|
+
///
|
29
|
+
/// @example scss
|
30
|
+
/// $foo: map-walk(('foo': 'bar', 'bar': 'baz'), 'to-upper-case');
|
31
|
+
/// // => ('foo': 'BAR', 'bar': 'BAZ')
|
32
|
+
/// $bar: list-walk('foo' 'bar' 'baz', 'to-upper-case');
|
33
|
+
/// // => 'FOO' 'BAR' 'BAZ'
|
34
|
+
/// $baz: list-walk('foo', 'to-upper-case');
|
35
|
+
/// // => 'FOO'
|
36
|
+
///
|
37
|
+
/// @access public
|
38
|
+
/// @since 0.1.0
|
39
|
+
|
40
|
+
@function walk( $list, $func, $args... )
|
41
|
+
{
|
42
|
+
@if type-of($list) == 'map' {
|
43
|
+
@return map-walk($list, $func, $args...);
|
44
|
+
}
|
45
|
+
|
46
|
+
@else if is-list($list) {
|
47
|
+
@return list-walk($list, $func, $args...);
|
48
|
+
}
|
49
|
+
|
50
|
+
$w: throw-warning("Walking over a simple value #{inspect($list)} — resulting value will be returned inside a list.");
|
51
|
+
@return call($func, $list, $args...);
|
52
|
+
}
|
53
|
+
|
54
|
+
// =list-walk( $list, $func[, $args... ])
|
55
|
+
// -----------------------------------------------------------------------------
|
56
|
+
/// Applies the given function to each value inside a list or arglist or a map.
|
57
|
+
/// **Note**: SassyLists offers the similar `sl-walk()` function but it throws
|
58
|
+
/// an wrong-type error in Libsass when passing a function that only accepts one
|
59
|
+
/// argument and an empty arglist as third parameter.
|
60
|
+
///
|
61
|
+
/// @param {list} $list [default] - The list of values to walk over.
|
62
|
+
/// @param {string} $func - The name of the function to apply to each value.
|
63
|
+
/// @param {arglist} $args... - Additional arguments passed to '$func`.
|
64
|
+
///
|
65
|
+
/// @return {list|map} - The list, arglist or map with modified values.
|
66
|
+
/// @throw Error if `$value` is not a list.
|
67
|
+
/// @throw Warning when walking over a simple value.
|
68
|
+
///
|
69
|
+
/// @example scss
|
70
|
+
/// $foo: map-walk(('foo': 'bar', 'bar': 'baz'), 'to-upper-case');
|
71
|
+
/// // => ('foo': 'BAR', 'bar': 'BAZ')
|
72
|
+
/// $bar: list-walk('foo' 'bar' 'baz', 'to-upper-case');
|
73
|
+
/// // => 'FOO' 'BAR' 'BAZ'
|
74
|
+
/// $baz: list-walk('foo', 'to-upper-case');
|
75
|
+
/// // => 'FOO'
|
76
|
+
///
|
77
|
+
/// @access public
|
78
|
+
/// @since 0.1.0
|
79
|
+
|
80
|
+
@function list-walk( $list, $func, $args... )
|
81
|
+
{
|
82
|
+
@if not is-list($list) {
|
83
|
+
$e: throw-error("list-walk():: $list must be a list, was #{inspect($list)}.");
|
84
|
+
}
|
85
|
+
|
86
|
+
$sep: list-separator($list);
|
87
|
+
$res: ();
|
88
|
+
|
89
|
+
@each $item in $list {
|
90
|
+
$new: if( length($args) == 0, call($func, $item), call($func, $item, $args...) );
|
91
|
+
$res: append($res, $new);
|
92
|
+
}
|
93
|
+
|
94
|
+
// keep original list separator
|
95
|
+
@return set-list-separator($res, $sep);
|
96
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - WRAP-IN-LIST
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-lists
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "aleksi/lists/set-list-separator";
|
9
|
+
|
10
|
+
// =wrap-in-list( $value[, $separator ])
|
11
|
+
// -----------------------------------------------------------------------------
|
12
|
+
/// Wraps any value inside a single-item list.
|
13
|
+
/// **Note**: contrary to SassyCast's `to-list()` function, maps won't be
|
14
|
+
/// transformed into lists, and lists will get nested.
|
15
|
+
///
|
16
|
+
/// @param {any} $value - The value to wrap inside a list.
|
17
|
+
/// @param {string} $separator ['space'] - The separator type the list should use.
|
18
|
+
///
|
19
|
+
/// @return {list} - A single item list with `$value` inside, and using `$separator`.
|
20
|
+
///
|
21
|
+
/// @example scss
|
22
|
+
/// $foo: wrap-in-list(10);
|
23
|
+
/// // => 10
|
24
|
+
/// type-of($foo);
|
25
|
+
/// // => list
|
26
|
+
/// $bar: wrap-in-list('foo' 'bar');
|
27
|
+
/// // => 'foo' 'bar'
|
28
|
+
/// length($bar);
|
29
|
+
/// // => 1
|
30
|
+
/// $baz: wrap-in-list( ('a': 'foo', 'b': 'bar') );
|
31
|
+
/// // => ('a': 'foo', 'b': 'bar')
|
32
|
+
/// type-of($baz);
|
33
|
+
/// // => list
|
34
|
+
///
|
35
|
+
/// @access public
|
36
|
+
/// @since 0.1.0
|
37
|
+
|
38
|
+
@function wrap-in-list( $value, $separator: 'space' )
|
39
|
+
{
|
40
|
+
$value: ($value,);
|
41
|
+
@return if($separator == 'space', to-space-list($value), $value);
|
42
|
+
}
|
@@ -0,0 +1,39 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - DEBUG-MAP
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-maps
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "aleksi/maps/map-depth";
|
9
|
+
|
10
|
+
// =debug-map( $map )
|
11
|
+
// -----------------------------------------------------------------------------
|
12
|
+
/// Prints out the given map's contents and useful information for debugging
|
13
|
+
/// purposes.
|
14
|
+
/// @author [Hugo Giraudel](http://hugogiraudel.com)
|
15
|
+
///
|
16
|
+
/// @param {map} $map - The map to print out.
|
17
|
+
///
|
18
|
+
/// @throw Error if `$map` is not a map.
|
19
|
+
///
|
20
|
+
/// @access public
|
21
|
+
/// @since 0.1.0
|
22
|
+
|
23
|
+
@mixin debug-map( $map )
|
24
|
+
{
|
25
|
+
@at-root {
|
26
|
+
@debug-map {
|
27
|
+
__toString__: inspect($map);
|
28
|
+
__length__: length($map);
|
29
|
+
__depth__: map-depth($map);
|
30
|
+
__keys__: map-keys($map);
|
31
|
+
__properties__ {
|
32
|
+
@each $key, $value in $map {
|
33
|
+
$key-str: '(#{type-of($value)})-#{$key}';
|
34
|
+
#{$key-str}: inspect($value);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - IS-MAP
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-maps
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
// =is-map( $value )
|
9
|
+
// -----------------------------------------------------------------------------
|
10
|
+
/// Verifies if the given value is a map. Also accepts `()`, contrary to testing
|
11
|
+
/// manually `type-of(()) == map`.
|
12
|
+
///
|
13
|
+
/// @param {any} $value - The value to test.
|
14
|
+
///
|
15
|
+
/// @return {bool} - Whether `$value` is a map.
|
16
|
+
///
|
17
|
+
/// @example scss
|
18
|
+
/// $foo: is-map(('a': 10, 'b': 'foo'));
|
19
|
+
/// // => true
|
20
|
+
/// $bar: is-map(());
|
21
|
+
/// // => true
|
22
|
+
/// $baz: is-map('a' 10 'b' 'foo');
|
23
|
+
/// // => false
|
24
|
+
///
|
25
|
+
/// @access public
|
26
|
+
/// @since 0.1.0
|
27
|
+
|
28
|
+
@function is-map( $value )
|
29
|
+
{
|
30
|
+
@return (type-of($value) == map or $value == ());
|
31
|
+
}
|
@@ -0,0 +1,45 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - MAP-CLEAN
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-maps
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "aleksi/general/throw";
|
9
|
+
@import "aleksi/maps/is-map";
|
10
|
+
|
11
|
+
// =map-clean( $map )
|
12
|
+
// -----------------------------------------------------------------------------
|
13
|
+
/// Removes all falsy values from a map.
|
14
|
+
/// **Note**: if all item shave been removed, it will return `()` to act like
|
15
|
+
/// all other map filtering functions (emptying a list with `map-remove()` would
|
16
|
+
/// normally return a *real* empty map ``);
|
17
|
+
///
|
18
|
+
/// @param {map} $map - The map to clean.
|
19
|
+
///
|
20
|
+
/// @return {map} - A new map, without falsy values.
|
21
|
+
/// @throw Error if `$map` is not a map.
|
22
|
+
///
|
23
|
+
/// @example scss
|
24
|
+
/// $foo: map-clean( ('a': 10, 'b': false, 'c': 'foo', 'd': null) );
|
25
|
+
/// // => ('a': 10, 'c': 'foo')
|
26
|
+
///
|
27
|
+
/// @access public
|
28
|
+
/// @since 0.1.0
|
29
|
+
|
30
|
+
@function map-clean( $map )
|
31
|
+
{
|
32
|
+
@if not is-map($map) {
|
33
|
+
@return throw-error('map-clean():: $map must be a map. Was #{inspect($map)}');
|
34
|
+
}
|
35
|
+
|
36
|
+
@each $key, $value in $map {
|
37
|
+
@if not $value {
|
38
|
+
$map: map-remove($map, $key);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
// return the empty map `()` instead of `` if all map
|
43
|
+
// items have been remove.
|
44
|
+
@return if(length($map) == 0, (), $map);
|
45
|
+
}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - MAP-DEPTH
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-maps
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "aleksi/general/throw";
|
9
|
+
@import "aleksi/maps/is-map";
|
10
|
+
|
11
|
+
// =map-depth( $map )
|
12
|
+
// -----------------------------------------------------------------------------
|
13
|
+
/// Returns the depth level of a given map.
|
14
|
+
/// @author [Hugo Giraudel](http://hugogiraudel.com)
|
15
|
+
///
|
16
|
+
/// @param {map} $map - The map to analyze.
|
17
|
+
///
|
18
|
+
/// @return {number} - The depth of `$map`.
|
19
|
+
/// @throw Error if `$map` is not a map.
|
20
|
+
///
|
21
|
+
/// @example scss
|
22
|
+
/// $foo: map-depth( ('a': 'foo', 'b': ( 'ba': 'bar', 'bb': 'baz' )));
|
23
|
+
/// // => 2
|
24
|
+
/// $bar: map-depht('a': 'foo', 'b': 'bar', 'c': 'baz');
|
25
|
+
/// // => 1
|
26
|
+
///
|
27
|
+
///
|
28
|
+
/// @access public
|
29
|
+
/// @since 0.1.0
|
30
|
+
|
31
|
+
@function map-depth( $map )
|
32
|
+
{
|
33
|
+
@if not is-map($map) {
|
34
|
+
@return throw-error('map-depth():: $map must be a map, was #{inspect($map)}.');
|
35
|
+
}
|
36
|
+
|
37
|
+
$lvl: 1;
|
38
|
+
|
39
|
+
@each $key, $val in $map {
|
40
|
+
@if type-of($val) == 'map' {
|
41
|
+
$lvl: max(map-depth($val) + 1, $lvl);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
@return $lvl;
|
46
|
+
}
|
@@ -0,0 +1,50 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - MAP-EXTEND
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-maps
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "SassyLists";
|
9
|
+
@import "aleksi/general/throw";
|
10
|
+
@import "aleksi/maps/is-map";
|
11
|
+
@import "aleksi/maps/map-merge-deep";
|
12
|
+
|
13
|
+
// =map-extend( $maps... )
|
14
|
+
// -----------------------------------------------------------------------------
|
15
|
+
/// Merges the given maps successively. Allows to merge more then two maps
|
16
|
+
/// together.
|
17
|
+
|
18
|
+
@function map-extend( $maps... )
|
19
|
+
{
|
20
|
+
@if length($maps) < 2 {
|
21
|
+
$e: throw-warning('map-extend():: trying to extend one map only. Returning the map as is.');
|
22
|
+
@return $nth($maps, 1);
|
23
|
+
}
|
24
|
+
|
25
|
+
$res: nth($maps, 1);
|
26
|
+
@each $map in sl-slice($maps, 2) {
|
27
|
+
$res: map-merge($res, $map);
|
28
|
+
}
|
29
|
+
|
30
|
+
@return $res;
|
31
|
+
}
|
32
|
+
|
33
|
+
// =map-extend-deep( $maps... )
|
34
|
+
// -----------------------------------------------------------------------------
|
35
|
+
|
36
|
+
@function map-extend-deep( $maps... )
|
37
|
+
{
|
38
|
+
@if length($maps) < 2 {
|
39
|
+
$e: throw-warning('map-extend-deep():: trying to extend one map only. Returning the map as is.');
|
40
|
+
@return $nth($maps, 1);
|
41
|
+
}
|
42
|
+
|
43
|
+
$res: nth($maps, 1);
|
44
|
+
|
45
|
+
@each $map in sl-slice($maps, 2) {
|
46
|
+
$res: map-merge-deep($res, $map);
|
47
|
+
}
|
48
|
+
|
49
|
+
@return $res;
|
50
|
+
}
|
@@ -0,0 +1,84 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - MAP-FILTER
|
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-filter( $map, $test, $args... )
|
13
|
+
// -----------------------------------------------------------------------------
|
14
|
+
/// Removes items in a map with a value that doesn't pass a given test function.
|
15
|
+
/// **Note**: to pass the test, the test function must return a truethy value —
|
16
|
+
/// not per se the boolean `true`.
|
17
|
+
///
|
18
|
+
/// @param {map} $map - The map with the item values to test.
|
19
|
+
/// @param {string} $test - The name of the test function to run on each item's value.
|
20
|
+
/// @param {arglist} $args... - Additional arguments for `$test`.
|
21
|
+
///
|
22
|
+
/// @return {map} - `$map` without the items that didn't pass the `$test` function.
|
23
|
+
///
|
24
|
+
/// @example scss
|
25
|
+
/// $foo: map-filter( ('foo': 10, 'bar': 5px, 'baz': 7, 'wiz' 3), 'unitless');
|
26
|
+
/// // => ('foo': 10, 'baz': 7, 'wiz': 3)
|
27
|
+
/// $bar: map-filter( ('foo': 10px, 'bar': 2%, 'baz': 4px, 'wiz': 8em), 'comparable', 1px);
|
28
|
+
/// // => ('foo': 10px, 'baz': 4px)
|
29
|
+
///
|
30
|
+
/// @access public
|
31
|
+
/// @since 0.1.0
|
32
|
+
|
33
|
+
@function map-filter( $map, $test, $args... )
|
34
|
+
{
|
35
|
+
@if not is-map($map) {
|
36
|
+
@return throw-error('map-filter():: $map must be a map, was #{inspect($map)}.');
|
37
|
+
}
|
38
|
+
|
39
|
+
$res: ();
|
40
|
+
|
41
|
+
@each $key, $val in $map {
|
42
|
+
@if call($test, $val, $args...) {
|
43
|
+
$res: map-set($res, $key, $val);
|
44
|
+
}
|
45
|
+
}
|
46
|
+
|
47
|
+
@return $res;
|
48
|
+
}
|
49
|
+
|
50
|
+
// =map-filter-keys( $map, $test, $args... )
|
51
|
+
// -----------------------------------------------------------------------------
|
52
|
+
/// Removes items in a map with a key that doesn't pass a given test function.
|
53
|
+
/// **Note**: to pass the test, the test function must return a truethy value —
|
54
|
+
/// not per se the boolean `true`.
|
55
|
+
///
|
56
|
+
/// @param {map} $map - The map with the item keys to test.
|
57
|
+
/// @param {string} $test - The name of the test function to run on each item's key.
|
58
|
+
/// @param {arglist} $args... - Additional arguments for `$test`.
|
59
|
+
///
|
60
|
+
/// @return {map} - `$map` without the items that didn't pass the `$test` function.
|
61
|
+
///
|
62
|
+
/// @example scss
|
63
|
+
/// $foo: map-filter( ('foo': 10, 'bar': 5px, 'baz': 7, 'wiz' 3), 'str-index', 'b');
|
64
|
+
/// // => ('bar': 5px, 'baz': 7)
|
65
|
+
///
|
66
|
+
/// @access public
|
67
|
+
/// @since 0.1.0
|
68
|
+
|
69
|
+
@function map-filter-keys( $map, $test, $args... )
|
70
|
+
{
|
71
|
+
@if not is-map($map) {
|
72
|
+
@return throw-error('map-filter():: $map must be a map, was #{inspect($map)}.');
|
73
|
+
}
|
74
|
+
|
75
|
+
$res: ();
|
76
|
+
|
77
|
+
@each $key, $val in $map {
|
78
|
+
@if call($test, $key, $args...) {
|
79
|
+
$res: map-set($res, $key, $val);
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
@return $res;
|
84
|
+
}
|
@@ -0,0 +1,95 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - MAP-FIND
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-maps
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "aleksi/general/throw";
|
9
|
+
@import "aleksi/maps/is-map";
|
10
|
+
|
11
|
+
// =map-find-key( $map, $value )
|
12
|
+
// -----------------------------------------------------------------------------
|
13
|
+
/// Returns the key under which a given value is stored in a map. If the value
|
14
|
+
/// is found multiple times, the first key for it will be returned. Returns
|
15
|
+
/// `null` if the value wasn't found.
|
16
|
+
///
|
17
|
+
/// @param {map} $map - The map to search in.
|
18
|
+
/// @param {any} $value - The value to search for.
|
19
|
+
///
|
20
|
+
/// @return {string} - The first map's key under which `$value` is stored.
|
21
|
+
/// @throw Error if `$map` is not a map.
|
22
|
+
///
|
23
|
+
/// @example scss
|
24
|
+
/// $foo: map-find('a': 10, 'b': 5, 'c': 3, 5);
|
25
|
+
/// // => 'b'
|
26
|
+
/// $bar: map-find('a': 10, 'b': 5, 'c': 3, 'd': 5, 5);
|
27
|
+
/// // => 'b'
|
28
|
+
///
|
29
|
+
/// @access public
|
30
|
+
/// @since 0.1.0
|
31
|
+
|
32
|
+
@function map-find-key( $map, $value )
|
33
|
+
{
|
34
|
+
@if not is-map($map) {
|
35
|
+
@return throw-error('map-find-key():: $map must be a map, was #{inspect($map)}.');
|
36
|
+
}
|
37
|
+
|
38
|
+
@each $key, $val in $map {
|
39
|
+
@if $val == $value {
|
40
|
+
@return $key;
|
41
|
+
}
|
42
|
+
}
|
43
|
+
|
44
|
+
@return null;
|
45
|
+
}
|
46
|
+
|
47
|
+
// =map-find( $map, $value )
|
48
|
+
// -----------------------------------------------------------------------------
|
49
|
+
/// @alias map-find-key
|
50
|
+
///
|
51
|
+
/// @access public
|
52
|
+
/// @since 0.1.0
|
53
|
+
|
54
|
+
@function map-find( $map, $value )
|
55
|
+
{
|
56
|
+
@return map-find-key($map, $value);
|
57
|
+
}
|
58
|
+
|
59
|
+
// =map-find-keys( $map, $value )
|
60
|
+
// -----------------------------------------------------------------------------
|
61
|
+
/// Returns a list with all the keys in a map that hold the given value.
|
62
|
+
///
|
63
|
+
/// @param {map} $map - The map to search in.
|
64
|
+
/// @param {any} $value - The value to search for
|
65
|
+
///
|
66
|
+
/// @return {list} - The list of keys that hold `$value` in `$map`.
|
67
|
+
/// @throw Error if `$map` is not a map.
|
68
|
+
///
|
69
|
+
/// @example scss
|
70
|
+
/// $foo: map-find-keys( 'a': 'foo', 'b': 'bar', 'c': 'foo', 'd': 'baz', 'foo');
|
71
|
+
/// // => 'a' 'b'
|
72
|
+
/// $bar: map-find-keys( 'a': 'foo', 'b': 'bar', 'c': 'baz', 'foo');
|
73
|
+
/// // => 'a';
|
74
|
+
/// $bar-type: type-of($bar);
|
75
|
+
/// // => list
|
76
|
+
///
|
77
|
+
/// @access public
|
78
|
+
/// @since 0.1.0
|
79
|
+
|
80
|
+
@function map-find-keys( $map, $value )
|
81
|
+
{
|
82
|
+
@if not is-map($map) {
|
83
|
+
@return throw-error('map-find-keys():: $map must be a map, was #{inspect($map)}.');
|
84
|
+
}
|
85
|
+
|
86
|
+
$keys: ();
|
87
|
+
|
88
|
+
@each $key, $val in $map {
|
89
|
+
@if $val == $value {
|
90
|
+
$keys: append($keys, $key);
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
@return $keys;
|
95
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - MAP-GET-TUPLE
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-maps
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
// =map-get-tuple( $map, $key )
|
9
|
+
// -----------------------------------------------------------------------------
|
10
|
+
/// Retrieves a tuple (a key, value formatted as a map item) from a map. Returns
|
11
|
+
/// `null` if `$key` was not found in `$map`.
|
12
|
+
///
|
13
|
+
/// @param {map} $map - The map in which to search for the tuple.
|
14
|
+
/// @param {string} $key - The key of the tuple to retreive.
|
15
|
+
///
|
16
|
+
/// @return {map} - The `(key: value)` pair corresponding to `$key`.
|
17
|
+
/// @throw Error if `$map`is not a map.
|
18
|
+
///
|
19
|
+
/// @example scss
|
20
|
+
/// $foo: map-get-tuple('a': 'foo', 'b': 'bar', 'a');
|
21
|
+
/// // => ('a': 'foo')
|
22
|
+
///
|
23
|
+
/// @access public
|
24
|
+
/// @since 0.1.0
|
25
|
+
|
26
|
+
@function map-get-tuple( $map, $key )
|
27
|
+
{
|
28
|
+
@if not is-map($map) {
|
29
|
+
@return throw-error('map-get-tuple():: $map must be a map, was #{inspect($map)}.');
|
30
|
+
}
|
31
|
+
|
32
|
+
@return (#{$key}: map-get($map, $key));
|
33
|
+
}
|
@@ -0,0 +1,92 @@
|
|
1
|
+
// =============================================================================
|
2
|
+
// =ALEKSI - MAP-HAS-KEYS
|
3
|
+
// =============================================================================
|
4
|
+
////
|
5
|
+
//// @group aleksi-maps
|
6
|
+
//// @author [Yoannis Jamar](http://yoannis.me)
|
7
|
+
|
8
|
+
@import "aleksi/general/throw";
|
9
|
+
@import "aleksi/maps/is-map";
|
10
|
+
|
11
|
+
// =map-has-keys( $map, $keys )
|
12
|
+
// -----------------------------------------------------------------------------
|
13
|
+
/// Tests if a map has all the given keys at first level.
|
14
|
+
/// @author [Hugo Giraudel](http://hugogiraudel.com)
|
15
|
+
///
|
16
|
+
/// @param {map} $map - The map to search in for `$keys...`.
|
17
|
+
/// @param {list} $keys - The keys to search for.
|
18
|
+
///
|
19
|
+
/// @return {bool} - Whether all keys were found in first level of `$map`.
|
20
|
+
/// @throw Error if `$map` is not a map.
|
21
|
+
///
|
22
|
+
/// @example scss
|
23
|
+
/// $foo: map-has-keys( ('a': 'foo', 'b': 'bar', 'c': 'baz'), 'a', 'd');
|
24
|
+
/// // => false
|
25
|
+
/// $bar: map-has-keys( ('a': 'foo', 'b': 'bar', 'c': 'baz'), 'a', 'b');
|
26
|
+
/// // => true
|
27
|
+
///
|
28
|
+
/// @access public
|
29
|
+
/// @since 0.1.0
|
30
|
+
|
31
|
+
@function map-has-keys($map, $keys)
|
32
|
+
{
|
33
|
+
@if not is-map($map) {
|
34
|
+
@return throw-error('map-has-keys():: $map must be a map, was #{inspect($map)}.');
|
35
|
+
}
|
36
|
+
|
37
|
+
@each $key in $keys {
|
38
|
+
@if not map-has-key($map, $key) {
|
39
|
+
@return false;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
@return true;
|
44
|
+
}
|
45
|
+
|
46
|
+
// =map-has-deep-key($map, $keys...)
|
47
|
+
// -----------------------------------------------------------------------------
|
48
|
+
/// Tests if a map has all given keys nested within each other.
|
49
|
+
/// @author [Hugo Giraudel](http://hugogiraudel.com)
|
50
|
+
///
|
51
|
+
/// @param {map} $map - The map to search in for `$keys...`.
|
52
|
+
/// @param {arglist} $keys - The keys to search for.
|
53
|
+
///
|
54
|
+
/// @return {bool} - Whether `$map` has all `$keys` nested within each other.
|
55
|
+
/// @throw Error if `$map` is not a map.
|
56
|
+
///
|
57
|
+
/// @example scss
|
58
|
+
/// $foo: map-has-deep-keys( ('a': 'foo', 'b': ('ba': 'bar', 'bb': 'baz')), 'a', 'b');
|
59
|
+
/// // => true
|
60
|
+
/// $bar: map-has-deep-keys( 'a': 'foo', 'b': 'bar', 'a', 'b')
|
61
|
+
///
|
62
|
+
/// @access public
|
63
|
+
/// @since 0.1.0
|
64
|
+
|
65
|
+
@function map-has-deep-key($map, $keys...)
|
66
|
+
{
|
67
|
+
@if not is-map($map) {
|
68
|
+
@return throw-error('map-has-deep-key():: $map must be a map, was #{inspect($map)}.');
|
69
|
+
}
|
70
|
+
|
71
|
+
@each $key in $keys {
|
72
|
+
@if not map-has-key($map, $key) {
|
73
|
+
@return false;
|
74
|
+
}
|
75
|
+
|
76
|
+
$map: map-get($map, $key);
|
77
|
+
}
|
78
|
+
|
79
|
+
@return true;
|
80
|
+
}
|
81
|
+
|
82
|
+
// =map-has-nested-key( $map, $keys... )
|
83
|
+
// -----------------------------------------------------------------------------
|
84
|
+
/// @alias map-has-deep-key
|
85
|
+
///
|
86
|
+
/// @access public
|
87
|
+
/// @since 0.1.0
|
88
|
+
|
89
|
+
@function map-has-nested-key( $map, $keys... )
|
90
|
+
{
|
91
|
+
@return map-has-deep-key($map, $keys...);
|
92
|
+
}
|