Last active
September 24, 2017 19:34
-
-
Save matthewharwood/eebab9272e29b4a1ab1f88bbae9074b3 to your computer and use it in GitHub Desktop.
Using zipObject to make a map of sets
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
class MediaQueryHelper { | |
public static smallAliases = new Set([0,'s0', 'small', 'sm', 's', 576]); | |
public static mediumAliases = new Set([1, 's1', 'medium', 'med', 'm', 768]); | |
public static defaultAliases = new Set([2,'s2','normal','default','norm','n', 992]); | |
public static largeAliases = new Set([3, 's3', 'large','l', 1200]); | |
public static xLargeAliases = new Set([4, 's4', 'xlarge','xl', 1599]); | |
public static breakpointSizes = [ | |
576, | |
768, | |
992, | |
1200, | |
1599, | |
]; | |
public static getBreakpointSizeByName(bpSize: string | number): number { | |
const allAliases = [ | |
MediaQueryHelper.smallAliases, | |
MediaQueryHelper.mediumAliases, | |
MediaQueryHelper.defaultAliases, | |
MediaQueryHelper.largeAliases, | |
MediaQueryHelper.xLargeAliases | |
]; | |
const aliasMap = zipObject(MediaQueryHelper.breakpointSizes, allAliases); | |
for(let [key, set] of Object.entries(aliasMap)) { | |
if(set.has(bpSize)) { | |
return parseInt(key, 10); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment