Deep access in sass maps with dot notation
https://css-tricks.com/snippets/sass/deep-getset-maps/#comment-1608318
@function ns($map, $path) {
$keys: ();
$separator: '.';
$index : str-index($path, $separator);
@while $index != null {
$item: str-slice($path, 1, $index - 1);
$keys: append($keys, $item);
$path: str-slice($path, $index + 1);
$index : str-index($path, $separator);
}
$keys: append($keys, $path);
@each $key in $keys {
$map: map-get($map, $key);
}
@return $map;
}
$config: (
foo: 'foo',
bar: (
baz: 'bar.baz',
size: (
m: 14px,
l: 18px,
xl: 270px
)
)
);
@function config($path) {
@return ns($config, $path);
}
/// USAGE
.a { font-size: config('bar.size.l'); }