├── package.json ├── README.md ├── LICENSE └── index.js /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "myanmar-nrc-tool", 3 | "version": "0.2.2", 4 | "description": "Myanmar NRC assert tool, used unicode", 5 | "main": "index.js", 6 | "repository": { 7 | "type": "git", 8 | "url": "git+https://github.com/greenlikeorange/NRCPrefix.git" 9 | }, 10 | "keywords": [ 11 | "Myanmar", 12 | "NRC", 13 | "Myanmar", 14 | "national", 15 | "registration", 16 | "card" 17 | ], 18 | "author": "greenlikeorange ", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/greenlikeorange/NRCPrefix/issues" 22 | }, 23 | "homepage": "https://github.com/greenlikeorange/NRCPrefix#readme" 24 | } 25 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | NRCPrefix 2 | ========= 3 | 4 | Prefixer for Myanmar National Registration Card's Format 5 | 6 | ## Match Formats 7 | 8 | `[State Number]\[District]([NAING/N])[Register No]` 9 | 10 | - `12/OKM(N)123456` 11 | - `12/OUKAMA(N)123456` 12 | - `12/OKM(NAING)123456` 13 | 14 | Prefer formats 15 | - `12/OUKAMA(N)123456` 16 | - `12/OUKAMA(NAING)123456` 17 | - `၁၂/ဥကမ(နိုင်)၁၂၃၄၅၆` 18 | 19 | *NOTE* 20 | 21 | Three english characters in district are not complete format and will not support some function. 22 | So you should be use six english characters for district. 23 | 24 | ## Usage 25 | ### Get format 26 | 27 | ```js 28 | var nrc = MMNRC("12/OuKaMa (NAING) 123456"); 29 | 30 | nrc.getFormat() // 12/OUKAMA(N)123456 31 | nrc.getFormat("mm") // ၁၂/ဉကမ(နိုင်)၁၂၃၄၅၆ 32 | ``` 33 | 34 | ### Test Equal 35 | 36 | ```js 37 | var nrc = MMNRC("12/OUKAMA (N) 123456"); 38 | 39 | nrc.isEqual('၁၂/ဥကမ(နိုင်)၁၂၃၄၅၆') // return true; 40 | ``` 41 | 42 | ### Get State name from nrc card 43 | 44 | ```js 45 | var nrc = MMNRC("14/PaPaNa(N)123456"); 46 | 47 | nrc.getState("mm") //ဧရာဝတီတိုင်း 48 | nrc.getState() // Ayeyarwaddy 49 | ``` 50 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 GreenLikeOrange 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. 22 | 23 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Myanmar National Registration Card Format Prefix 3 | * 4 | * Version: 0.1.0 (beta) 5 | * Language: JavaScript 6 | * 7 | * [State Number]\[District]([NAING])[Register No] 8 | * 9 | */ 10 | 11 | var MM_NUM = "\u1040-\u1049"; 12 | var MM_NUM_CHARS = "\u1040\u1041\u1042\u1043\u1044\u1045\u1046\u1047\u1048\u1040"; 13 | var mmChar = "\u1000\u1001\u1002\u1003\u1004\u1005\u1006\u1007\u1008\u100A\u100E\u100F\u1010\u1011\u1012\u1013\u1014\u1015\u1016\u1017\u1018\u1019\u101A\u101B\u101C\u101D\u101E\u101F\u1020\u1025\u1027"; 14 | var NAING_MM = "\u1014\u102D\u102F\u1004\u103A"; 15 | var regx_eng = /^([\d]{1,2})\/([\w]{3}|[\w]{6})\(?:N|NAING\)([\d]{6})$/; 16 | var regx_mm = new RegExp("^(["+MM_NUM+"]{1,2})\/(["+mmChar+"]{3}|["+mmChar+"]{6})\((?:"+NAING_MM+")\)(["+MM_NUM+"]{6})$"); 17 | 18 | var states = [ 19 | {en:"Kachin", mm:"\u1000\u1001\u103B\u1004\u103A\u1015\u103C\u100A\u103A\u1014\u101A\u103A"}, 20 | {en:"Kayah", mm:"\u1000\u101A\u102C\u1038\u1015\u103C\u100A\u103A\u1014\u101A\u103A"}, 21 | {en:"Kayin", mm:"\u1000\u101B\u1004\u103A\u1015\u103C\u100A\u103A\u1014\u101A\u103A"}, 22 | {en:"Chin", mm:"\u1001\u103B\u1004\u103A\u1038\u1015\u103C\u100A\u103A\u1014\u101A\u103A"}, 23 | {en:"Sagaing", mm:"\u1005\u1005\u103A\u1000\u102D\u102F\u1004\u103A\u1038\u1010\u102D\u102F\u1004\u103A\u1038"}, 24 | {en:"Tanintharyi", mm:"\u1010\u1014\u1004\u103A\u1039\u101E\u102C\u101B\u102E\u1010\u102D\u102F\u1004\u103A\u1038"}, 25 | {en:"Bago", mm:"\u1015\u1032\u1001\u1030\u1038\u1010\u102D\u102F\u1004\u103A\u1038"}, 26 | {en:"Magway", mm:"\u1019\u1000\u103D\u1031\u1038\u1010\u102D\u102F\u1004\u103A\u1038"}, 27 | {en:"Mandalay", mm:"\u1019\u1014\u1039\u1010\u101C\u1031\u1038\u1010\u102D\u102F\u1004\u103A\u1038"}, 28 | {en:"Mon", mm:"\u1019\u103D\u1014\u103A\u1015\u103C\u100A\u103A\u1014\u101A\u103A"}, 29 | {en:"Rakhine", mm:"\u101B\u1001\u102D\u102F\u1004\u103A\u1015\u103C\u100A\u103A\u1014\u101A\u103A"}, 30 | {en:"Yangon", mm:"\u101B\u1014\u103A\u1000\u102F\u1014\u103A\u1010\u102D\u102F\u1004\u103A\u1038"}, 31 | {en:"Shan", mm:"\u101B\u103E\u1019\u103A\u1038\u1015\u103C\u100A\u103A\u1014\u101A\u103A"}, 32 | {en:"Ayeyarwaddy", mm:"\u1027\u101B\u102C\u101D\u1010\u102E\u1010\u102D\u102F\u1004\u103A\u1038"} 33 | ]; 34 | 35 | // ref: http://en.wiktionary.org/wiki/Appendix:Unicode/Myanmar 36 | var CHARACTERS = { 37 | // MM -> ENG 38 | "\u1000": "KA", 39 | "\u1001": "KH", 40 | "\u1002": "GA", 41 | "\u1003": "GH", 42 | "\u1004": "NG", 43 | "\u1005": "CA", 44 | "\u1006": "CH", 45 | "\u1007": "JA", 46 | "\u1008": "JH", 47 | // TODO: NNYA 48 | "\u100A": "NY", 49 | "\u100E": "DD", 50 | // TODO: NNA 51 | "\u100F": "NN", 52 | "\u1010": "TA", 53 | "\u1011": "TH", 54 | "\u1012": "DA", 55 | "\u1013": "DH", 56 | "\u1014": "NA", 57 | "\u1015": "PA", 58 | "\u1016": "PH", 59 | "\u1017": "BA", 60 | "\u1018": "BH", 61 | "\u1019": "MA", 62 | "\u101A": "YA", 63 | "\u101B": "RA", 64 | "\u101C": "LA", 65 | "\u101D": "WA", 66 | "\u101E": "SA", 67 | "\u101F": "HA", 68 | "\u1020": "LL", 69 | "\u1025": "U", 70 | "\u1027": "E", 71 | // ENG -> MM 72 | "KA": "\u1000", 73 | "KH": "\u1001", 74 | "GA": "\u1002", 75 | "GH": "\u1003", 76 | "NG": "\u1004", 77 | "CA": "\u1005", 78 | "CH": "\u1006", 79 | "JA": "\u1007", 80 | "JH": "\u1008", 81 | "NY": "\u100A", 82 | "DD": "\u100E", 83 | "NN": "\u100F", 84 | "TA": "\u1010", 85 | "TH": "\u1011", 86 | "DA": "\u1012", 87 | "DH": "\u1013", 88 | "NA": "\u1014", 89 | "PA": "\u1015", 90 | "PH": "\u1016", 91 | "BA": "\u1017", 92 | "BH": "\u1018", 93 | "MA": "\u1019", 94 | "YA": "\u101A", 95 | "RA": "\u101B", 96 | "LA": "\u101C", 97 | "WA": "\u101D", 98 | "SA": "\u101E", 99 | "HA": "\u101F", 100 | "LL": "\u1020", 101 | "OU": "\u1025", 102 | "AE": "\u1027" 103 | }; 104 | 105 | /** 106 | * Constructor 107 | * {String} NRC String 108 | */ 109 | var MMNRC = function(nrc){ 110 | nrc = nrc.trim(); 111 | nrc = nrc.replace(/\s/g, ""); 112 | return new this.prototype.init(nrc); 113 | }; 114 | 115 | MMNRC.prototype = { 116 | inti: function(nrc){ 117 | if((this.match = regx_eng.exec(nrc))){ 118 | this.lang = "en"; 119 | this.state = this.match[1]; 120 | this.dist = parseInt(this.match[2], 10); 121 | this.num = parseInt(this.match[3], 10); 122 | // 3 Characters Districts are not compete and can"t be generate Full Format 123 | if(this.dist.length === 3) 124 | this.inCompleteInfo = true; 125 | return this; 126 | } else if ((this.match = regx_mm.exec(nrc))){ 127 | this.lang = "mm"; 128 | this.state = MMNRC.toEngNum(this.match[1], 10); 129 | this.dist = MMNRC.convDistrict(this.match[2], 10); 130 | this.num = MMNRC.toEngNum(this.match[3], 10); 131 | return this; 132 | } 133 | // Return for error 134 | throw new Error("Type Not Match!"); 135 | }, 136 | 137 | isEqual: function(nrc){ 138 | return MMNRC.formatConvert(nrc).fullcode === this.getFormat(); 139 | } 140 | }; 141 | 142 | MMNRC.prototype.init.prototype = MMNRC.prototype; 143 | 144 | /** 145 | * Get Default Format 146 | */ 147 | MMNRC.prototype.getFormat = function (lang){ 148 | if(lang && lang === "mm" && !this.inCompleteInfo) { 149 | MMNRC.toMyaNum(this.state) + "/" + MMNRC.convDistrict(this.dist) + "("+NAING_MM+")" + MMNRC.toMyaNum(this.num); 150 | } else { 151 | this.state + "/" + this.dist + "(N)" + this.num; 152 | } 153 | }; 154 | 155 | /** 156 | * Get State 157 | */ 158 | 159 | MMNRC.prototype.getState= function (lang) { 160 | if (lang === "mm") { 161 | return states[this.dist].mm; 162 | } else { 163 | return states[this.dist].en; 164 | } 165 | }; 166 | 167 | /** 168 | * Convert Myanmar Number type to English 169 | */ 170 | MMNRC.toEngNum = function(MM_NUM){ 171 | var _res = ""; 172 | for (var i = 0; i < MM_NUM.length; i++) { 173 | _res += MM_NUM_CHARS.indexOf(MM_NUM[i]); 174 | } 175 | return parseInt(_res); 176 | }; 177 | 178 | /** 179 | * Convert English Number type to Myanmar 180 | */ 181 | MMNRC.toMyaNum = function(enNum){ 182 | var _res = ""; 183 | while(enNum > 0){ 184 | _res = enNum%10 + _res; 185 | enNum = enNum / 10; 186 | } 187 | return parseInt(_res); 188 | }; 189 | 190 | MMNRC.convDistrict = function(dist){ 191 | var _res = ""; 192 | for (var i = 0; i < dist.length; i++) { 193 | if(!CHARACTERS[dist[i]]) 194 | return null; 195 | _res += CHARACTERS[dist[i]]; 196 | } 197 | return _res; 198 | }; 199 | 200 | MMNRC.formatConvert = function(nrc){ 201 | var _res = {}; 202 | var _match; 203 | if((_match = regx_eng.exec(nrc))){ 204 | _res.lang = "en"; 205 | _res.state += _match[1]; 206 | _res.dist += parseInt(_match[2], 10); 207 | _res.number = parseInt(_match[3], 10); 208 | _res.fullcode = _res.state + "/" + _res.dist + "(N)" + _res.number; 209 | // 3 Characters Districts are not compete and can"t be generate Full Format 210 | if(_res.dist.length === 3) 211 | console.warn("Incomplete format!"); 212 | return _res; 213 | } else if ((_match = regx_mm.exec(nrc))){ 214 | _res.lang = "mm"; 215 | _res.state += MMNRC.toEngNum(_match[1], 10); 216 | _res.dist = MMNRC.convDistrict(_match[2], 10); 217 | _res.number = MMNRC.toEngNum(_match[3], 10); 218 | _res.fullcode = _res.state + "/" + _res.dist + "(N)" + _res.number; 219 | return _res; 220 | } 221 | return null; 222 | }; 223 | 224 | module.exports = MMNRC; 225 | --------------------------------------------------------------------------------