UNPKG

607 BJavaScriptView Raw
1import list from 'google-fonts-complete/api-response.json'
2
3const getWeights = variants =>
4 variants
5 .filter(v => !v.includes('italic'))
6 .map(v => (v === 'regular' ? 400 : v))
7
8const all = list.map(font => ({
9 category: font.category,
10 value: font.family,
11 weights: getWeights(font.variants),
12}))
13
14const byName = {}
15all.forEach(f => (byName[f.value] = f))
16
17export const fontFamily = all.map(f => f.value)
18
19export const isGoogleFont = family => !!byName[family]
20
21export const maybeAddFallbackFont = f => {
22 const font = byName[f]
23
24 return font && font.category ? `${f}, ${font.category}` : f
25}