This package is to streamline development for myanmar nric input and verification.
Using npm:
npm install mm-nric
Using yarn:
yarn add mm-nric
Using pnpm:
pnpm add mm-nric
After installation you can use the package with either import
or requrie
approach.
Example
import { getStates } from 'mm-nric'
console.log(getStates())
// OR
const mmNric = require('mm-nric')
console.log(mmNric.getStates()
Generators
Returns an array of all states.
const states = getStates()
Returns an array of all districts.
const districts = getDistricts()
Returns an array of districts included in the specified state. Useful for controlling the dropdown values based on the state that the user chose.
NOTE: This function will return an empty array for invalid state code.
const districts = getDistrictsByState(1)
Validators
Returns a boolean to check if the specified state code is valid.
NOTE: valid state codes are numbers ranging from 1 to 14
console.log(validateState(1)) // true
console.log(validateState(0)) // false
console.log(validateState(15)) // false
Returns a boolean to check if the specified nric type is valid. Useful to validate raw user inputs
console.log(validateNricType('N')) // true
console.log(validateNricType('A')) // false
Returns a boolean to check if the specified nric string is in valid format. Supports for both myanmar and english language.
console.log(validateNricFormat('12/PABADA(N)0XXXXX')) // en
console.log(validateNricFormat('၁၂/ပဘတ(နိုင်)၀xxxxx')) // mm
Returns a boolean to check if the specified nric string is valid. Supports for both myanmar and english language.
Currently only supports english NRIC
console.log(validateNric('12/PABADA(N)0XXXXX')) // true
Conversions
Convert the provided NRIC string from myanmar to english.
console.log(convertToEnglish('၁၂/ပဇတ(နိုင်)၀၀၀၀၀၀')) // 12/PAZATA(N)000000
Convert the provided NRIC string from english to myanmar.
console.log(convertToEnglish('12/PAZATA(N)000000')) // ၁၂/ပဇတ(နိုင်)၀၀၀၀၀၀
interface State {
en: string; /* English State Name */
mm: string; /* Burmese State Suffix */
code: number; /* The State code */
}
interface District {
en: string; /* English District Suffix */
mm: string; /* Burmese District Suffix */
code: number; /* The State code */
fullEn: string; /* Full English District Name */
fullMm: string; /* Full Burmese District Name */
}
enum NricTypesEn {
N = 'N',
E = 'E',
P = 'P',
}
enum NricTypesMm {
N = 'နိုင်',
E = 'ဧည့်',
P = 'ပြု',
}