https://github.com/seavleu/khmer-utils
A ๐ฐ๐ญ utility library for number formatting, currency display, date localization, text normalization, and script transliteration, built for Cambodian developers.
https://github.com/seavleu/khmer-utils
currency-conversion date-localization khmer-language locale number-formatting text-normalization transliteration
Last synced: about 2 months ago
JSON representation
A ๐ฐ๐ญ utility library for number formatting, currency display, date localization, text normalization, and script transliteration, built for Cambodian developers.
- Host: GitHub
- URL: https://github.com/seavleu/khmer-utils
- Owner: Seavleu
- License: mit
- Created: 2025-04-04T07:30:10.000Z (about 2 months ago)
- Default Branch: main
- Last Pushed: 2025-04-04T07:50:45.000Z (about 2 months ago)
- Last Synced: 2025-04-10T23:39:55.290Z (about 2 months ago)
- Topics: currency-conversion, date-localization, khmer-language, locale, number-formatting, text-normalization, transliteration
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/khmer-utils
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Khmer Number & Currency Formatter ๐ ๐ฐ๐ญ
A lightweight utility library to help developers format numbers, currencies, and dates using **Khmer Unicode**, along with utilities for transliteration, normalization, and Khmer-specific input validation.
## ๐ฆ Installation
Install via [npm](https://www.npmjs.com/):
```bash
npm install khmer-utils
```## ๐ Features
- โ Convert Arabic numbers to Khmer numerals
- โ Format currency into Khmer Riel (`แ`) or `แแแ`
- โ Format `Date` objects using Khmer digits
- โ Normalize Khmer text (trim, reduce spaces, normalize Unicode)
- โ Transliterate Khmer script to Latin phonetics
- โ Validate Khmer phone numbers & national IDs## ๐ Usage
### 1. Importing
```js
const {
formatNumber,
formatCurrency,
formatDate,
normalizeText,
khmerToLatin,
validateMobile,
validateLandline,
validateNationalID,
} = require("khmer-utils");
```## ๐ข formatNumber
Convert Arabic numbers to Khmer numerals.
```js
formatNumber(12345); // "แกแขแฃแคแฅ"
formatNumber("123,456.78"); // "แกแขแฃ,แคแฅแฆ.แงแจ"
```## ๐ต formatCurrency
Format numbers as Khmer Riel currency.
```js
formatCurrency(12345);
// Output: "แกแข,แฃแคแฅแ"formatCurrency(12345.678, {
minimumFractionDigits: 2,
maximumFractionDigits: 2,
currencySymbol: " แแแ",
});
// Output: "แกแข,แฃแคแฅ.แฆแจ แแแ"
```## ๐ formatDate
Format JavaScript `Date` objects into `DD/MM/YYYY` using Khmer digits.
```js
formatDate(new Date(2023, 2, 15));
// Output: "แกแฅ/แฃ/แขแ แขแฃ"formatDate(new Date(2025, 0, 1), { delimiter: "-" });
// Output: "แก-แก-แขแ แขแฅ"
```## ๐งน normalizeText
Normalize Khmer or mixed-language text by:
- Removing extra spaces
- Lowercasing
- Unicode NFC normalization```js
normalizeText(" แแฝแแแแธ แแทแแแแแ ");
// Output: "แแฝแแแแธ แแทแแแแแ"
```## ๐ค khmerToLatin
Transliterate basic Khmer script to Latin characters.
```js
khmerToLatin("แแแแแ");
// Output: "kkhggng"
```## โ Validators
### validateMobile
```js
validateMobile("+855-12-3456789"); // true
validateMobile("+855-123-456789"); // false
```### validateLandline
```js
validateLandline("+855-23-123456"); // true
validateLandline("+855-23-12345"); // false
```### validateNationalID
```js
validateNationalID("1234567890"); // true
validateNationalID("123456789"); // false
```## ๐ License
MIT License
## ๐ Others
Feel free to reach out if you want to contribute or report issues!1. Fork this repo
2. Create a new branch: `git checkout -b my-change`
3. Make your changes
4. Submit a pull request## ๐ Support & Community
If you find this useful for Khmer development or localization, please โญ๏ธ the repo and share it!
Created with โค๏ธ by Seavleu Heang