Created
March 11, 2019 05:55
-
-
Save anykeyist/9b19be55b24d9c7241402cf3d20bfedc to your computer and use it in GitHub Desktop.
SASS map reverse function
This file contains hidden or 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
| @function mapReverse ($map) { | |
| $result: null; | |
| @if type-of($map) == "map" { | |
| $keys: map-keys($map); | |
| $map-reversed: (); | |
| @for $i from length($keys) through 1 { | |
| $map-reversed: map-merge( | |
| $map-reversed, | |
| (nth($keys, $i): map-get($map, nth($keys, $i))) | |
| ); | |
| } | |
| @if type-of($map-reversed) == "map" { | |
| $result: $map-reversed; | |
| } @else { | |
| @warn 'There was an error reversing the order of "#{$map}"'; | |
| } | |
| } @else { | |
| @warn '"#{$map}" is not a valid map'; | |
| } | |
| @return $result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment