Created
May 10, 2016 10:53
-
-
Save jemgold/b7824e2becd40ab0e73a54c4dfd19815 to your computer and use it in GitHub Desktop.
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
/* @flow */ | |
import { compose, contains, filter, forEach, flip, map, prop } from 'ramda'; | |
type TypekitFont = { | |
descriptors: { | |
featureSettings: string, | |
subset: string, | |
unicodeRange: string, | |
weight: number, | |
}, | |
dynamic: boolean, | |
family: string, | |
id: number, | |
source: string, | |
} | |
const kitFontToFontObject = (font: TypekitFont) => { | |
return new window.Typekit.Font(font.family, font.source, font.descriptors, false); | |
}; | |
const loadAllFonts = forEach(f => window.Typekit.fonts.add(f)); | |
export function loadFonts(fonts: Array<string>) { | |
const containedInFonts = compose( | |
flip(contains)(fonts), | |
prop('family') | |
); | |
if (window.Typekit) { | |
compose( | |
loadAllFonts, | |
map(kitFontToFontObject), | |
filter(containedInFonts) | |
)(window.Typekit.kit); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment