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

digipinjs-lib

v1.1.0

Published

Official JavaScript implementation of India's DIGIPIN national geocoding standard

Readme

DIGIPIN-JS

JavaScript/TypeScript Library for India's National Geocoding Standard

Transform coordinates into precise, hierarchical digital addresses — no API required. From country-level to doorstep accuracy in milliseconds.

NPM Size TypeScript Tests License

🐍 Python Version📖 Full Documentation🐛 Issues


What is DIGIPIN?

DIGIPIN (Digital Postal Index Number) is India's national geocoding system developed by the Department of Posts, Ministry of Communications. It divides the entire country into a hierarchical grid, assigning a unique code to every ~4m × 4m location.

This JavaScript implementation provides offline geocoding with zero dependencies and full TypeScript support.


⚡ Installation

# NPM
npm install digipinjs-lib

# Yarn
yarn add digipinjs-lib

# PNPM
pnpm add digipinjs-lib

Browser CDN:

<script src="https://cdn.jsdelivr.net/npm/digipinjs-lib"></script>

🚀 Quick Start

import { encode, decode, getNeighbors, getDisk } from 'digipinjs-lib';

// Encode coordinates to DIGIPIN
const pin = encode(28.622788, 77.213033);  // '39J49LL8T4'

// Decode back to coordinates
const { lat, lon } = decode('39J49LL8T4');

// Variable precision (1-10 levels)
const cityCode = encode(28.6, 77.2, 5);    // '39J49' (~4km)
const doorCode = encode(28.6, 77.2, 10);   // '39J49LL8T4' (~4m)

// Find 8 immediate neighbors
const neighbors = getNeighbors(pin);

// Get all cells within radius
const area = getDisk(pin, 5);              // 11×11 grid (~300m)

// Validate codes
import { isValid } from 'digipinjs-lib';
isValid('39J49LL8T4');  // true

✨ Features

🎯 Core Operations

  • Encode/Decode
  • Validation
  • Variable precision (10 levels)
  • Bounding boxes
  • Parent/child codes

🗺️ Geospatial

  • Neighbor discovery
  • Radius search (disk)
  • Batch operations
  • Distance helpers
  • 8-directional navigation

👨‍💻 Developer Ready

  • TypeScript definitions
  • Zero dependencies
  • < 5KB gzipped
  • Node.js & Browser
  • React Native compatible

📖 Complete API Reference

Core Operations

// Encoding & Decoding
encode(lat, lon, precision?)           // → '39J49LL8T4'
decode(code)                           // → { lat: 28.6, lon: 77.2 }

// Validation
isValid(code, strict?)                 // → true/false
isValidCoordinate(lat, lon)            // → true/false

// Spatial Queries
getBounds(code)                        // → { minLat, maxLat, minLon, maxLon }
getParent(code, level)                 // → '39J49' (parent at level 5)

Geospatial Functions

// Neighbor Discovery
getNeighbors(code, direction?)         // → [...] (8 neighbors or filtered)
// Directions: 'all', 'cardinal', 'north', 'south', 'east', 'west',
//             'northeast', 'northwest', 'southeast', 'southwest'

// Search Areas
getDisk(code, radius?)                 // → [...] (all cells within radius)
getRing(code, radius)                  // → [...] (cells at exact radius)

// Batch Operations
batchEncode(coords, precision?)        // → [...] (encode multiple)
batchDecode(codes)                     // → [...] (decode multiple)

🎯 Real-World Examples

Store Locator

// Find nearby stores
const customerPin = encode(userLat, userLon, 8);
const searchArea = getDisk(customerPin, 5);  // ~300m radius

const nearbyStores = stores.filter(store =>
  searchArea.includes(store.digipin)
);

Delivery Zone Mapping

// Define service coverage
const warehousePin = '39J49LL8T4';
const deliveryZone = getDisk(warehousePin, 10);  // ~600m radius

// Check if address is serviceable
const customerPin = encode(customerLat, customerLon, 10);
const canDeliver = deliveryZone.includes(customerPin);

Route Optimization

// Group nearby delivery addresses
const addresses = [
  { lat: 28.6, lon: 77.2, id: 1 },
  { lat: 28.61, lon: 77.21, id: 2 }
];

// Encode all addresses
const encoded = batchEncode(
  addresses.map(a => [a.lat, a.lon]),
  8  // street-level precision
);

// Group by region (first 5 characters)
const regions = {};
encoded.forEach((code, i) => {
  const region = code.substring(0, 5);
  if (!regions[region]) regions[region] = [];
  regions[region].push(addresses[i]);
});

📊 Precision Levels

| Level | Cell Size | Resolution | Use Case | |-------|-----------|-----------|----------| | 1 | ~1000 km | Country | National analytics | | 2 | ~250 km | State | Regional planning | | 3 | ~63 km | Region | District operations | | 4 | ~16 km | District | City-wide services | | 5 | ~4 km | City | Urban zones | | 6 | ~1 km | Neighborhood | Delivery zones | | 7 | ~250 m | Area | Local services | | 8 | ~60 m | Street | Store locator | | 9 | ~15 m | Building | Building-level | | 10 | ~4 m | Doorstep | Last-mile delivery |


🌐 Platform Support

| Platform | Support | Version | |----------|---------|---------| | Node.js | ✅ Full | v10+ | | Browsers | ✅ Full | ES6+ | | TypeScript | ✅ Full | Included | | React | ✅ Compatible | Any | | React Native | ✅ Compatible | Any | | Vue.js | ✅ Compatible | Any | | Angular | ✅ Compatible | Any |


🔗 DIGIPIN Ecosystem

| Package | Environment | Version | Status | |---------|------------|---------|--------| | digipinpy | Python 3.7+ | v1.7.0 | ✅ Production | | digipinjs-lib | JavaScript/TS | v1.0.0 | ✅ Production | | digipin-django | Django ORM | Included | ✅ Available | | digipin-flask | Flask + SQLAlchemy | Included | ✅ Available | | digipin-fastapi | FastAPI | Included | ✅ Available | | digipin-pandas | Pandas | Included | ✅ Available |


✅ Testing

npm test  # 60+ tests, 100% pass rate

Test Coverage:

  • ✅ Encoding/Decoding accuracy
  • ✅ Edge cases (poles, boundaries)
  • ✅ Neighbor discovery (8 directions)
  • ✅ Search algorithms (disk, ring)
  • ✅ Batch operations
  • ✅ Validation logic

📜 License

MIT License — Free for commercial and personal use.

Based on the official DIGIPIN specification published by the Department of Posts, Ministry of Communications, Government of India.

See LICENSE file for details.


👥 Maintainers

SAMARTHA H VMR SHIVAKUMAR

📧 [email protected][email protected]


🔗 Links


Government of India • Department of Posts • National Addressing Initiative