-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_map.get-any.function.scss
32 lines (28 loc) · 1.21 KB
/
_map.get-any.function.scss
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Sass.
@use 'sass:list';
// Functions.
@use '../list/list.append.function' as *;
@use '../map/map.get.function';
// Status: DONE
// The `map.get-any()` function returns first value not `null` associated with `$key` or any of `$keys` in `$map`. If all values are `null`
// returns fallback value, which is the last value in `$keys`.
// @param `$map` A map to get the value by using `$key` or any of `$keys`.
// @param `$key` The key used to get the value from `$map`.
// @arbitrary `$keys...` Any keys to get the value from `$map`. The last argument is the fallback value.
// @return The return value is not `null` value associated with `$key` or any of `$keys` from the `$map`, if `null` returns fallback value.
@function get-any($map, $key, $keys...) {
$i: 1;
@each $key in append((), $key, comma, $keys...) {
@if not ($i == list.length(append((), $key, comma, $keys...))) {
$result: map.get($map, $key, null);
@if $result {
@return $result;
}
}
$i: $i + 1;
}
@return list.nth($keys, list.length($keys));
}
// Examples.
// @debug get-any((a-test: 1, b: 2, c: null, b-name: 5), c, b-name, null); // 5
// @debug get-any((a-test: 1, b: 2, c: null, b-name: 5, d: null), c, d, 10); // 10