Telefonnummer
Telefonnummer is phone number in Swedish. This package formats all Swedish phone numbers, both mobile and landline, to a standard format. Area code information is provided by Post- och telestyrelsen (PTS).
Installation
npm install telefonnummer --save
Parse
parsephoneNumber: string, options?: ParserOptions : stringTake a phone number and return a parsed version of the number. Parser is also default export of package, but might be removed as default in the future.
Example
parse'222' // Röstbrevlåda (Voicemail in Swedish)parse'0701234567' // 070-123 45 67parse'468123456' // 08-12 34 56parse'031626262' // 031-62 62 62parse'050012345' // 0500-123 45 // With custom separatorparse'0701234567', // 070:123 45 67 // Internationalizedparse'0701234567', // +46701234567Parser options
| Property | Type | Default | Description |
|---|---|---|---|
| separator | string | '-' | Separator between area code and phone number |
| internationalized | boolean | false | If true returns on the format +46xxxxxxxxxx |
Area code
areaCodearea: string: stringReturns the area code of the provided city
Example
areaCode'Stockholm' // 08areaCode'Korpilombolo' // 0977Numbering area
numberingAreaareaCode: string | number: stringReturns the numbering area for a provided area code or phone number. Also handles numbers without leading zero.
Example
numberingArea'0977-123 45' // KorpilombolonumberingArea'081234567' // StockholmnumberingArea'08' // StockholmnumberingArea'031' // GöteborgnumberingArea8 // StockholmValidator
validatorphoneNumber: string, options?: ValidatorOptions: booleanValidates both mobile and landline numbers.
Example
validator'0977-123 45' // truevalidator'081234567' // truevalidator'050012123456' // falsevalidator'0500123456', // falsevalidator'0701234567', // trueArea codes
areaCodes: stringReturns a number sorted array of all the area codes.
Example
areaCodes// [// '011 Norrköping',// '0120 Åtvidaberg',// '0121 Söderköping',// ....// ]Normalize
normalizestring: stringClean up any non-digits and country codes from phone number.
Example
normalize'070-123.45x67' // 0701234567normalize'+46701234567' // 0701234567AreEqual
areEqualstring, string: booleanCleans up provided strings and checks if the two phone number values match.
Example
areEqual'0701234567', '0701234567' // trueareEqual'070-123.45 67', '070123--45 67' // trueTests
npm test
Contributors
Thanks goes to these wonderful people (emoji key):
Rickard Laurin 🐛 💻 📖 👀 |
Jimmy Jardland 📖 |
|---|
This project follows the all-contributors specification. Contributions of any kind welcome!