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 🙏

© 2026 – Pkg Stats / Ryan Hefner

phone-validator-lk

v1.0.0

Published

A lightweight Node.js library to validate, detect type, and normalize Sri Lankan mobile and landline phone numbers. Supports various input formats and standardizes them to international format (+94).

Readme

phone-validator-lk

A lightweight and robust Node.js library for validating and normalizing Sri Lankan phone numbers.

npm version License: MIT

Features

  • Validates both mobile and landline Sri Lankan phone numbers
  • Normalizes numbers to the international format (+94XXXXXXXXX)
  • Identifies phone number types (mobile or landline)
  • Accepts multiple input formats
  • Zero dependencies
  • Compatible with Node.js v14+
  • Available as both CommonJS and ESM

Installation

npm install phone-validator-lk

or

yarn add phone-validator-lk

Usage

CommonJS

const { validatePhone, normalizePhone, getPhoneType } = require('phone-validator-lk');

ES Modules

import { validatePhone, normalizePhone, getPhoneType } from 'phone-validator-lk';

API

validatePhone(number)

Validates a phone number and returns an object with validation results.

Parameters:

  • number (string): The phone number to validate

Returns:

An object with the following properties:

  • isValid (boolean): Whether the number is a valid Sri Lankan phone number
  • normalized (string|null): The normalized number in international format, or null if invalid
  • type (string|null): 'mobile', 'landline', or null if invalid
  • original (string): The original input

Example:

validatePhone('0712345678');
// {
//   isValid: true, 
//   normalized: '+94712345678', 
//   type: 'mobile', 
//   original: '0712345678'
// }

validatePhone('071-234-5678');
// {
//   isValid: true, 
//   normalized: '+94712345678', 
//   type: 'mobile', 
//   original: '071-234-5678'
// }

validatePhone('0712345');
// {
//   isValid: false, 
//   normalized: null, 
//   type: null, 
//   original: '0712345'
// }

normalizePhone(number)

Normalizes a phone number to international format.

Parameters:

  • number (string): The phone number to normalize

Returns:

  • (string|null): The normalized number or null if the number is invalid

Example:

normalizePhone('0712345678'); // '+94712345678'
normalizePhone('071-234-5678'); // '+94712345678'
normalizePhone('invalid'); // null

getPhoneType(number)

Determines the type of phone number.

Parameters:

  • number (string): The phone number to check

Returns:

  • (string|null): 'mobile', 'landline', or null if invalid

Example:

getPhoneType('0712345678'); // 'mobile'
getPhoneType('0112345678'); // 'landline'
getPhoneType('invalid'); // null

Supported Formats

The library accepts the following phone number formats:

Mobile Numbers

Mobile numbers in Sri Lanka have the format 07X-XXX-XXXX where X is a digit. The package supports the following prefixes: 70, 71, 72, 74, 75, 76, 77, 78.

Examples of valid mobile number formats:

  • +94712345678
  • 0712345678
  • 94712345678
  • 071-234-5678
  • 071 234 5678
  • And more...

Landline Numbers

Landline numbers in Sri Lanka have the format 0XX-XXX-XXXX where XX is the area code.

Examples of valid landline number formats:

  • +94112345678
  • 0112345678
  • 94112345678
  • 011-234-5678
  • 011 234 5678
  • And more...

License

MIT