summaryrefslogtreecommitdiff
path: root/shared/fonts/src/index.ts
blob: 509d2115d796ab1ca46d883e224ebe0b4558cb5b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const LOCALES_REGEX = {
    ARABIC: /^(ar-?)/,
    HEBREW: /^(he-?)/,
    HINDI: /^(hi-?)/,
    JAPANESE: /^(ja-?)/,
    KOREAN: /^(ko-?)/,
    THAI: /^(th-?)/,
};

export const BASE = '//www.apple.com/wss/fonts';

/**
 *
 * @param locale %7C String %7C The locale to get the font URL for
 * @param includeNewYork %7C Boolean %7C Used to specifiy whether to include the New York font which is an additional font in addition to SF Pro
 * @returns URL string to fetch fonts
 */
export function getFontURL(locale: string, includeNewYork?: boolean): string {
    let fonts = 'SF+Pro,v4%7CSF+Pro+Icons,v1';
    // Check for any Arabic locales first (full list here: https://confluence.sd.apple.com/display/AMPRighttoLeft/BRD)
    if (LOCALES_REGEX.ARABIC.test(locale)) {
        fonts = `${fonts}%7CArabic+UI,v1`;
    } else if (LOCALES_REGEX.HEBREW.test(locale)) {
        fonts = `${fonts}%7CArial+Hebrew,v1`;
    } else if (LOCALES_REGEX.HINDI.test(locale)) {
        fonts = `${fonts}%7CKohinoor+Devanagari,v1`;
    } else if (LOCALES_REGEX.JAPANESE.test(locale)) {
        fonts = `${fonts}%7CSF+Pro+JP,v1`;
    } else if (LOCALES_REGEX.KOREAN.test(locale)) {
        fonts = `${fonts}%7CSF+Pro+KR,v2`;
    } else if (LOCALES_REGEX.THAI.test(locale)) {
        fonts = `${fonts}%7CThonburi+Pro,v1`;
    }

    switch (locale) {
        case 'zh-cn':
            fonts = `SF+Pro,v4%7CSF+Pro+SC,v1%7CSF+Pro+Icons,v1`;
            break;
        case 'zh-hk':
            fonts = `SF+Pro,v4%7CSF+Pro+HK,v1%7CSF+Pro+Icons,v1`;
            break;
        case 'zh-mo':
        case 'zh-tw':
            fonts = `SF+Pro,v4%7CSF+Pro+TC,v1%7CSF+Pro+Icons,v1`;
            break;
    }

    if (includeNewYork) {
        fonts = `${fonts}%7CNew+York+Small,v1%7CNew+York+Medium,v1%7CNew+York+Large,v1`;
    }

    return `${BASE}?families=${fonts}&display=swap`;
}