|
| 1 | +import { |
| 2 | + formatObosMembershipNumber as _formatObosMembershipNumber, |
| 3 | + formatOrganizationNumber as formatOrganizationNumberNo, |
| 4 | + formatPhoneNumber as formatPhoneNumberNo, |
| 5 | + formatPostalCode as formatPostalCodeNo, |
| 6 | +} from './no'; |
| 7 | +import { |
| 8 | + formatOrganizationNumber as formatOrganizationNumberSe, |
| 9 | + formatPhoneNumber as formatPhoneNumberSe, |
| 10 | + formatPostalCode as formatPostalCodeSe, |
| 11 | +} from './se'; |
| 12 | + |
| 13 | +export type Locale = 'no' | 'se'; |
| 14 | + |
| 15 | +type Options = { |
| 16 | + locale: Locale; |
| 17 | +}; |
| 18 | + |
| 19 | +/** |
| 20 | + * Format a phone number |
| 21 | + * @example |
| 22 | + * ``` |
| 23 | + * formatPhoneNumber('00000000', { locale: 'no' }) // => '00 00 00 00' |
| 24 | + * formatPhoneNumber('07012345678', { locale: 'se' }) // => '070-123 45 678' |
| 25 | + * ``` |
| 26 | + */ |
| 27 | +export function formatPhoneNumber(input: string, options: Options): string { |
| 28 | + return options.locale === 'no' |
| 29 | + ? formatPhoneNumberNo(input) |
| 30 | + : formatPhoneNumberSe(input); |
| 31 | +} |
| 32 | + |
| 33 | +/** |
| 34 | + * Format an organization number |
| 35 | + * @example |
| 36 | + * ``` |
| 37 | + * formatOrganizationNumber('000000000', { locale: 'no' }) // => '000 000 000' |
| 38 | + * formatOrganizationNumber('0000000000', { locale: 'se' }) // => '000000-0000' |
| 39 | + * ``` |
| 40 | + */ |
| 41 | +export function formatOrganizationNumber( |
| 42 | + input: string, |
| 43 | + options: Options, |
| 44 | +): string { |
| 45 | + return options.locale === 'no' |
| 46 | + ? formatOrganizationNumberNo(input) |
| 47 | + : formatOrganizationNumberSe(input); |
| 48 | +} |
| 49 | + |
| 50 | +/** |
| 51 | + * Format a postal code |
| 52 | + * @example |
| 53 | + * ``` |
| 54 | + * formatPostalCode('0000', { locale: 'no' }) // => '0000' |
| 55 | + * formatPostalCode('00000', { locale: 'se' }) // => '000 00' |
| 56 | + * ``` |
| 57 | + */ |
| 58 | +export function formatPostalCode(input: string, options: Options): string { |
| 59 | + return options.locale === 'no' |
| 60 | + ? formatPostalCodeNo(input) |
| 61 | + : formatPostalCodeSe(input); |
| 62 | +} |
| 63 | + |
| 64 | +/** |
| 65 | + * Format an OBOS membership number |
| 66 | + * @example |
| 67 | + * ``` |
| 68 | + * formatObosMembershipNumber('0000000', { locale: 'no' }) // => '000 00 00' |
| 69 | + * formatObosMembershipNumber('0000000', { locale: 'se' }) // => '000 00 00' |
| 70 | + * ``` |
| 71 | + */ |
| 72 | +export function formatObosMembershipNumber( |
| 73 | + input: string, |
| 74 | + options: Options, |
| 75 | +): string { |
| 76 | + // this is the same for no/se. But we want the APIs to be consistent... |
| 77 | + return _formatObosMembershipNumber(input); |
| 78 | +} |
0 commit comments