Quickstart
Getting started with @nhtio/phone-object is quick and easy. Just follow the steps below and you'll be up and running in no time.
Installation
You can install @nhtio/phone-object directly from your preferred package manager
sh
npm i @nhtio/phone-objectsh
pnpm add @nhtio/phone-objectsh
yarn add @nhtio/phone-objectUsage
Import the Phone Object
typescript
import { Phone } from '@nhtio/phone-object'Create a new Phone Object
typescript
const phone = new Phone('202-456-141', 'US')
const phone = new Phone('202-456-1414', 'US')
const phone = new Phone('(202) 456-1414', 'US')
const phone = new Phone('+1 (202) 456-1414', 'US')
const phone = new Phone('202.456.1414', 'US')
const phone = new Phone('202/4561414', 'US')
const phone = new Phone('1 202 456 1414', 'US')
const phone = new Phone('+12024561414', 'US')
const phone = new Phone('1 202-456-1414' 'US')Get the phone number in different formats
typescript
phone.raw // 2024561414
phone.national // (202) 456-1414
phone.international // +1 202-456-1414
phone.e164 // +12024561414Get the country code
typescript
phone.country // USGet a timezone suggestion
typescript
phone.timezone // America/New_YorkGet the type of line
typescript
phone.valid // true
phone.type // FIXED_LINE_OR_MOBILE
phone.mobile // trueSerialize for storage
typescript
phone.serialize() // <base64 encoded string>Deserialize from storage
typescript
const phone = Phone.deserialize(<base64 encoded string>)