-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path_utils.scss
More file actions
58 lines (50 loc) · 1.54 KB
/
_utils.scss
File metadata and controls
58 lines (50 loc) · 1.54 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* HELPER FUNCTIONS
* some useful map functions with safe gaurds
* https://www.sitepoint.com/extra-map-functions-sass/
*/
// adds a safe gaurd in case map is not a map
@function map-safe-get($map: (), $key: '""') {
@return if(type-of($map) == map, map-get($map, $key), '');
}
// loops through and returns the value the key list path or the default
@function map-deep-get($map, $keys...) {
@each $key in $keys {
$map: map-safe-get($map, $key);
}
@return $map;
}
// like merge but is not losey and allows deep merging
@function map-extend($map, $maps... /*, $deep */) {
$last: nth($maps, -1);
$deep: $last == true;
$max: if($deep, length($maps) - 1, length($maps));
// Loop through all maps in $maps...
@for $i from 1 through $max {
// Store current map
$current: nth($maps, $i);
// If not in deep mode, simply merge current map with map
@if not $deep {
$map: map-merge($map, $current);
} @else {
// If in deep mode, loop through all tuples in current map
@each $key, $value in $current {
@if length($value) > 0 {
// If value is a nested map and same key from map is a nested map as well
@if type-of($value) == 'map' and type-of(map-get($map, $key)) == 'map' {
// Recursive extend
$value: map-extend(map-get($map, $key), $value, true);
}
// Merge current tuple with map
$map: map-merge(
$map,
(
$key: $value,
)
);
}
}
}
}
@return $map;
}