UNPKG

khmer-utils

Version:

A Khmer utility library for number formatting, currency conversion, date localization, transliteration, and text normalization.

138 lines (96 loc) โ€ข 3.1 kB
# 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 <a href="https://github.com/Seavleu/khmer-utils">contribute</a> or report <a href="https://github.com/Seavleu/khmer-utils/issues">issues</a>! 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