arabic-ntl
v1.0.0
Published
Convert numbers to Arabic words with gender awareness support.
Readme
Arabic NTL (Number to Letters)
Convert numbers to Arabic words with gender awareness support.
Installation
npm install arabic-ntlUsage
ES6 Import
import { ntl, ArabicNTL } from 'arabic-ntl';
// Using singleton instance
const result = ntl.number(123).counted("كتاب").toWords();
// Output: "مئة و ثلاثة و عشرون كتاب"
// Using static method
const result2 = ArabicNTL.convert(456, "طالبة");
// Output: "أربع مئة و ستة و خمسون طالبة"CommonJS
const { ntl, ArabicNTL } = require('arabic-ntl');
// Convert without counted item
const result = ntl.number(789).toWords();
// Output: "سبع مئة و تسعة و ثمانون"Browser
<script src="node_modules/arabic-ntl/index.js"></script>
<script>
const result = ntl.number(1000).counted("دينار").toWords();
// Output: "ألف دينار"
</script>API
Chained API
ntl.number(num).counted(item).toWords()number(num): Set the number to convertcounted(item): Set the counted item (المعدود) - optionaltoWords(): Convert to Arabic words
Static Method
ArabicNTL.convert(num, counted)num: The number to convertcounted: The counted item (optional)
Create New Instance
const converter = new ArabicNTL();
converter.number(2500).toWords();
// Output: "ألفان و خمس مئة"Features
- ✅ Gender awareness (masculine/feminine)
- ✅ Support for numbers up to trillions
- ✅ Proper Arabic grammar rules
- ✅ Zero configuration
- ✅ Lightweight
- ✅ No dependencies
Examples
// Masculine
ArabicNTL.convert(3, "كتاب") // "ثلاثة كتاب"
ArabicNTL.convert(13, "قلم") // "ثلاثة عشر قلم"
ArabicNTL.convert(2000, "ريال") // "ألفان ريال"
// Feminine
ArabicNTL.convert(3, "طالبة") // "ثلاث طالبة"
ArabicNTL.convert(13, "ورقة") // "ثلاث عشرة ورقة"
ArabicNTL.convert(2000, "ليرة") // "ألفان ليرة"
// Without counted item
ArabicNTL.convert(0) // "صفر"
ArabicNTL.convert(100) // "مئة"
ArabicNTL.convert(1000000) // "مليون"License
MIT
