indian-amount-parser
v1.1.0
Published
Parse Indian-currency amounts (digits or words) from free-form text across 24 languages.
Maintainers
Readme
Indian Amount Parser
Parse amounts from free-form text in 24 languages — digits, words, or mixed. Supports the Indian numbering system (lakh, crore), international currencies, and 12 native digit scripts. Pure ESM, zero dependencies, works in Node.js and browsers.
parseAmountFromText("रुपये दो लाख पचास हजार") // { amount: 250000, currency: 'INR', language: 'hi', ... }
parseAmountFromText("Rs 2 lakh") // { amount: 200000, currency: 'INR', ... }
parseAmountFromText("₹1,50,000") // { amount: 150000, currency: 'INR', ... }
parseAmountFromText("$2,500") // { amount: 2500, currency: 'USD', ... }
parseAmountFromText("ढाई लाख") // { amount: 250000, ... } (Hindi fractional)
parseAmountFromText("5K and 10L") // { amount: 1000000, ... } (abbreviations)Install
npm install indian-amount-parserBrowser (CDN)
UMD (script tag):
<script src="https://unpkg.com/indian-amount-parser/dist/indian-amount-parser.min.js"></script>
<script>
const result = IndianAmountParser.parseAmountFromText("Rs 2 lakh");
console.log(result.amount); // 200000
</script>ESM (modern browsers):
<script type="module">
import { parseAmountFromText } from "https://esm.sh/indian-amount-parser";
console.log(parseAmountFromText("पाँच लाख").amount); // 500000
</script>Quick start
import {
parseAmountFromText,
parseAllAmounts,
createCachedParser,
} from "indian-amount-parser";
// Basic parsing
parseAmountFromText("five lakh"); // { amount: 500000, language: 'en', ... }
parseAmountFromText("पाँच लाख"); // { amount: 500000, language: 'hi', currency: 'INR', ... }
parseAmountFromText("₹ 1,50,000"); // { amount: 150000, currency: 'INR', ... }
parseAmountFromText("two lakh fifty thousand"); // { amount: 250000, ... }
// International currencies
parseAmountFromText("$100"); // { amount: 100, currency: 'USD', ... }
parseAmountFromText("€50"); // { amount: 50, currency: 'EUR', ... }
parseAmountFromText("£250"); // { amount: 250, currency: 'GBP', ... }
parseAmountFromText("¥5000"); // { amount: 5000, currency: 'JPY', ... }
parseAmountFromText("200 yuan"); // { amount: 200, currency: 'CNY', ... }
// Native digits (12 scripts)
parseAmountFromText("₹५००"); // { amount: 500, ... } (Devanagari)
parseAmountFromText("৫০০ টাকা"); // { amount: 500, ... } (Bengali)
parseAmountFromText("௫௦௦"); // { amount: 500, ... } (Tamil)
// Abbreviations
parseAmountFromText("5K"); // { amount: 5000, ... }
parseAmountFromText("2.5L"); // { amount: 250000, ... }
parseAmountFromText("1.5Cr"); // { amount: 15000000, ... }
// Negative amounts
parseAmountFromText("-500"); // { amount: -500, ... }
parseAmountFromText("(500)"); // { amount: -500, ... } (accounting style)
// Hindi/Urdu fractions
parseAmountFromText("ढाई लाख"); // { amount: 250000, ... } (2.5 lakh)
parseAmountFromText("डेढ़ लाख"); // { amount: 150000, ... } (1.5 lakh)
parseAmountFromText("सवा सौ"); // { amount: 125, ... } (1.25 × 100)
// Paise subunits
parseAmountFromText("दस रुपये पचास पैसे"); // { amount: 10.5, ... }
// Multiple amounts in one string
parseAllAmounts("I paid 1000, then 2000, then 3000");
// [{ amount: 1000, ... }, { amount: 2000, ... }, { amount: 3000, ... }]
// Force a specific language
parseAmountFromText("पाँच", { language: "hi" });
// No match
parseAmountFromText("this string has no number");
// { amount: null, matched: false, ... }API
parseAmountFromText(text, options?) → Result
Parses the input text and returns the best-matching amount.
Options:
| Option | Type | Default | Description |
| ---------------- | --------- | ------- | ---------------------------------------- |
| language | string | auto | Force a specific language code. |
| filterYears | boolean | true | Drop 4-digit numbers in 1900–2099. |
| filterPhones | boolean | true | Drop 10-digit phone-shaped numbers. |
| filterIds | boolean | true | Drop #-prefixed ID numbers. |
Result:
| Field | Type | Description |
| ------------ | ------------------ | ------------------------------------------------- |
| amount | number \| null | Parsed amount, or null if nothing detected. |
| text | string | Original input text. |
| language | string \| null | Detected language code ('en', 'hi', ...). |
| currency | string \| null | Currency code ('INR', 'USD', 'EUR', etc.). |
| confidence | number | 0–1 confidence score. |
| rawTokens | string[] | Cleaned tokens used for parsing. |
| groups | Array | All candidate groups with their parsed amounts. |
| matched | boolean | true if an amount was extracted. |
parseAllAmounts(text, options?) → Result[]
Returns every candidate amount from the text (not just the largest).
normalizeText(text, dictionary?) → string
Returns the cleaned, normalized form of the input. Useful for debugging or custom pipelines.
tokenize(text, dictionary?) → string[]
Splits normalized input into tokens. Currency symbols and punctuation are stripped.
dictionaries / supportedLanguages
Direct access to all 24 dictionary objects and the array of language codes.
createCachedParser(parseFn, options?) → cachedParse
Wraps any parser function with an LRU cache.
const cachedParse = createCachedParser(parseAmountFromText, { maxSize: 500 });
cachedParse("Rs 2 lakh"); // parses
cachedParse("Rs 2 lakh"); // cached
cachedParse.size(); // 1
cachedParse.clear(); // resetSupported languages
| # | Code | Language | Script |
| -- | ----- | ----------------- | -------------- |
| 1 | en | English | Latin |
| 2 | hi | Hindi | Devanagari |
| 3 | bn | Bengali | Bengali |
| 4 | te | Telugu | Telugu |
| 5 | mr | Marathi | Devanagari |
| 6 | ta | Tamil | Tamil |
| 7 | gu | Gujarati | Gujarati |
| 8 | ur | Urdu | Perso-Arabic |
| 9 | kn | Kannada | Kannada |
| 10 | or | Odia | Odia |
| 11 | ml | Malayalam | Malayalam |
| 12 | pa | Punjabi | Gurmukhi |
| 13 | as | Assamese | Assamese |
| 14 | mai | Maithili | Devanagari |
| 15 | sa | Sanskrit | Devanagari |
| 16 | kok | Konkani | Devanagari |
| 17 | sd | Sindhi | Perso-Arabic |
| 18 | ne | Nepali | Devanagari |
| 19 | ks | Kashmiri | Perso-Arabic |
| 20 | doi | Dogri | Devanagari |
| 21 | brx | Bodo | Devanagari |
| 22 | sat | Santali | Devanagari |
| 23 | mni | Manipuri (Meitei) | Bengali |
| 24 | bho | Bhojpuri | Devanagari |
Every language includes full 0–99 number words in native script, plus multipliers for hundred, thousand, lakh, and crore.
Supported currencies
| Symbol | Code | Detection |
| ------ | ----- | ---------------------------------- |
| ₹ | INR | Symbol, Rs, or any native word |
| $ | USD | Symbol or "dollar(s)" / "usd" |
| € | EUR | Symbol or "euro(s)" / "eur" |
| £ | GBP | Symbol or "pound(s)" / "sterling" |
| ¥ | JPY | Symbol or "yen" / "jpy" |
| ¥ | CNY | "yuan" / "rmb" / "renminbi" |
INR is always checked first — Indian currency words take priority.
Indian numbering system
| Western | Indian | Value | | -------: | ---------------: | ------------: | | thousand | thousand | 1,000 | | (none) | lakh | 1,00,000 | | (none) | crore | 1,00,00,000 | | million | 10 lakh | 10,00,000 | | billion | 100 crore / arab | 1,00,00,00,000|
The parser handles lakh and crore as first-class multipliers, including composites like two lakh fifty thousand (250,000).
Testing
npm test370 tests covering normalization, dictionary validation, parsing, auto-detection, composites, currencies, and edge cases.
Build
npm run buildOutputs to dist/:
indian-amount-parser.esm.js— ESM bundleindian-amount-parser.min.js— UMD bundle (minified)indian-amount-parser.js— UMD bundle (dev)
Contributing
To add a new language:
Create
src/languages/<code>.jswith this shape:export default { numbers: { /* word → integer, 0–99 */ }, multipliers: { hundred: 100, thousand: 1000, lakh: 100000, crore: 10000000 }, connectors: [ /* 'and' equivalents */ ], currency: [ /* symbols/words */ ], subunits: { /* optional, e.g. paise: 0.01 */ }, };Register it in
src/languages/registry.js.Add tests in
test/parser.test.jsandtest/auto-detect.test.js.Run
npm test.
License
MIT — see LICENSE.
