Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including telefonnummer with all npm packages installed. Try it out:

var telefonnummer = require("telefonnummer")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

telefonnummer v0.5.2

Phone number formatter for Swedish phone numbers


npm version Build Status Code Climate Test Coverage

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).


yarn add telefonnummer


parse(phoneNumber: string, separator?: string): string

Take 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.


import { parse } from 'telefonnummer'
// OR import telefonnummer from 'telefonnummer'

parse('222') // Röstbrevlåda (Voicemail in Swedish)
parse('0701234567') // 070-123 45 67
parse('468123456') // 08-12 34 56
parse('031626262') // 031-62 62 62
parse('050012345') // 0500-123 45

// With custom separator
parse('0701234567', ':') // 070:123 45 67

Area code

areaCode(area: string): string

Returns the area code of the provided city


import { areaCode } from 'telefonnummer'

areaCode('Stockholm') // 08
areaCode('Korpilombolo') // 0977

Numbering area

numberingArea(areaCode: string | number): string

Returns the numbering area for a provided area code or phone number. Also handles numbers without leading zero.


import { numberingArea } from 'telefonnummer'

numberingArea('0977-123 45') // Korpilombolo
numberingArea('081234567') // Stockholm
numberingArea('08') // Stockholm
numberingArea('031') // Göteborg
numberingArea(8) // Stockholm


validate(phoneNumber: string): boolean

Validate both mobile and landline numbers.


import { validate } from 'telefonnummer'

validate('0977-123 45') // true
validate('081234567') // true
validate('050012123456') // false

Area codes

areaCodes(): string[]

Returns a number sorted array of all the area codes.


import { areaCodes } from 'telefonnummer'

//  [
//    '011 Norrköping',
//    '0120 Åtvidaberg',
//    '0121 Söderköping',
//    ....
//  ]


yarn test
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free