npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

telefonnummer

v2.1.0

Published

Phone number formatter for Swedish phone numbers

Downloads

231

Readme

Telefonnummer

npm version Build Status Code Climate Test Coverage Known Vulnerabilities

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

parse(phoneNumber: string, options?: ParserOptions ): 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.

Example

import { parse } 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', { separator: ':' }) // 070:123 45 67

// Internationalized
parse('0701234567', { internationalized: true }) // +46701234567

Parser 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

areaCode(area: string): string

Returns the area code of the provided city

Example

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.

Example

import { numberingArea } from 'telefonnummer'

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

Validator

interface ValidatorOptions {
  onlyMobile?: boolean
}

validator(phoneNumber: string, options?: ValidatorOptions): boolean

Validates both mobile and landline numbers.

Example

import { validator } from 'telefonnummer'

validator('0977-123 45') // true
validator('081234567') // true
validator('050012123456') // false
validator('0500123456', { onlyMobile: true }) // false
validator('0701234567', { onlyMobile: true }) // true

Area codes

areaCodes(): string[]

Returns a number sorted array of all the area codes.

Example

import { areaCodes } from 'telefonnummer'

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

Normalize

normalize(string): string

Clean up any non-digits and country codes from phone number.

Example

import { normalize } from 'telefonnummer'

normalize('070-123.45x67') // 0701234567
normalize('+46701234567') // 0701234567

AreEqual

areEqual(string, string): boolean

Cleans up provided strings and checks if the two phone number values match.

Example

import { areEqual } from 'telefonnummer'

areEqual('0701234567', '0701234567') // true
areEqual('070-123.45 67', '070123--45 67') // true

Tests

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!