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