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

@teknyo/sl_nic_validator

v1.0.0

Published

Validate Sri Lankan NIC numbers for old and new formats (JavaScript & TypeScript).

Readme

Sri Lanka NIC Validator

npm version Build Status Coverage Status License: MIT

A lightweight utility library for validating and extracting information from Sri Lankan National Identity Card (NIC) numbers - both old and new formats.


Features

✅ Format & structural validation
✅ Supports both old (10-char) and new (12-digit) NIC formats
✅ Extracts gender, birth year, birth month, birth day
✅ Returns detailed validation errors
✅ TypeScript support with clear typings
✅ Fully tested with Jest


Installation

npm install @teknyo/sl_nic_validator

NIC Formats

| Type | Format | Example | Notes | | ---- | ------------- | -------------- | ------------------------- | | Old | YYDDDNNNN(V or X) | 853456789V | 2-digit year, day of year | | New | YYYYDDDNNNNN | 199845612345 | 4-digit year, day of year |

  • DDD is day-of-year:

  • If DDD > 500, indicates a female

  • Otherwise, male

  • Final character in old NIC is V or X

Usage

import
import { validateNIC  } from '@teknyo/sl_nic_validator';

1. isSimpleValidNIC(nic: string): boolean

Validates format only.

isSimpleValidNIC('853456789V'); // true
isSimpleValidNIC('123');        // false

2. isFullValidNIC(nic: string): boolean

Validates format + logical birth values (day, year ranges).

isFullValidNIC('199845612345'); // true
isFullValidNIC('199813513456'); // false (invalid day)

3. getSimpleValidNICInfo(nic: string): NICBasicDetails

Returns basic info:

{
  nic: "853456789V",
  isValid: true,
  type: "old",
  error: ""
}

4. getFullValidNICInfo(nic: string): NICBasicDetails

Same as above but includes validation errors if invalid:

{
  nic: "123",
  isValid: false,
  type: null,
  error: "NIC format is invalid"
}

5. getFullNICDetails(nic: string): NICFullDetails

Returns all extracted metadata:

{
  nic: "853456789V",
  isValid: true,
  type: "old",
  gender: "male",
  birthYear: 1985,
  birthMonth: 12,
  birthDay: 11,
  error: undefined
}

Helper Functions

These utilities let you build custom logic using raw NIC values.

| Function | Returns | | ----------------------- | ---------------------------- | | getNICGender(nic) | 'male' / 'female' / null | | getNICBirthYear(nic) | number (e.g. 1985) / null | | getNICDayOfYear(nic) | number (1–366) / null | | getNICBirthMonth(nic) | number (1–12) / null | | getNICBirthDay(nic) | number (1–31) / null |

Validation Criteria

Both simple and full validations check for format and logical correctness.

Old NIC (Format: YYDDDNNNNV)

| Segment | Description | Example | Rules | | --------- | --------------------------------------- | --------------------- | ---------------------------------------------------------- | | YY | Last 2 digits of birth year | 85 | Interpreted as 1900 + YY | | DDD | Day of year | 001–366 / 501–866 | > 500 indicates female, subtract 500 to get actual day | | NNNN | Serial portion (not validated strictly) | 1234 | Ignored in logic validation | | V / X | Suffix | V | Must be either V or X |

New NIC (Format: YYYYDDDNNNN)

| Segment | Description | Example | Rules | | ------- | --------------- | --------------------- | ----------------------------------------- | | YYYY | Full birth year | 2000 | Must be between 1900 and current year | | DDD | Day of year | 001–366 / 501–866 | Same rule as old NIC: >500 = female | | NNNN | Serial portion | 5678 | Ignored in logic validation |

License

MIT © Teknyo.lk