mistergraphx
1/17/2018 - 5:31 PM

Sass dot access datas

@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'); }