-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(map.get-index()): add function to get value based on key checked…
… by `list.index()`.
- Loading branch information
1 parent
8ac459b
commit e1459b9
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Modules. | ||
@use '../list'; | ||
|
||
// Status: DONE | ||
// The `map.get-index()` function returns value from `$key` and `$keys`. | ||
// @param `$map` A map to get value. | ||
// @param `$key` Required key to `list.index()` map. | ||
// @arbitrary `$keys...` Optional nested keys. | ||
// @returns The returned value is value of `$key` and/or `$keys`. | ||
@function get-index($map, $key, $keys...) { | ||
@if $key { | ||
@each $key-list, $value in $map { | ||
@if list.index($key-list, $key) { | ||
@if list.length($keys) > 0 { | ||
@return get-index($value, list.nth($keys, 1), list.remove-nth($keys, 1)...); | ||
} @else { | ||
@return $value; | ||
} | ||
} | ||
} | ||
} | ||
@return $map; | ||
} | ||
|
||
// Examples. | ||
// $example: ( | ||
// test basic: ( | ||
// basic two: ( | ||
// hue saturation: ( | ||
// lightness alpha: hsla(15deg, 30%, 35%, 1) | ||
// ) | ||
// ) | ||
// ) | ||
// ); | ||
|
||
// @debug get-index($example, test, two, hue, alpha); // hsl(15deg, 30%, 35%) |