jquery-khmer-address-formatter
v1.0.5
Published
jQuery plugin to auto-format Cambodian address strings with Khmer spacing and digit conversion.
Maintainers
Readme
jQuery Khmer Address Formatter
A lightweight, zero-dependency jQuery plugin designed to automatically format Cambodian address strings. It intelligently converts Western Arabic numerals (
0-9) into Khmer digits (០-៩) and adds standard Khmer word spacing between administrative divisions (ភូមិ, ឃុំ, ស្រុក, ខេត្ត, etc.).
Key Features
- 🇰🇭 Khmer Digit Translation: Automatically normalizes Western numerals (
0-9) to official Khmer digits (០-៩). - 📍 Full Administrative Coverage: Supports all 25 Provinces/Autonomous Municipalities, Districts/Khan, Communes/Sangkat, Villages, and major landmark zones across Cambodia.
- ⌨️ Form Input Auto-Formatting: Rebinds input events (
blur,change,keypress) to clean up address entries dynamically. - 📄 Static Text View Support: Effortlessly formats non-input elements (
<div>,<span>,<p>,<td>) rendered from server-side templates (CodeIgniter, Laravel, WordPress). - ⚡ Performance Optimized: Uses sorted Regex boundary matching to prevent nested string collisions.
Installation
Via npm
npm install jquery-khmer-address-formatterVia CDN (jsDelivr / unpkg)
<!-- jsDelivr -->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.khmer-address-formatter.min.js"></script>
<!-- unpkg -->
<script src="https://unpkg.com/[email protected]/dist/jquery.khmer-address-formatter.min.js"></script>Quick Start
<input type="text" id="address" placeholder="ភូមិ6សង្កាត់4អូរត្រេះព្រះសីហនុ">
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="yourpath/to/jquery.khmer-address-formatter.min.js"></script>
<script>
$(document).ready(function() {
$('#address').khmerAddressFormatter({
spacing: 2,
convertNumbers: true
});
});
</script>Options
| Option | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| event | string | 'blur' | Event that triggers formatting ('blur', 'change'). |
| spacing | number | 2 | Number of spaces to insert between divisions. |
| convertNumbers | boolean | true | Automatically converts Western digits (0-9) to Khmer digits (០-៩). |
| onFormat | function | null | Callback triggered after formatting (function(formattedValue)). |
Utility Usage
You can also format address strings directly without binding to an input element:
const result = $.formatKhmerAddress('ភូមិ1ឃុំបិតត្រាំងស្រុកព្រៃនប់', 2, true);
// Output: "ភូមិ ១ ឃុំ បិតត្រាំង ស្រុក ព្រៃនប់"Developers
- Chou Chamnan – Creator & Maintainer
- GitHub: https://github.com/SmarterCoding
- npm: https://www.npmjs.com/~chamnan_dev
Made with ❤️ in Cambodia 🇰🇭
License
MIT License
