indian-railway-station-codes
v1.0.1
Published
High-performance, zero-dependency bi-directional Indian Railway station code searching library
Downloads
305
Maintainers
Readme
indian-railway-station-codes
A high-performance, zero-dependency, and strictly functional TypeScript library for bi-directional Indian Railway station code searching (Name ↔ Code).
Contains 13,220 unique stations extracted directly from the official Indian Railways database (rct.indianrail.gov.in), completely frozen and optimized for fast O(1) matching.
Features
- 🚀 Zero Dependencies: Pure code with no runtime overhead.
- ⚡ O(1) Performance: Uses pre-computed frozen Maps for exact code/name lookups.
- 🔍 Substring Search: Supports case-insensitive substring matching for names and codes.
- 🧊 Immutability: All returned structures and internal databases are deeply frozen (
Object.freeze). - 📦 Dual Bundle: Ships with both ESM (
import) and CommonJS (require) builds out of the box. - 🛡️ Fully Typed: Written natively in TypeScript.
Installation
npm install indian-railway-station-codesQuick Start
ESM / TypeScript
import {
getStationByCode,
getStationByName,
searchStations
} from "indian-railway-station-codes";
// Exact Lookup by Code (O(1) - Case Insensitive)
const kalyan = getStationByCode("KYN");
// => { name: "KALYAN JN.", code: "KYN" }
// Exact Lookup by Name (O(1) - Case Insensitive)
const ndls = getStationByName("NEW DELHI");
// => { name: "NEW DELHI", code: "NDLS" }
// Substring Search on both name and code (Case Insensitive)
const results = searchStations("delhi");
// => [
// { name: "DELHI", code: "DLI" },
// { name: "NEW DELHI", code: "NDLS" },
// ...
// ]CommonJS (Node.js)
const { getStationByCode, searchStations } = require("indian-railway-station-codes");
console.log(getStationByCode("KYN"));
// => { name: "KALYAN JN.", code: "KYN" }API Reference
getStationByCode(code: string): Station | undefined
Performs an exact, case-insensitive O(1) map lookup. Returns the matching station object or undefined.
getStationByName(name: string): Station | undefined
Performs an exact, case-insensitive O(1) map lookup. Returns the matching station object or undefined.
searchStations(query: string): readonly Station[]
Performs a case-insensitive substring search matching both station codes and names. Returns a frozen array of matches.
searchByCode(codeQuery: string): readonly Station[]
Performs a case-insensitive substring search matching only station codes. Returns a frozen array of matches.
searchByName(nameQuery: string): readonly Station[]
Performs a case-insensitive substring search matching only station names. Returns a frozen array of matches.
stations: readonly Station[]
The raw frozen database containing all 13,220+ stations.
Data Update & Build
The library includes an auto-ingestion pipeline script to pull the latest listings from the official server and compile them into static code assets.
# Ingest data & compile CJS/ESM/DTS targets
npm run build
# Run unit tests
npm run testLicense
MIT
