ProjectsCase Study

verify-pak-nic

Modern Pakistani CNIC utility toolkit—offline structural validation, parse, format, mask, and test-data generators for Node and browsers.

verify-pak-nic library overview
Industry
Fintech · Identity forms · Pakistan
Category
Open-source library
Role
Author — API design, validation core, packaging, and tests
Timeline
2026
Status
Published npm-oriented library (MIT)
Stack
TypeScript · tsup · Vitest · dual ESM/CJS exports

Executive Overview

Forms across Pakistan collect CNIC numbers daily, but ad-hoc regex checks miss province digits, family-number rules, and checksum failures that erode data quality downstream.

verify-pak-nic packages those rules as a small, offline library—explicit about what it does (structural validation) and what it never claims (NADRA identity lookup).

Business Problem

Existing workflow

Teams copy brittle regex from Stack Overflow, ship slightly different rules in web and API, and silently accept typos until reconciliation fails.

Pain points

  • 13-digit rules and dash formatting differ between client and server.
  • Invalid province or checksum digits slip through naive length checks.
  • Privacy teams block server-side identity APIs for simple form validation.
  • Bundle size matters on marketing sites that only need validate + format.

Why it matters

Bad CNIC capture wastes support time and breaks KYC-style flows before they start.

Solution

One library, multiple runtimes:

  • Validate & parse

    validateCNIC, parseCNIC, and hasValidChecksum expose structured reasons—not just boolean failures.

  • Format & mask

    formatCNIC, stripCNIC, and maskCNIC keep display consistent without leaking full numbers in logs.

  • Generate test data

    generateCNIC and generateIdentity help fixtures stay structurally valid in dev and QA.

Teams share one rule set across Node, browsers, and frameworks—with no network calls and no telemetry.

Core Features

CNIC toolkit

Structural validation

Checks length, separators, province digit, family number patterns, and weighted mod-10 checksum.

NeedCatch typos before they hit your database.

ValueHigher-quality identity fields on first submit.

Parse & region metadata

parseCNIC returns province, gender, and administrative breakdown when digits are valid.

NeedDownstream UX can show human-readable region info offline.

ValueRicher forms without external APIs.

Technical Highlights

Weighted checksum core

computeChecksumDigit in src/utils/checksum.ts applies mod-10 weighting on the first 12 digits—hasValidChecksum gates full 13-digit strings.

Business valueCatches transpositions simple regex misses.

Tree-shakeable dual package

sideEffects: false with separate ESM/CJS builds via tsup and explicit export maps for browser entry points.

Business valueDrop into Next.js or Node services without bloating client bundles.

Challenges & Solutions

ChallengeSolution
Developers assumed the library performed government identity lookup—setting wrong expectations for compliance teams.README and API docs state clearly: offline structural validation only, never NADRA verification.
Province and region tables needed to stay data-driven as administrative codes evolved.Centralized province constants and parse.ts lookup paths so validation and parse stay aligned.

Tech Stack

Core
TypeScript — validate, format, parse, generators
Build
tsup — ESM + CJS + declaration files
Quality
Vitest, ESLint, CI workflow
Distribution
npm package verify-pak-nic, MIT license

Need trustworthy form validation libraries for regulated fields?

verify-pak-nic is a small OSS case study: precise rules, honest scope, and packaging that respects privacy. If you want similar libraries for your domain, start a conversation.

Start a conversation
Role

Open Source Author

Client

Community library / verify-pak-nic

Date

2026

Collaborators

Solo build

Next Project

ZNPak.ai

View next