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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@alwatr/iranian-national-code-validator

v1.0.16

Published

A tiny TypeScript library to Validates an Iranian National Code (Code Melli).

Downloads

568

Readme

@alwatr/iranian-national-code-validator

A tiny, zero-dependency TypeScript library to validate an Iranian National Code (Code Melli).

This package provides a single, highly-optimized function to check the validity of an Iranian National Code based on the official algorithm. It's designed to be lightweight, fast, and easy to use in any JavaScript or TypeScript project.

Why this package?

When you need to validate an Iranian National Code, you want a solution that is reliable, small, and does one thing well. This package is built to provide exactly that without adding unnecessary bloat to your project.

  • Simple & Focused: A single function isValidIranianNationalCode is all you need to learn.
  • Lightweight: Tiny footprint with zero runtime dependencies.
  • Reliable: Implements the official validation algorithm.
  • Modern: Written in TypeScript and provides both ESM and CJS modules.

Features

  • Declarative: A simple, pure function for easy integration.
  • Lightweight: Tiny footprint with zero dependencies.
  • TypeScript: Written in TypeScript with type definitions included.
  • Cross-Platform: Works in Node.js, Deno, and modern browsers.
  • Dual-Module: Supports both ESM (import) and CJS (require).

Installation

# npm
npm i @alwatr/iranian-national-code-validator

# yarn
yarn add @alwatr/iranian-national-code-validator

# pnpm
pnpm i @alwatr/iranian-national-code-validator

Usage

Import the function and pass the national code string to it. It will return true if the code is valid and false otherwise.

ES Module (ESM)

// src/main.ts
import {isValidIranianNationalCode} from '@alwatr/iranian-national-code-validator';

console.log(`'0018550152' is valid: ${isValidIranianNationalCode('0018550152')}`); // true
console.log(`'0018550153' is valid: ${isValidIranianNationalCode('0018550153')}`); // false

// It also checks for the correct format (10 digits)
console.log(`'12345' is valid: ${isValidIranianNationalCode('12345')}`); // false
console.log(`'not-a-number' is valid: ${isValidIranianNationalCode('not-a-number')}`); // false

CommonJS (CJS)

// main.js
const {isValidIranianNationalCode} = require('@alwatr/iranian-national-code-validator');

console.log(`'0018550152' is valid: ${isValidIranianNationalCode('0018550152')}`); // true
console.log(`'0018550153' is valid: ${isValidIranianNationalCode('0018550153')}`); // false

API Reference

isValidIranianNationalCode(code: string): boolean

Validates an Iranian National Code string.

The validation is based on the official algorithm:

  1. The code must be a string containing exactly 10 digits.
  2. The last digit is a check digit.
  3. A weighted sum of the first 9 digits is calculated.
  4. The remainder of the sum divided by 11 is compared with the check digit based on a specific rule.
  • code: The Iranian National Code string to validate.
  • Returns: true if the national code is valid, false otherwise.

Sponsors

The following companies, organizations, and individuals support nanolib ongoing maintenance and development. Become a Sponsor to get your logo on our README and website.

Contributing

Contributions are welcome! Please read our contribution guidelines before submitting a pull request.