| Total Complexity | 6 |
| Complexity/F | 2 |
| Lines of Code | 36 |
| Function Count | 3 |
| Duplicated Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 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 |