Skip to content

Instantly share code, notes, and snippets.

@jemgold
Created May 10, 2016 10:53
Show Gist options
  • Save jemgold/b7824e2becd40ab0e73a54c4dfd19815 to your computer and use it in GitHub Desktop.
Save jemgold/b7824e2becd40ab0e73a54c4dfd19815 to your computer and use it in GitHub Desktop.
/* @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