Completed
Push — master ( d4303e...fcef0c )
by Jan
15s queued 12s
created

util.ts ➔ validateCurrencyCode   A

Complexity

Conditions 2

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 15
rs 10
c 0
b 0
f 0
cc 2
1
2
/**
3
 * Language codes are
4
 * [ISO 639-2](https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes)
5
 * and must be a 3 character string.
6
 *
7
 * This function could also be potentially be used to validate that the given
8
 * code is a known code.
9
 *
10
 * @param languageCode The language code to be validated.
11
 * @returns Returns the given language code if valid otherwise throws.
12
 */
13
export function validateLanguageCode(languageCode: string) {
14
    if (languageCode.length !== 3) {
15
        throw new RangeError(
16
            "Language string length must be 3, see ISO 639-2 codes"
17
        )
18
    }
19
    return languageCode
20
}
21
22
/**
23
 * Currency codes are
24
 * [ISO-4217](https://en.wikipedia.org/wiki/ISO_4217)
25
 *
26
 * @param currencyCode The currency code to be validated.
27
 * @returns Returns the given currency code if valid otherwise throws.
28
 */
29
export function validateCurrencyCode(currencyCode: string) {
30
    if (currencyCode.length !== 3) {
31
        throw new RangeError(
32
            "Currency string length must be 3, see "
33
        )
34
    }
35
    return currencyCode
36
}
37