india-formatter: A Lightweight JavaScript Toolkit for Indian Developers 🇮🇳
🇮🇳 india-formatter: A Lightweight JavaScript Toolkit for Indian Developers
Working with Indian financial data in JavaScript applications often means handling different formatting conventions and validation requirements.
For example:
- Formatting ₹12,34,567 instead of 1,234,567.
- Converting monetary amounts into Indian English words.
- Formatting amounts in Lakhs and Crores.
- Validating PAN and GSTIN formats.
- Handling Indian mobile number formats.
Developers often end up implementing these utilities separately across projects.
india-formatter brings these commonly needed Indian-specific utilities together in one lightweight, zero-dependency JavaScript and TypeScript package.
🚀 Introducing india-formatter
india-formatter is designed to make Indian number formatting, INR currency conversion, and common Indian data validations easier to integrate into modern applications.
The package supports:
- Node.js
- React
- Next.js
- Browser applications
- Edge runtimes
- Cloudflare Workers
It also provides ESM and CommonJS builds with TypeScript definitions.
✨ Features at a glance
| Feature | Description |
|---|---|
| INR Formatting | Indian currency grouping |
| Compact Currency | K, Lakh and Crore notation |
| Number to Words | Indian English currency words |
| Number Formatting | Indian comma separation |
| PAN Validation | PAN format validation |
| GSTIN Validation | GSTIN structure validation |
| Phone Validation | Indian mobile number validation |
| Zero Dependencies | No runtime dependencies |
The package targets a gzipped bundle size below 3 KB.
📦 Installation
Install the package using npm:
npm install india-formatter Other package managers are supported too:
yarn add india-formatter pnpm add india-formatter 💰 1. Indian Currency Formatting
One of the main features is formatting currency according to the Indian numbering system.
import { formatINR } from 'india-formatter'; formatINR(1234567.89); // ₹12,34,567.89 formatINR(150000, { decimals: 0 }); // ₹1,50,000 formatINR(500, { showSymbol: false }); // 500.00 formatINR(150000, { symbol: 'Rs. ' }); // Rs. 1,50,000.00 Compact Currency Formatting
For dashboards, reports, and analytics interfaces, compact currency notation can be useful.
import { formatINRCompact } from 'india-formatter'; formatINRCompact(1500); // ₹1.5 K formatINRCompact(1500000); // ₹15 Lakh formatINRCompact(25000000); // ₹2.5 Crore 🗣️ 2. Convert Numbers into Indian English Words
Converting monetary values into words is useful when generating invoices, receipts, and financial documents.
import { toWordsINR } from 'india-formatter'; toWordsINR(125000); // One Lakh Twenty Five Thousand Rupees Only toWordsINR(10500.50); // Ten Thousand Five Hundred Rupees and Fifty Paise Only toWordsINR(0); // Zero Rupees Only You can also customize the output:
toWordsINR(500, { showOnly: false }); // Five Hundred Rupees 🔢 3. Indian Number Formatting
Indian and international number grouping conventions are different.
import { formatIndianNumber } from 'india-formatter'; formatIndianNumber(1234567); // 12,34,567 formatIndianNumber(1234567.89); // 12,34,567.89 formatIndianNumber(1234567, 2); // 12,34,567.00 🛡️ 4. PAN Validation
The package provides PAN format validation, including an optional strict mode for checking the fourth-character category.
import { isValidPAN } from 'india-formatter'; isValidPAN('ABCDE1234F'); // true isValidPAN('12345ABCDE'); // false isValidPAN('ABCPE1234F', { strict: true }); // true 🧾 5. GSTIN Validation
Validate the structure of a 15-character GSTIN.
import { isValidGSTIN } from 'india-formatter'; isValidGSTIN('27ABCDE1234F1Z5'); // true isValidGSTIN('invalid-gst'); // false 📱 6. Indian Mobile Number Validation
Indian mobile numbers can arrive in different formats, such as with country codes, prefixes, and separators.
import { isValidIndianPhone } from 'india-formatter'; isValidIndianPhone('9876543210'); // true isValidIndianPhone('+91 98765 43210'); // true isValidIndianPhone('+919876543210'); // true isValidIndianPhone('09876543210'); // true isValidIndianPhone('1234567890'); // false Important: These validators check formatting and structural rules. They do not establish the authenticity of government records or verify whether a phone number is active.
🌐 Built for Modern JavaScript Applications
The package provides:
- Dual ESM and CommonJS support.
- Full TypeScript definitions.
- Native JavaScript and TypeScript implementation.
- Zero runtime dependencies.
- Support for browser and server-side environments.
This makes it suitable for applications built with Node.js, React, Next.js, and supported edge runtimes.
🧪 Development
Developers interested in exploring or contributing to the package can get started with:
# Clone the repository git clone https://github.com/rahman4ktr/india-formatter.git # Enter the project cd india-formatter # Install dependencies npm install # Run tests npm test # Build the package npm run build 💡 Why Indian-Specific Utilities Matter
JavaScript provides many general-purpose formatting and validation capabilities, but application developers still need to account for country-specific conventions.
Indian currency grouping, Lakhs and Crores, monetary amounts in words, and common identification-number formats are everyday requirements in many Indian applications.
Having these utilities in one reusable package can reduce repeated implementation and make application code easier to maintain.
🔗 Explore the Project
Want to see it in action or explore the source code?
- GitHub Repository: https://github.com/rahman4ktr/india-formatter
- Live Playground: https://india-formatter.rexvel.com/
- npm Package: https://www.npmjs.com/package/india-formatter
🤝 Open Source & Community
The project is maintained by M. Rahman.
Developers are welcome to explore the implementation, try the package, share feedback, and contribute improvements through the GitHub repository.
If you work with Indian financial data or build applications for Indian users, give india-formatter a try.
Happy coding! 🚀
india-formatter — Indian formatting utilities for modern JavaScript and TypeScript applications.