File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change 11import { replaceIfMatch } from './utils' ;
22
3+ // See https://sprakradet.no/godt-og-korrekt-sprak/rettskriving-og-grammatikk/tall-tid-dato/
4+ const REGULAR_PHONE_NUMBER_FORMAT = / ^ ( \d { 2 } ) ( \d { 2 } ) ( \d { 2 } ) ( \d { 2 } ) $ / ;
5+ const EIGHT_HUNDRED_SERIES_PHONE_NUMBER_FORMAT = / ^ ( \d { 3 } ) ( \d { 2 } ) ( \d { 3 } ) $ / ;
6+
7+ /**
8+ * Format a phone number
9+ * @example
10+ * ```
11+ * formatPhoneNumber('00000000') // => '00 00 00 00'
12+ * formatPhoneNumber('80000000') // => '800 00 000'
13+ * ```
14+ */
15+ export function formatPhoneNumber ( number : string ) : string {
16+ if ( number . startsWith ( '8' ) ) {
17+ return number . replace ( EIGHT_HUNDRED_SERIES_PHONE_NUMBER_FORMAT , '$1 $2 $3' ) ;
18+ }
19+
20+ return number . replace ( DEFAULT_PHONE_NUMBER_FORMAT , '$1 $2 $3 $4' ) ;
21+ }
22+
323const ORG_NUMBER_FORMAT = / ^ ( \d { 3 } ) ( \d { 3 } ) ( \d { 3 } ) $ / ;
424
525/**
You can’t perform that action at this time.
0 commit comments