uchcharan 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +91 -2
- package/bin/uchcharan.js +32 -0
- package/package.json +15 -4
- package/src/index.js +58 -0
- package/src/lang/hi.js +70 -0
- package/src/lang/mr.js +72 -0
- package/src/numbers.js +72 -0
- package/src/rules.js +162 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 DenSa
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,92 @@
|
|
|
1
|
-
#
|
|
1
|
+
# uchcharan (उच्चारण)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Make any TTS speak Indian text correctly.**
|
|
4
|
+
|
|
5
|
+
Voice agents, IVRs and audiobook tools break on Indian text: `₹2,500` comes out as "rupee two comma five hundred", `PNR 4521879630` is read as one giant number, `₹2.5 crore` loses the "ढाई". uchcharan is a small, vendor-neutral layer you put **in front of any TTS** (ElevenLabs, Sarvam, Google, Azure, Polly, open-source models) so the text is already in spoken form.
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
BEFORE: इस प्लॉट की कीमत ₹2.5 crore है, GST 18% अलग से।
|
|
9
|
+
AFTER : इस प्लॉट की कीमत ढाई करोड़ रुपये है, जी एस टी अठारह प्रतिशत अलग से।
|
|
10
|
+
|
|
11
|
+
BEFORE: तुमचा OTP 482913 आहे. तो 10 मिनिटांत वापरा.
|
|
12
|
+
AFTER : तुमचा ओ टी पी चार आठ दोन नऊ एक तीन आहे. तो दहा मिनिटांत वापरा.
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Zero dependencies. Pure rules, so it adds well under a millisecond, not a model round-trip.
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
npm install uchcharan
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Use
|
|
24
|
+
|
|
25
|
+
```js
|
|
26
|
+
import { normalize } from 'uchcharan';
|
|
27
|
+
|
|
28
|
+
normalize('आपका ₹2,500 का EMI 05/12/2026 को due है।');
|
|
29
|
+
// → 'आपका दो हज़ार पाँच सौ रुपये का ई एम आई पाँच दिसंबर दो हज़ार छब्बीस को due है।'
|
|
30
|
+
|
|
31
|
+
normalize('₹1.5 lakh पासून, दुकान 7:00 PM पर्यंत', { lang: 'mr' });
|
|
32
|
+
// → 'दीड लाख रुपये पासून, दुकान संध्याकाळी सात वाजता पर्यंत'
|
|
33
|
+
|
|
34
|
+
// See exactly what changed (useful for debugging voice agents)
|
|
35
|
+
normalize('₹500 at 10:30', { explain: true });
|
|
36
|
+
// → { text: '...', changes: [{ rule: 'currency', from: '₹500', to: 'पाँच सौ रुपये' }, ...] }
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
CLI:
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
npx uchcharan --lang mr "₹2.5 कोटी 25 Nov 2026"
|
|
43
|
+
echo "PNR 4521879630" | npx uchcharan --explain
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Options
|
|
47
|
+
|
|
48
|
+
| option | default | meaning |
|
|
49
|
+
|---|---|---|
|
|
50
|
+
| `lang` | `'hi'` | `'hi'` Hindi or `'mr'` Marathi |
|
|
51
|
+
| `spellAcronyms` | `true` | `GST` → `जी एस टी`. Known word-acronyms (`ISRO` → `इसरो`) are always spoken as words |
|
|
52
|
+
| `digitRunMin` | `6` | digit strings this long (PNR, OTP, account, PIN) are read digit by digit |
|
|
53
|
+
| `explain` | `false` | return `{ text, changes }` instead of a string |
|
|
54
|
+
|
|
55
|
+
## What it handles (v0.1)
|
|
56
|
+
|
|
57
|
+
| Input | Hindi | Marathi |
|
|
58
|
+
|---|---|---|
|
|
59
|
+
| `₹2,500` / `Rs. 2,500.50` / `₹1,50,000/-` | दो हज़ार पाँच सौ रुपये (पचास पैसे) | दोन हजार पाचशे रुपये |
|
|
60
|
+
| `₹2.5 crore`, `₹1.5 lakh`, `₹3.5 लाख` | ढाई करोड़ / डेढ़ लाख / साढ़े तीन लाख रुपये | अडीच कोटी / दीड लाख |
|
|
61
|
+
| Indian & Western commas, decimals | लाख / करोड़ system | लाख / कोटी system |
|
|
62
|
+
| `25/11/2026`, `2026-11-25`, `25 Nov 2026` | पच्चीस नवंबर दो हज़ार छब्बीस | पंचवीस नोव्हेंबर दोन हजार सव्वीस |
|
|
63
|
+
| `सन् 1998 में` / `1998 मध्ये` | उन्नीस सौ अट्ठानवे | एकोणीसशे अठ्ठ्याण्णव |
|
|
64
|
+
| `10:30`, `5:00 pm`, `14:15` | दस बजकर तीस मिनट / शाम पाँच बजे | दहा वाजून तीस मिनिटे / संध्याकाळी पाच वाजता |
|
|
65
|
+
| `+91 98765 43210` | digit by digit, with a pause in the middle | same |
|
|
66
|
+
| PNR / OTP / PIN / account numbers | digit by digit | digit by digit |
|
|
67
|
+
| `18%`, `5 km`, `-5°C`, `2+2=4` | अठारह प्रतिशत, पाँच किलोमीटर, माइनस पाँच डिग्री सेल्सियस | अठरा टक्के, ... |
|
|
68
|
+
| `10-12`, `3rd`, `10वीं` | दस से बारह, तीसरा, दसवीं | दहा ते बारा, तिसरा |
|
|
69
|
+
| `Dr.`, `Smt.`, `No. 5`, `etc.` | डॉक्टर, श्रीमती, नंबर पाँच, वगैरह | डॉक्टर, श्रीमती, नंबर पाच, वगैरे |
|
|
70
|
+
| `GST`, `EMI`, `ISRO`, `AIIMS` | जी एस टी, ई एम आई, इसरो, एम्स | जी एस टी, ई एम आय, इस्रो, एम्स |
|
|
71
|
+
| Devanagari digits `२५` | पच्चीस | पंचवीस |
|
|
72
|
+
|
|
73
|
+
## Known limits
|
|
74
|
+
|
|
75
|
+
- It does not inflect for grammar. `7:00 PM पर्यंत` becomes `सात वाजता पर्यंत`, but a native speaker would say `सात वाजेपर्यंत`.
|
|
76
|
+
- A bare 10-digit number starting with 6–9 is treated as a phone number.
|
|
77
|
+
- A bare 6+ digit number with no commas (`100000`) is read digit by digit. Write `1,00,000` for amounts.
|
|
78
|
+
- Hinglish and Romanized Hindi ("aapka order") are not transliterated yet.
|
|
79
|
+
|
|
80
|
+
## Roadmap
|
|
81
|
+
|
|
82
|
+
- [ ] Hosted HTTP API with a free tier
|
|
83
|
+
- [ ] Gujarati, Tamil, Telugu, Bengali, Kannada
|
|
84
|
+
- [ ] Custom pronunciation dictionary for brand and place names (`Nashik`, `Paithani`)
|
|
85
|
+
- [ ] Plugins for ElevenLabs, Sarvam, Bolna and LiveKit pipelines
|
|
86
|
+
- [ ] SSML output (`<say-as>` and pauses)
|
|
87
|
+
|
|
88
|
+
Contributions are welcome, especially from native speakers checking number words.
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|
package/bin/uchcharan.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { normalize } from '../src/index.js';
|
|
3
|
+
|
|
4
|
+
const args = process.argv.slice(2);
|
|
5
|
+
const opts = { lang: 'hi' };
|
|
6
|
+
const text = [];
|
|
7
|
+
for (let i = 0; i < args.length; i++) {
|
|
8
|
+
const a = args[i];
|
|
9
|
+
if (a === '--lang' || a === '-l') opts.lang = args[++i];
|
|
10
|
+
else if (a === '--explain') opts.explain = true;
|
|
11
|
+
else if (a === '--no-spell') opts.spellAcronyms = false;
|
|
12
|
+
else if (a === '--help' || a === '-h') {
|
|
13
|
+
console.log('Usage: uchcharan [--lang hi|mr] [--explain] [--no-spell] "text"\n echo "text" | uchcharan --lang mr');
|
|
14
|
+
process.exit(0);
|
|
15
|
+
} else text.push(a);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const run = (input) => {
|
|
19
|
+
const r = normalize(input, opts);
|
|
20
|
+
if (opts.explain) {
|
|
21
|
+
console.log(r.text);
|
|
22
|
+
for (const c of r.changes) console.error(` [${c.rule}] ${c.from} → ${c.to}`);
|
|
23
|
+
} else console.log(r);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
if (text.length) run(text.join(' '));
|
|
27
|
+
else {
|
|
28
|
+
let buf = '';
|
|
29
|
+
process.stdin.setEncoding('utf8');
|
|
30
|
+
process.stdin.on('data', (d) => (buf += d));
|
|
31
|
+
process.stdin.on('end', () => run(buf));
|
|
32
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uchcharan",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Make any TTS speak Indian text correctly. Normalizes ₹ amounts, lakh/crore, dates, times, phone numbers, PNR/OTP, %, units and acronyms into spoken Hindi and Marathi.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.js",
|
|
7
|
+
"exports": "./src/index.js",
|
|
8
|
+
"bin": { "uchcharan": "bin/uchcharan.js" },
|
|
9
|
+
"files": ["src", "bin", "README.md", "LICENSE"],
|
|
10
|
+
"scripts": {
|
|
11
|
+
"test": "node --test",
|
|
12
|
+
"demo": "node examples/demo.js"
|
|
13
|
+
},
|
|
14
|
+
"engines": { "node": ">=18" },
|
|
15
|
+
"keywords": ["tts", "text-normalization", "hindi", "marathi", "indic", "voice-ai", "speech", "elevenlabs", "sarvam", "ivr"],
|
|
16
|
+
"license": "MIT"
|
|
17
|
+
}
|
package/src/index.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import hi from './lang/hi.js';
|
|
2
|
+
import mr from './lang/mr.js';
|
|
3
|
+
import { buildRules } from './rules.js';
|
|
4
|
+
import { intToWords, numberStringToWords, yearToWords } from './numbers.js';
|
|
5
|
+
|
|
6
|
+
export const LANGUAGES = { hi, mr };
|
|
7
|
+
|
|
8
|
+
const DEFAULTS = { lang: 'hi', spellAcronyms: true, digitRunMin: 6, explain: false };
|
|
9
|
+
const ruleCache = new Map();
|
|
10
|
+
|
|
11
|
+
function getLang(code) {
|
|
12
|
+
const L = LANGUAGES[code];
|
|
13
|
+
if (!L) throw new Error(`uchcharan: unsupported lang "${code}". Supported: ${Object.keys(LANGUAGES).join(', ')}`);
|
|
14
|
+
return L;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Normalize text so any TTS engine speaks it correctly in Hindi or Marathi.
|
|
19
|
+
* @param {string} text
|
|
20
|
+
* @param {{lang?: 'hi'|'mr', spellAcronyms?: boolean, digitRunMin?: number, explain?: boolean}} [options]
|
|
21
|
+
* @returns {string | {text: string, changes: {rule: string, from: string, to: string}[]}}
|
|
22
|
+
*/
|
|
23
|
+
export function normalize(text, options = {}) {
|
|
24
|
+
const opts = { ...DEFAULTS, ...options };
|
|
25
|
+
const L = getLang(opts.lang);
|
|
26
|
+
const key = `${opts.lang}|${opts.spellAcronyms}|${opts.digitRunMin}`;
|
|
27
|
+
if (!ruleCache.has(key)) ruleCache.set(key, buildRules(L, opts));
|
|
28
|
+
|
|
29
|
+
// NFC + Devanagari digits (०-९) → ASCII so every rule sees one form.
|
|
30
|
+
let out = String(text ?? '').normalize('NFC').replace(/[०-९]/g, (d) => String(d.charCodeAt(0) - 0x966));
|
|
31
|
+
const changes = [];
|
|
32
|
+
|
|
33
|
+
for (const rule of ruleCache.get(key)) {
|
|
34
|
+
rule.re.lastIndex = 0;
|
|
35
|
+
out = out.replace(rule.re, (...args) => {
|
|
36
|
+
const match = args[0];
|
|
37
|
+
const hasNamed = typeof args[args.length - 1] === 'object';
|
|
38
|
+
const end = hasNamed ? -3 : -2;
|
|
39
|
+
const offset = args[args.length + end];
|
|
40
|
+
const input = args[args.length + end + 1];
|
|
41
|
+
let res = rule.fn(match, args.slice(1, end), L);
|
|
42
|
+
if (res === match) return match;
|
|
43
|
+
// Keep words apart when a number was glued to Latin text ("COVID19").
|
|
44
|
+
if (/[A-Za-z]/.test(input[offset - 1] ?? '')) res = ` ${res}`;
|
|
45
|
+
if (/[A-Za-z0-9]/.test(input[offset + match.length] ?? '')) res = `${res} `;
|
|
46
|
+
if (opts.explain) changes.push({ rule: rule.name, from: match, to: res.trim() });
|
|
47
|
+
return res;
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
out = out.replace(/[ \t]{2,}/g, ' ').replace(/ +([,.?!।])/g, '$1').trim();
|
|
52
|
+
return opts.explain ? { text: out, changes } : out;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const numberToWords = (n, lang = 'hi') => numberStringToWords(String(n), getLang(lang));
|
|
56
|
+
export const yearToSpoken = (y, lang = 'hi') => yearToWords(y, getLang(lang));
|
|
57
|
+
export { intToWords };
|
|
58
|
+
export default normalize;
|
package/src/lang/hi.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Hindi (hi) language data for uchcharan.
|
|
2
|
+
const ones = [
|
|
3
|
+
'शून्य', 'एक', 'दो', 'तीन', 'चार', 'पाँच', 'छह', 'सात', 'आठ', 'नौ',
|
|
4
|
+
'दस', 'ग्यारह', 'बारह', 'तेरह', 'चौदह', 'पंद्रह', 'सोलह', 'सत्रह', 'अठारह', 'उन्नीस',
|
|
5
|
+
'बीस', 'इक्कीस', 'बाईस', 'तेईस', 'चौबीस', 'पच्चीस', 'छब्बीस', 'सत्ताईस', 'अट्ठाईस', 'उनतीस',
|
|
6
|
+
'तीस', 'इकतीस', 'बत्तीस', 'तैंतीस', 'चौंतीस', 'पैंतीस', 'छत्तीस', 'सैंतीस', 'अड़तीस', 'उनतालीस',
|
|
7
|
+
'चालीस', 'इकतालीस', 'बयालीस', 'तैंतालीस', 'चवालीस', 'पैंतालीस', 'छियालीस', 'सैंतालीस', 'अड़तालीस', 'उनचास',
|
|
8
|
+
'पचास', 'इक्यावन', 'बावन', 'तिरपन', 'चौवन', 'पचपन', 'छप्पन', 'सत्तावन', 'अट्ठावन', 'उनसठ',
|
|
9
|
+
'साठ', 'इकसठ', 'बासठ', 'तिरसठ', 'चौंसठ', 'पैंसठ', 'छियासठ', 'सड़सठ', 'अड़सठ', 'उनहत्तर',
|
|
10
|
+
'सत्तर', 'इकहत्तर', 'बहत्तर', 'तिहत्तर', 'चौहत्तर', 'पचहत्तर', 'छिहत्तर', 'सतहत्तर', 'अठहत्तर', 'उन्यासी',
|
|
11
|
+
'अस्सी', 'इक्यासी', 'बयासी', 'तिरासी', 'चौरासी', 'पचासी', 'छियासी', 'सत्तासी', 'अट्ठासी', 'नवासी',
|
|
12
|
+
'नब्बे', 'इक्यानवे', 'बानवे', 'तिरानवे', 'चौरानवे', 'पंचानवे', 'छियानवे', 'सत्तानवे', 'अट्ठानवे', 'निन्यानवे',
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
function period(h24) {
|
|
16
|
+
if (h24 >= 4 && h24 < 12) return 'सुबह';
|
|
17
|
+
if (h24 >= 12 && h24 < 16) return 'दोपहर';
|
|
18
|
+
if (h24 >= 16 && h24 < 20) return 'शाम';
|
|
19
|
+
return 'रात';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const special = { 1: 'पहला', 2: 'दूसरा', 3: 'तीसरा', 4: 'चौथा', 6: 'छठा' };
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
code: 'hi',
|
|
26
|
+
name: 'Hindi',
|
|
27
|
+
ones,
|
|
28
|
+
zero: 'शून्य',
|
|
29
|
+
point: 'दशमलव',
|
|
30
|
+
minus: 'माइनस',
|
|
31
|
+
plus: 'प्लस',
|
|
32
|
+
times: 'गुणा',
|
|
33
|
+
equals: 'बराबर',
|
|
34
|
+
to: 'से',
|
|
35
|
+
and: 'और',
|
|
36
|
+
number: 'नंबर',
|
|
37
|
+
percent: 'प्रतिशत',
|
|
38
|
+
scales: { thousand: 'हज़ार', lakh: 'लाख', crore: 'करोड़' },
|
|
39
|
+
hundred: (h) => `${ones[h]} सौ`,
|
|
40
|
+
century: (c) => `${ones[c]} सौ`,
|
|
41
|
+
half: { 1: 'डेढ़', 2: 'ढाई', prefix: 'साढ़े' },
|
|
42
|
+
rupee: (n) => (n === 1 ? 'रुपया' : 'रुपये'),
|
|
43
|
+
paise: (n) => (n === 1 ? 'पैसा' : 'पैसे'),
|
|
44
|
+
months: ['जनवरी', 'फ़रवरी', 'मार्च', 'अप्रैल', 'मई', 'जून', 'जुलाई', 'अगस्त', 'सितंबर', 'अक्टूबर', 'नवंबर', 'दिसंबर'],
|
|
45
|
+
time(h24, m, showPeriod, words) {
|
|
46
|
+
const h12 = h24 % 12 || 12;
|
|
47
|
+
const p = showPeriod ? `${period(h24)} ` : '';
|
|
48
|
+
return m ? `${p}${words(h12)} बजकर ${words(m)} मिनट` : `${p}${words(h12)} बजे`;
|
|
49
|
+
},
|
|
50
|
+
ordinal: (n, words) => special[n] || `${words(n)}वाँ`,
|
|
51
|
+
letters: {
|
|
52
|
+
A: 'ए', B: 'बी', C: 'सी', D: 'डी', E: 'ई', F: 'एफ़', G: 'जी', H: 'एच', I: 'आई', J: 'जे', K: 'के', L: 'एल', M: 'एम',
|
|
53
|
+
N: 'एन', O: 'ओ', P: 'पी', Q: 'क्यू', R: 'आर', S: 'एस', T: 'टी', U: 'यू', V: 'वी', W: 'डब्ल्यू', X: 'एक्स', Y: 'वाई', Z: 'ज़ेड',
|
|
54
|
+
},
|
|
55
|
+
// Acronyms Indians say as a word, not letter by letter.
|
|
56
|
+
wordAcronyms: {
|
|
57
|
+
ISRO: 'इसरो', NASA: 'नासा', AIIMS: 'एम्स', NEET: 'नीट', OK: 'ओके', SEBI: 'सेबी', NABARD: 'नाबार्ड',
|
|
58
|
+
BHIM: 'भीम', COVID: 'कोविड', PIN: 'पिन', UNESCO: 'यूनेस्को', NITI: 'नीति', WiFi: 'वाईफ़ाई',
|
|
59
|
+
},
|
|
60
|
+
units: {
|
|
61
|
+
'km/h': 'किलोमीटर प्रति घंटा', kmph: 'किलोमीटर प्रति घंटा', km: 'किलोमीटर', kg: 'किलो', gm: 'ग्राम', g: 'ग्राम',
|
|
62
|
+
cm: 'सेंटीमीटर', mm: 'मिलीमीटर', ml: 'मिलीलीटर', gb: 'जीबी', mb: 'एमबी', tb: 'टीबी',
|
|
63
|
+
'°c': 'डिग्री सेल्सियस', '°f': 'डिग्री फ़ारेनहाइट',
|
|
64
|
+
},
|
|
65
|
+
abbreviations: [
|
|
66
|
+
['Dr\\.', 'डॉक्टर'], ['Mr\\.', 'मिस्टर'], ['Mrs\\.', 'मिसेज़'], ['Ms\\.', 'मिस'], ['Smt\\.', 'श्रीमती'],
|
|
67
|
+
['Prof\\.', 'प्रोफ़ेसर'], ['etc\\.', 'वगैरह'], ['vs\\.?', 'बनाम'], ['approx\\.', 'लगभग'],
|
|
68
|
+
['Ltd\\.', 'लिमिटेड'], ['Pvt\\.', 'प्राइवेट'], ['डॉ\\.', 'डॉक्टर'],
|
|
69
|
+
],
|
|
70
|
+
};
|
package/src/lang/mr.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Marathi (mr) language data for uchcharan.
|
|
2
|
+
const ones = [
|
|
3
|
+
'शून्य', 'एक', 'दोन', 'तीन', 'चार', 'पाच', 'सहा', 'सात', 'आठ', 'नऊ',
|
|
4
|
+
'दहा', 'अकरा', 'बारा', 'तेरा', 'चौदा', 'पंधरा', 'सोळा', 'सतरा', 'अठरा', 'एकोणीस',
|
|
5
|
+
'वीस', 'एकवीस', 'बावीस', 'तेवीस', 'चोवीस', 'पंचवीस', 'सव्वीस', 'सत्तावीस', 'अठ्ठावीस', 'एकोणतीस',
|
|
6
|
+
'तीस', 'एकतीस', 'बत्तीस', 'तेहेतीस', 'चौतीस', 'पस्तीस', 'छत्तीस', 'सदतीस', 'अडतीस', 'एकोणचाळीस',
|
|
7
|
+
'चाळीस', 'एक्केचाळीस', 'बेचाळीस', 'त्रेचाळीस', 'चव्वेचाळीस', 'पंचेचाळीस', 'सेहेचाळीस', 'सत्तेचाळीस', 'अठ्ठेचाळीस', 'एकोणपन्नास',
|
|
8
|
+
'पन्नास', 'एक्कावन्न', 'बावन्न', 'त्रेपन्न', 'चोपन्न', 'पंचावन्न', 'छप्पन्न', 'सत्तावन्न', 'अठ्ठावन्न', 'एकोणसाठ',
|
|
9
|
+
'साठ', 'एकसष्ट', 'बासष्ट', 'त्रेसष्ट', 'चौसष्ट', 'पासष्ट', 'सहासष्ट', 'सदुसष्ट', 'अडुसष्ट', 'एकोणसत्तर',
|
|
10
|
+
'सत्तर', 'एक्काहत्तर', 'बाहत्तर', 'त्र्याहत्तर', 'चौऱ्याहत्तर', 'पंचाहत्तर', 'शहात्तर', 'सत्याहत्तर', 'अठ्ठ्याहत्तर', 'एकोणऐंशी',
|
|
11
|
+
'ऐंशी', 'एक्याऐंशी', 'ब्याऐंशी', 'त्र्याऐंशी', 'चौऱ्याऐंशी', 'पंच्याऐंशी', 'शहाऐंशी', 'सत्त्याऐंशी', 'अठ्ठ्याऐंशी', 'एकोणनव्वद',
|
|
12
|
+
'नव्वद', 'एक्याण्णव', 'ब्याण्णव', 'त्र्याण्णव', 'चौऱ्याण्णव', 'पंच्याण्णव', 'शहाण्णव', 'सत्त्याण्णव', 'अठ्ठ्याण्णव', 'नव्व्याण्णव',
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
function period(h24) {
|
|
16
|
+
if (h24 >= 4 && h24 < 12) return 'सकाळी';
|
|
17
|
+
if (h24 >= 12 && h24 < 16) return 'दुपारी';
|
|
18
|
+
if (h24 >= 16 && h24 < 20) return 'संध्याकाळी';
|
|
19
|
+
return 'रात्री';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const special = { 1: 'पहिला', 2: 'दुसरा', 3: 'तिसरा', 4: 'चौथा', 6: 'सहावा' };
|
|
23
|
+
|
|
24
|
+
export default {
|
|
25
|
+
code: 'mr',
|
|
26
|
+
name: 'Marathi',
|
|
27
|
+
ones,
|
|
28
|
+
zero: 'शून्य',
|
|
29
|
+
point: 'पूर्णांक',
|
|
30
|
+
minus: 'मायनस',
|
|
31
|
+
plus: 'प्लस',
|
|
32
|
+
times: 'गुणिले',
|
|
33
|
+
equals: 'बरोबर',
|
|
34
|
+
to: 'ते',
|
|
35
|
+
and: 'आणि',
|
|
36
|
+
number: 'नंबर',
|
|
37
|
+
percent: 'टक्के',
|
|
38
|
+
scales: { thousand: 'हजार', lakh: 'लाख', crore: 'कोटी' },
|
|
39
|
+
// 100 alone is "शंभर"; otherwise एकशे, दोनशे, ... नऊशे.
|
|
40
|
+
hundred: (h, rest) => (h === 1 && rest === 0 ? 'शंभर' : `${ones[h]}शे`),
|
|
41
|
+
century: (c) => `${ones[c]}शे`,
|
|
42
|
+
half: { 1: 'दीड', 2: 'अडीच', prefix: 'साडे' },
|
|
43
|
+
rupee: (n) => (n === 1 ? 'रुपया' : 'रुपये'),
|
|
44
|
+
paise: (n) => (n === 1 ? 'पैसा' : 'पैसे'),
|
|
45
|
+
months: ['जानेवारी', 'फेब्रुवारी', 'मार्च', 'एप्रिल', 'मे', 'जून', 'जुलै', 'ऑगस्ट', 'सप्टेंबर', 'ऑक्टोबर', 'नोव्हेंबर', 'डिसेंबर'],
|
|
46
|
+
time(h24, m, showPeriod, words) {
|
|
47
|
+
const h12 = h24 % 12 || 12;
|
|
48
|
+
const p = showPeriod ? `${period(h24)} ` : '';
|
|
49
|
+
return m
|
|
50
|
+
? `${p}${words(h12)} वाजून ${words(m)} ${m === 1 ? 'मिनिट' : 'मिनिटे'}`
|
|
51
|
+
: `${p}${words(h12)} वाजता`;
|
|
52
|
+
},
|
|
53
|
+
ordinal: (n, words) => special[n] || `${words(n)}वा`,
|
|
54
|
+
letters: {
|
|
55
|
+
A: 'ए', B: 'बी', C: 'सी', D: 'डी', E: 'ई', F: 'एफ', G: 'जी', H: 'एच', I: 'आय', J: 'जे', K: 'के', L: 'एल', M: 'एम',
|
|
56
|
+
N: 'एन', O: 'ओ', P: 'पी', Q: 'क्यू', R: 'आर', S: 'एस', T: 'टी', U: 'यू', V: 'व्ही', W: 'डब्ल्यू', X: 'एक्स', Y: 'वाय', Z: 'झेड',
|
|
57
|
+
},
|
|
58
|
+
wordAcronyms: {
|
|
59
|
+
ISRO: 'इस्रो', NASA: 'नासा', AIIMS: 'एम्स', NEET: 'नीट', OK: 'ओके', SEBI: 'सेबी', NABARD: 'नाबार्ड',
|
|
60
|
+
BHIM: 'भीम', COVID: 'कोविड', PIN: 'पिन', UNESCO: 'युनेस्को', NITI: 'नीती', WiFi: 'वायफाय',
|
|
61
|
+
},
|
|
62
|
+
units: {
|
|
63
|
+
'km/h': 'किलोमीटर प्रति तास', kmph: 'किलोमीटर प्रति तास', km: 'किलोमीटर', kg: 'किलो', gm: 'ग्रॅम', g: 'ग्रॅम',
|
|
64
|
+
cm: 'सेंटीमीटर', mm: 'मिलिमीटर', ml: 'मिलिलिटर', gb: 'जीबी', mb: 'एमबी', tb: 'टीबी',
|
|
65
|
+
'°c': 'डिग्री सेल्सिअस', '°f': 'डिग्री फॅरनहाइट',
|
|
66
|
+
},
|
|
67
|
+
abbreviations: [
|
|
68
|
+
['Dr\\.', 'डॉक्टर'], ['Mr\\.', 'मिस्टर'], ['Mrs\\.', 'मिसेस'], ['Ms\\.', 'मिस'], ['Smt\\.', 'श्रीमती'],
|
|
69
|
+
['Prof\\.', 'प्रोफेसर'], ['etc\\.', 'वगैरे'], ['vs\\.?', 'विरुद्ध'], ['approx\\.', 'अंदाजे'],
|
|
70
|
+
['Ltd\\.', 'लिमिटेड'], ['Pvt\\.', 'प्रायव्हेट'], ['डॉ\\.', 'डॉक्टर'],
|
|
71
|
+
],
|
|
72
|
+
};
|
package/src/numbers.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// Number → words in the Indian system (हज़ार, लाख, करोड़).
|
|
2
|
+
|
|
3
|
+
function below1000(n, L) {
|
|
4
|
+
const h = Math.floor(n / 100);
|
|
5
|
+
const r = n % 100;
|
|
6
|
+
const parts = [];
|
|
7
|
+
if (h) parts.push(L.hundred(h, r));
|
|
8
|
+
if (r) parts.push(L.ones[r]);
|
|
9
|
+
return parts.join(' ');
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function positive(n, L) {
|
|
13
|
+
const parts = [];
|
|
14
|
+
if (n >= 1e7) {
|
|
15
|
+
// Indians say "एक हज़ार करोड़", not "दस अरब".
|
|
16
|
+
parts.push(positive(Math.floor(n / 1e7), L), L.scales.crore);
|
|
17
|
+
n %= 1e7;
|
|
18
|
+
}
|
|
19
|
+
const lakh = Math.floor(n / 1e5);
|
|
20
|
+
n %= 1e5;
|
|
21
|
+
const thousand = Math.floor(n / 1e3);
|
|
22
|
+
n %= 1e3;
|
|
23
|
+
if (lakh) parts.push(L.ones[lakh], L.scales.lakh);
|
|
24
|
+
if (thousand) parts.push(L.ones[thousand], L.scales.thousand);
|
|
25
|
+
if (n) parts.push(below1000(n, L));
|
|
26
|
+
return parts.join(' ');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function intToWords(n, L) {
|
|
30
|
+
n = Number(n);
|
|
31
|
+
if (!Number.isSafeInteger(n)) return digitsToWords(String(n), L);
|
|
32
|
+
if (n === 0) return L.zero;
|
|
33
|
+
if (n < 0) return `${L.minus} ${positive(-n, L)}`;
|
|
34
|
+
return positive(n, L);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function digitsToWords(str, L) {
|
|
38
|
+
return [...String(str).replace(/\D/g, '')].map((d) => L.ones[Number(d)]).join(' ');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** "2,500.75" → int words + point + each decimal digit. */
|
|
42
|
+
export function numberStringToWords(str, L) {
|
|
43
|
+
const clean = String(str).replace(/,/g, '');
|
|
44
|
+
const [int, frac] = clean.split('.');
|
|
45
|
+
if (int.length > 15) return digitsToWords(clean, L);
|
|
46
|
+
const intWords = intToWords(int, L);
|
|
47
|
+
return frac ? `${intWords} ${L.point} ${digitsToWords(frac, L)}` : intWords;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** 1998 → "उन्नीस सौ अट्ठानवे" / "एकोणीसशे अठ्ठ्याण्णव"; 2026 → normal reading. */
|
|
51
|
+
export function yearToWords(y, L) {
|
|
52
|
+
y = Number(y);
|
|
53
|
+
if (y >= 1100 && y <= 1999) {
|
|
54
|
+
const c = Math.floor(y / 100);
|
|
55
|
+
const r = y % 100;
|
|
56
|
+
return r ? `${L.century(c)} ${L.ones[r]}` : L.century(c);
|
|
57
|
+
}
|
|
58
|
+
return intToWords(y, L);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** Amounts before लाख/करोड़: 1.5 → डेढ़, 2.5 → ढाई, 3.5 → साढ़े तीन. */
|
|
62
|
+
export function amountWords(str, L) {
|
|
63
|
+
const clean = String(str).replace(/,/g, '');
|
|
64
|
+
const m = /^(\d+)\.50*$/.exec(clean);
|
|
65
|
+
if (m) {
|
|
66
|
+
const n = Number(m[1]);
|
|
67
|
+
if (n === 1) return L.half[1];
|
|
68
|
+
if (n === 2) return L.half[2];
|
|
69
|
+
if (n > 2) return `${L.half.prefix} ${intToWords(n, L)}`;
|
|
70
|
+
}
|
|
71
|
+
return numberStringToWords(clean, L);
|
|
72
|
+
}
|
package/src/rules.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// Ordered normalization rules. Order matters: specific patterns (currency,
|
|
2
|
+
// dates, phones) run before generic number reading.
|
|
3
|
+
import { intToWords, digitsToWords, numberStringToWords, yearToWords, amountWords } from './numbers.js';
|
|
4
|
+
|
|
5
|
+
// Number with Western (1,500,000) or Indian (15,00,000) commas, optional decimals.
|
|
6
|
+
const NUM = String.raw`(?:\d{1,3}(?:,\d{3})+(?!\d)|\d{1,2}(?:,\d{2})+,\d{3}(?!\d)|\d+)(?:\.\d+)?`;
|
|
7
|
+
const DEV = String.raw`ऀ-ॿ`;
|
|
8
|
+
const MONTHS = String.raw`Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|June?|July?|Aug(?:ust)?|Sep(?:t(?:ember)?)?|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?`;
|
|
9
|
+
const MONTH_KEYS = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
|
|
10
|
+
|
|
11
|
+
const MULTIPLIER = {
|
|
12
|
+
lakh: 'lakh', lakhs: 'lakh', lac: 'lakh', lacs: 'lakh', 'लाख': 'lakh',
|
|
13
|
+
crore: 'crore', crores: 'crore', cr: 'crore', ['करोड़'.normalize('NFC')]: 'crore', 'करोड': 'crore', 'कोटी': 'crore',
|
|
14
|
+
k: 'thousand', thousand: 'thousand', ['हज़ार'.normalize('NFC')]: 'thousand', 'हजार': 'thousand',
|
|
15
|
+
};
|
|
16
|
+
const MULT_RE = String.raw`lakhs?|lacs?|crores?|cr\.?|k|K|thousand|लाख|करोड़|करोड|कोटी|हज़ार|हजार`.normalize('NFC');
|
|
17
|
+
const PLAIN_MULT_RE = String.raw`lakhs?|lacs?|crores?|cr\.?|लाख|करोड़|करोड|कोटी`.normalize('NFC');
|
|
18
|
+
|
|
19
|
+
const re = (src, flags = 'gu') => new RegExp(src.normalize('NFC'), flags);
|
|
20
|
+
const multKey = (s) => MULTIPLIER[s.replace(/\.$/, '').toLowerCase()] || MULTIPLIER[s];
|
|
21
|
+
|
|
22
|
+
export function buildRules(L, opts) {
|
|
23
|
+
const words = (n) => intToWords(n, L);
|
|
24
|
+
const num = (s) => numberStringToWords(s, L);
|
|
25
|
+
const date = (d, m, y) => {
|
|
26
|
+
d = Number(d); m = Number(m);
|
|
27
|
+
if (m < 1 || m > 12 || d < 1 || d > 31) return null;
|
|
28
|
+
const parts = [words(d), L.months[m - 1]];
|
|
29
|
+
if (y) parts.push(yearToWords(String(y).length === 2 ? 2000 + Number(y) : y, L));
|
|
30
|
+
return parts.join(' ');
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
name: 'currency',
|
|
36
|
+
re: re(String.raw`(?<![A-Za-z])(?:₹|Rs\.?|INR|रु\.?|रू\.?)\s*(${NUM})(?:\s*(${MULT_RE})(?![A-Za-z${DEV}]))?(?:\s*\/-)?`),
|
|
37
|
+
fn: (m, [amount, mult]) => {
|
|
38
|
+
if (mult) return `${amountWords(amount, L)} ${L.scales[multKey(mult)]} ${L.rupee(2)}`;
|
|
39
|
+
const [int, frac] = amount.replace(/,/g, '').split('.');
|
|
40
|
+
const rupees = Number(int);
|
|
41
|
+
let out = `${words(rupees)} ${L.rupee(rupees)}`;
|
|
42
|
+
const paise = frac ? Number(frac.slice(0, 2).padEnd(2, '0')) : 0;
|
|
43
|
+
if (paise) out += ` ${words(paise)} ${L.paise(paise)}`;
|
|
44
|
+
return out;
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
...L.abbreviations.map(([pat, rep]) => ({
|
|
48
|
+
name: 'abbreviation',
|
|
49
|
+
re: re(String.raw`(?<![A-Za-z${DEV}])${pat}(?![A-Za-z])`),
|
|
50
|
+
fn: () => rep,
|
|
51
|
+
})),
|
|
52
|
+
{ name: 'number-sign', re: re(String.raw`(?<![A-Za-z])(?:No\.|#)\s*(?=\d)`), fn: () => `${L.number} ` },
|
|
53
|
+
{
|
|
54
|
+
name: 'date',
|
|
55
|
+
re: re(String.raw`(?<!\d)(\d{1,2})([\/.\-])(\d{1,2})\2(\d{4}|\d{2})(?!\d)`),
|
|
56
|
+
fn: (m, [d, , mo, y]) => date(d, mo, y) ?? m,
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
name: 'date',
|
|
60
|
+
re: re(String.raw`(?<!\d)(\d{4})-(\d{2})-(\d{2})(?!\d)`),
|
|
61
|
+
fn: (m, [y, mo, d]) => date(d, mo, y) ?? m,
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'date',
|
|
65
|
+
re: re(String.raw`(?<!\d)(\d{1,2})(?:st|nd|rd|th)?\s+(${MONTHS})\.?(?:,?\s+(\d{4}))?(?![A-Za-z])`),
|
|
66
|
+
fn: (m, [d, mon, y]) => date(d, MONTH_KEYS.indexOf(mon.slice(0, 3).toLowerCase()) + 1, y) ?? m,
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: 'date',
|
|
70
|
+
re: re(String.raw`(?<![A-Za-z])(${MONTHS})\.?\s+(\d{1,2})(?:st|nd|rd|th)?(?:,?\s+(\d{4}))?(?!\d)`),
|
|
71
|
+
fn: (m, [mon, d, y]) => date(d, MONTH_KEYS.indexOf(mon.slice(0, 3).toLowerCase()) + 1, y) ?? m,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: 'time',
|
|
75
|
+
re: re(String.raw`(?<![\d:])([01]?\d|2[0-3]):([0-5]\d)(?:\s*([AaPp])\.?\s?[Mm]\.?(?![A-Za-z]))?(?![\d:])`),
|
|
76
|
+
fn: (m, [h, min, ap]) => {
|
|
77
|
+
let h24 = Number(h);
|
|
78
|
+
if (ap) {
|
|
79
|
+
if (ap.toLowerCase() === 'p' && h24 < 12) h24 += 12;
|
|
80
|
+
if (ap.toLowerCase() === 'a' && h24 === 12) h24 = 0;
|
|
81
|
+
}
|
|
82
|
+
return L.time(h24, Number(min), Boolean(ap) || h24 > 12 || h24 === 0, words);
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
name: 'phone',
|
|
87
|
+
re: re(String.raw`(?<![\d+])(\+91[\s-]?|0)?([6-9]\d{4})[\s-]?(\d{5})(?!\d)`),
|
|
88
|
+
fn: (m, [prefix, a, b]) => {
|
|
89
|
+
let pre = '';
|
|
90
|
+
if (prefix && prefix.startsWith('+')) pre = `${L.plus} ${digitsToWords('91', L)} `;
|
|
91
|
+
else if (prefix) pre = `${L.zero} `;
|
|
92
|
+
return `${pre}${digitsToWords(a, L)}, ${digitsToWords(b, L)}`;
|
|
93
|
+
},
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
// PNR, account numbers, OTPs, PIN codes: read digit by digit.
|
|
97
|
+
name: 'digit-run',
|
|
98
|
+
re: re(String.raw`(?<!\d|\d[.,])\d{${opts.digitRunMin},}(?!\d|[.,]\d)`),
|
|
99
|
+
fn: (m) => digitsToWords(m, L),
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'year',
|
|
103
|
+
re: re(String.raw`(?<![A-Za-z${DEV}])(सन्|सन|साल|वर्ष|year|in|In)(\s+)(1[1-9]\d\d)(?![\d,.]?\d)`),
|
|
104
|
+
fn: (m, [w, sp, y]) => `${w}${sp}${yearToWords(y, L)}`,
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'year',
|
|
108
|
+
re: re(String.raw`(?<![\d.,])(1[1-9]\d\d)(?=\s+(?:में|साल|साली|मध्ये)(?![${DEV}]))`),
|
|
109
|
+
fn: (m, [y]) => yearToWords(y, L),
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'negative',
|
|
113
|
+
re: re(String.raw`(?<![\w\d${DEV}])-(?=\d)`),
|
|
114
|
+
fn: () => `${L.minus} `,
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'percent',
|
|
118
|
+
re: re(String.raw`(?<![\d.])(${NUM})\s*%`),
|
|
119
|
+
fn: (m, [n]) => `${num(n)} ${L.percent}`,
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: 'unit',
|
|
123
|
+
re: re(String.raw`(?<![\d.])(${NUM})\s*(km\/h|kmph|km|Km|KM|kg|Kg|KG|gm|g|cm|mm|ml|mL|GB|MB|TB|°C|°F)(?![A-Za-z])`),
|
|
124
|
+
fn: (m, [n, u]) => `${num(n)} ${L.units[u.toLowerCase()]}`,
|
|
125
|
+
},
|
|
126
|
+
{
|
|
127
|
+
name: 'multiplier',
|
|
128
|
+
re: re(String.raw`(?<![\d.])(${NUM})\s*(${PLAIN_MULT_RE})(?![A-Za-z${DEV}])`),
|
|
129
|
+
fn: (m, [n, mult]) => `${amountWords(n, L)} ${L.scales[multKey(mult)]}`,
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
name: 'ordinal',
|
|
133
|
+
re: re(String.raw`(?<![\d.])(\d+)(st|nd|rd|th)(?![A-Za-z])`),
|
|
134
|
+
fn: (m, [n]) => L.ordinal(Number(n), words),
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: 'operator',
|
|
138
|
+
re: re(String.raw`(?<=\d)\s*([+×=])\s*(?=\d)`),
|
|
139
|
+
fn: (m, [op]) => ` ${{ '+': L.plus, '×': L.times, '=': L.equals }[op]} `,
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
name: 'range',
|
|
143
|
+
re: re(String.raw`(?<![\d.])(${NUM})\s*[-–]\s*(${NUM})(?!\d)`),
|
|
144
|
+
fn: (m, [a, b]) => `${num(a)} ${L.to} ${num(b)}`,
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
name: 'number',
|
|
148
|
+
re: re(String.raw`(?<![\d.])(${NUM})`),
|
|
149
|
+
fn: (m, [n]) => num(n),
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
name: 'acronym',
|
|
153
|
+
re: re(String.raw`(?<![A-Za-z])([A-Z]{2,6}|WiFi)(?![A-Za-z])`),
|
|
154
|
+
fn: (m) => {
|
|
155
|
+
if (L.wordAcronyms[m]) return L.wordAcronyms[m];
|
|
156
|
+
if (!opts.spellAcronyms) return m;
|
|
157
|
+
return [...m].map((c) => L.letters[c] ?? c).join(' ');
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
{ name: 'symbol', re: re(String.raw`\s&\s`), fn: () => ` ${L.and} ` },
|
|
161
|
+
];
|
|
162
|
+
}
|