From a428d5ec738584e68b6b5992a55b45b619ebfec2 Mon Sep 17 00:00:00 2001 From: Dmitri Smirnov Date: Wed, 13 Jul 2022 21:53:13 +0300 Subject: [PATCH] Fixed issues #28, added src dir, added constants for gender. --- .gitignore | 1 + Makefile | 9 ++-- __tests__/isikukood.test.js | 34 +++++++++++++-- dest/isikukood.cjs.js | 33 +++++++++------ dest/isikukood.js | 33 +++++++++------ dest/isikukood.min.js | 2 +- dest/isikukood.min.js.map | 4 +- dest/isikukood.mjs | 33 +++++++++------ package-lock.json | 72 ++++++++------------------------ package.json | 8 ++-- isikukood.js => src/isikukood.js | 44 +++++++++++-------- 11 files changed, 149 insertions(+), 124 deletions(-) rename isikukood.js => src/isikukood.js (88%) diff --git a/.gitignore b/.gitignore index 3c3629e..e8f7aaf 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +tags diff --git a/Makefile b/Makefile index 290b500..6b60d65 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,4 @@ +SRC := ./src DEST := ./dest ESBUILD := ./node_modules/.bin/esbuild ESLINT := ./node_modules/.bin/eslint @@ -6,7 +7,7 @@ JEST := ./node_modules/.bin/jest all: build lint test isikukood: - $(ESBUILD) isikukood.js --global-name=ik --format=iife\ + $(ESBUILD) $(SRC)/isikukood.js --global-name=ik --format=iife\ --footer:js="window.Isikukood=ik.Isikukood;"\ --outfile=$(DEST)/isikukood.js @@ -16,17 +17,17 @@ isikukood.min.js: --outfile=$(DEST)/isikukood.min.js isikukood.mjs: - $(ESBUILD) isikukood.js --format=esm\ + $(ESBUILD) $(SRC)/isikukood.js --format=esm\ --outfile=$(DEST)/isikukood.mjs isikukood.cjs.js: - $(ESBUILD) isikukood.js --format=cjs\ + $(ESBUILD) $(SRC)/isikukood.js --format=cjs\ --outfile=$(DEST)/isikukood.cjs.js build: isikukood isikukood.min.js isikukood.mjs isikukood.cjs.js lint: - $(ESLINT) isikukood.js + $(ESLINT) $(SRC)/isikukood.js test: $(call lint) diff --git a/__tests__/isikukood.test.js b/__tests__/isikukood.test.js index e014a85..f6cab12 100644 --- a/__tests__/isikukood.test.js +++ b/__tests__/isikukood.test.js @@ -47,7 +47,35 @@ describe('Generated Isikukood', () => { it(code + ' should be valid', () => { let ik = new Isikukood(code); expect(ik.validate()).toBe(true); - }) + }); + }); + }); + + describe('It should generate female code (#28)', () => { + Array(200) + .fill(null) + .map((_) => Isikukood.generate({ + gender: Isikukood.GENDER.FEMALE + })) + .forEach(code => { + it('should be female code', () => { + let ik = new Isikukood(code); + expect(ik.getGender()).toBe(Isikukood.GENDER.FEMALE); + }); + }); + }); + + describe('It should generate male code (#28)', () => { + Array(200) + .fill(null) + .map((_) => Isikukood.generate({ + gender: Isikukood.GENDER.MALE + })) + .forEach(code => { + it('should be female code', () => { + let ik = new Isikukood(code); + expect(ik.getGender()).toBe(Isikukood.GENDER.MALE); + }); }); }); }); @@ -58,7 +86,7 @@ describe('Isikukood 35703150220', () => { expect(ik.validate()).toBe(true); }); it('should return male as a gender', () => { - expect(ik.getGender()).toBe('male'); + expect(ik.getGender()).toBe(Isikukood.GENDER.MALE); }); it('should return age correctly', () => { const correct_bd = new Date(1957, 2, 15); @@ -84,7 +112,7 @@ describe('Isikukood 48709172756', () => { expect(ik.validate()).toBe(false); }); it('should return female as a gender', () => { - expect(ik.getGender()).toBe('female'); + expect(ik.getGender()).toBe(Isikukood.GENDER.FEMALE); }); it('should return correct age', () => { var correct_bd = new Date(1987, 8, 17); diff --git a/dest/isikukood.cjs.js b/dest/isikukood.cjs.js index 1fedb1b..1bbe26a 100644 --- a/dest/isikukood.cjs.js +++ b/dest/isikukood.cjs.js @@ -30,6 +30,13 @@ class Isikukood { set code(c) { this._code = String(c); } + static get GENDER() { + return { + MALE: "male", + FEMALE: "female", + UNKNOWN: "unknown" + }; + } getControlNumber(code) { if (!code) { code = this.code; @@ -78,15 +85,15 @@ class Isikukood { case "1": case "3": case "5": - retval = "male"; + retval = this.constructor.GENDER.MALE; break; case "2": case "4": case "6": - retval = "female"; + retval = this.constructor.GENDER.FEMALE; break; default: - retval = "unknown"; + retval = this.constructor.GENDER.UNKNOWN; } return retval; } @@ -123,7 +130,7 @@ class Isikukood { let y; let m; let d; - let gender = params.gender || Math.round(Math.random()) === 0 ? "male" : "female"; + let gender = params.gender || (Math.round(Math.random()) === 0 ? this.GENDER.MALE : this.GENDER.FEMALE); let personalId = ""; const hospitals = [ "00", @@ -142,7 +149,7 @@ class Isikukood { "70", "95" ]; - if (!(gender === "female" || gender === "male")) { + if (![this.GENDER.MALE, this.GENDER.FEMALE].includes(gender)) { return ""; } if (params.birthYear) { @@ -161,21 +168,21 @@ class Isikukood { var daysInMonth = new Date(y, m, 0).getDate(); d = Math.floor(Math.random() * daysInMonth) + 1; } - if (gender === "male" && y >= 1800 && y <= 1899) { + if (gender === this.GENDER.MALE && y >= 1800 && y <= 1899) { personalId += "1"; - } else if (gender === "female" && y >= 1800 && y <= 1899) { + } else if (gender === this.GENDER.FEMALE && y >= 1800 && y <= 1899) { personalId += "2"; - } else if (gender === "male" && y >= 1900 && y <= 1999) { + } else if (gender === this.GENDER.MALE && y >= 1900 && y <= 1999) { personalId += "3"; - } else if (gender === "female" && y >= 1900 && y <= 1999) { + } else if (gender === this.GENDER.FEMALE && y >= 1900 && y <= 1999) { personalId += "4"; - } else if (gender === "male" && y >= 2e3 && y <= 2099) { + } else if (gender === this.GENDER.MALE && y >= 2e3 && y <= 2099) { personalId += "5"; - } else if (gender === "female" && y >= 2e3 && y <= 2099) { + } else if (gender === this.GENDER.FEMALE && y >= 2e3 && y <= 2099) { personalId += "6"; - } else if (gender === "male" && y >= 2100 && y <= 2199) { + } else if (gender === this.GENDER.MALE && y >= 2100 && y <= 2199) { personalId += "7"; - } else if (gender === "female" && y >= 2100 && y <= 2199) { + } else if (gender === this.GENDER.FEMALE && y >= 2100 && y <= 2199) { personalId += "8"; } else { return ""; diff --git a/dest/isikukood.js b/dest/isikukood.js index e2b42f8..f0a842c 100644 --- a/dest/isikukood.js +++ b/dest/isikukood.js @@ -30,6 +30,13 @@ var ik = (() => { set code(c) { this._code = String(c); } + static get GENDER() { + return { + MALE: "male", + FEMALE: "female", + UNKNOWN: "unknown" + }; + } getControlNumber(code) { if (!code) { code = this.code; @@ -78,15 +85,15 @@ var ik = (() => { case "1": case "3": case "5": - retval = "male"; + retval = this.constructor.GENDER.MALE; break; case "2": case "4": case "6": - retval = "female"; + retval = this.constructor.GENDER.FEMALE; break; default: - retval = "unknown"; + retval = this.constructor.GENDER.UNKNOWN; } return retval; } @@ -123,7 +130,7 @@ var ik = (() => { let y; let m; let d; - let gender = params.gender || Math.round(Math.random()) === 0 ? "male" : "female"; + let gender = params.gender || (Math.round(Math.random()) === 0 ? this.GENDER.MALE : this.GENDER.FEMALE); let personalId = ""; const hospitals = [ "00", @@ -142,7 +149,7 @@ var ik = (() => { "70", "95" ]; - if (!(gender === "female" || gender === "male")) { + if (![this.GENDER.MALE, this.GENDER.FEMALE].includes(gender)) { return ""; } if (params.birthYear) { @@ -161,21 +168,21 @@ var ik = (() => { var daysInMonth = new Date(y, m, 0).getDate(); d = Math.floor(Math.random() * daysInMonth) + 1; } - if (gender === "male" && y >= 1800 && y <= 1899) { + if (gender === this.GENDER.MALE && y >= 1800 && y <= 1899) { personalId += "1"; - } else if (gender === "female" && y >= 1800 && y <= 1899) { + } else if (gender === this.GENDER.FEMALE && y >= 1800 && y <= 1899) { personalId += "2"; - } else if (gender === "male" && y >= 1900 && y <= 1999) { + } else if (gender === this.GENDER.MALE && y >= 1900 && y <= 1999) { personalId += "3"; - } else if (gender === "female" && y >= 1900 && y <= 1999) { + } else if (gender === this.GENDER.FEMALE && y >= 1900 && y <= 1999) { personalId += "4"; - } else if (gender === "male" && y >= 2e3 && y <= 2099) { + } else if (gender === this.GENDER.MALE && y >= 2e3 && y <= 2099) { personalId += "5"; - } else if (gender === "female" && y >= 2e3 && y <= 2099) { + } else if (gender === this.GENDER.FEMALE && y >= 2e3 && y <= 2099) { personalId += "6"; - } else if (gender === "male" && y >= 2100 && y <= 2199) { + } else if (gender === this.GENDER.MALE && y >= 2100 && y <= 2199) { personalId += "7"; - } else if (gender === "female" && y >= 2100 && y <= 2199) { + } else if (gender === this.GENDER.FEMALE && y >= 2100 && y <= 2199) { personalId += "8"; } else { return ""; diff --git a/dest/isikukood.min.js b/dest/isikukood.min.js index 97c4913..15d11eb 100644 --- a/dest/isikukood.min.js +++ b/dest/isikukood.min.js @@ -1,3 +1,3 @@ // isikukood.js, https://github.com/dknight/Isikukood-js -var ik=(()=>{var n=Object.defineProperty,c=Object.getOwnPropertyDescriptor,u=Object.getOwnPropertyNames,f=Object.prototype.hasOwnProperty,g=(s,e)=>{for(var t in e)n(s,t,{get:e[t],enumerable:!0})},d=(s,e,t,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of u(e))!f.call(s,r)&&r!==t&&n(s,r,{get:()=>e[r],enumerable:!(a=c(e,r))||a.enumerable});return s},b=s=>d(n({},"__esModule",{value:!0}),s),l={};g(l,{Isikukood:()=>m});class m{constructor(e){this.code=e}get code(){return this._code}set code(e){this._code=String(e)}getControlNumber(e){e||(e=this.code);const t=[1,2,3,4,5,6,7,8,9,1],a=[3,4,5,6,7,8,9,1,2,3];let r=0,i=0;for(let o=0;o<10;++o)i+=e.charAt(o)*t[o];if(r=i%11,i=0,r===10){for(let o=0;o<10;++o)i+=e.charAt(o)*a[o];r=i%11,r===10&&(r=0)}return r}validate(){if(this.code.charAt(0)==="0"||this.code.length!==11||this.getControlNumber()!==parseInt(this.code.charAt(10)))return!1;const t=Number(this.code.substring(1,3)),a=Number(this.code.substring(3,5)),r=Number(this.code.substring(5,7)),i=this.getBirthday();return t===i.getFullYear()%100&&i.getMonth()+1===a&&r===i.getDate()}getGender(){const e=this.code.charAt(0);let t="";switch(e){case"1":case"3":case"5":t="male";break;case"2":case"4":case"6":t="female";break;default:t="unknown"}return t}getAge(){return Math.floor((new Date().getTime()-this.getBirthday().getTime())/864e5/365.25)}getBirthday(){let e=parseInt(this.code.substring(1,3));const t=parseInt(this.code.substring(3,5).replace(/^0/,""))-1,a=this.code.substring(5,7).replace(/^0/,""),r=this.code.charAt(0);return r==="1"||r==="2"?e+=1800:r==="3"||r==="4"?e+=1900:r==="5"||r==="6"?e+=2e3:(r==="7"||r==="8")&&(e+=2100),new Date(e,t,a)}parse(e){return e||(e=this.code),{gender:this.getGender(),birthDay:this.getBirthday(),age:this.getAge()}}static generate(e={}){let t,a,r,i=e.gender||Math.round(Math.random())===0?"male":"female",o="";const h=["00","01","02","22","27","37","42","47","49","52","57","60","65","70","95"];if(!(i==="female"||i==="male"))return"";if(e.birthYear?t=e.birthYear:t=Math.round(Math.random()*100+1900+(new Date().getFullYear()-2e3)),e.birthMonth?a=e.birthMonth:a=Math.floor(Math.random()*12)+1,e.birthDay)r=e.birthDay;else{var p=new Date(t,a,0).getDate();r=Math.floor(Math.random()*p)+1}if(i==="male"&&t>=1800&&t<=1899)o+="1";else if(i==="female"&&t>=1800&&t<=1899)o+="2";else if(i==="male"&&t>=1900&&t<=1999)o+="3";else if(i==="female"&&t>=1900&&t<=1999)o+="4";else if(i==="male"&&t>=2e3&&t<=2099)o+="5";else if(i==="female"&&t>=2e3&&t<=2099)o+="6";else if(i==="male"&&t>=2100&&t<=2199)o+="7";else if(i==="female"&&t>=2100&&t<=2199)o+="8";else return"";return o+=String(t).substring(2,4),o+=String(a).length===1?"0"+a:a,o+=String(r).length===1?"0"+r:r,o+=h[Math.floor(Math.random()*h.length)],o+=Math.floor(Math.random()*10),o+=this.prototype.getControlNumber(o),o}}return b(l)})();window.Isikukood=ik.Isikukood; +var ik=(()=>{var a=Object.defineProperty,c=Object.getOwnPropertyDescriptor,u=Object.getOwnPropertyNames,E=Object.prototype.hasOwnProperty,g=(n,t)=>{for(var e in t)a(n,e,{get:t[e],enumerable:!0})},d=(n,t,e,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of u(t))!E.call(n,r)&&r!==e&&a(n,r,{get:()=>t[r],enumerable:!(o=c(t,r))||o.enumerable});return n},f=n=>d(a({},"__esModule",{value:!0}),n),h={};g(h,{Isikukood:()=>b});class b{constructor(t){this.code=t}get code(){return this._code}set code(t){this._code=String(t)}static get GENDER(){return{MALE:"male",FEMALE:"female",UNKNOWN:"unknown"}}getControlNumber(t){t||(t=this.code);const e=[1,2,3,4,5,6,7,8,9,1],o=[3,4,5,6,7,8,9,1,2,3];let r=0,s=0;for(let i=0;i<10;++i)s+=t.charAt(i)*e[i];if(r=s%11,s=0,r===10){for(let i=0;i<10;++i)s+=t.charAt(i)*o[i];r=s%11,r===10&&(r=0)}return r}validate(){if(this.code.charAt(0)==="0"||this.code.length!==11||this.getControlNumber()!==parseInt(this.code.charAt(10)))return!1;const e=Number(this.code.substring(1,3)),o=Number(this.code.substring(3,5)),r=Number(this.code.substring(5,7)),s=this.getBirthday();return e===s.getFullYear()%100&&s.getMonth()+1===o&&r===s.getDate()}getGender(){const t=this.code.charAt(0);let e="";switch(t){case"1":case"3":case"5":e=this.constructor.GENDER.MALE;break;case"2":case"4":case"6":e=this.constructor.GENDER.FEMALE;break;default:e=this.constructor.GENDER.UNKNOWN}return e}getAge(){return Math.floor((new Date().getTime()-this.getBirthday().getTime())/864e5/365.25)}getBirthday(){let t=parseInt(this.code.substring(1,3));const e=parseInt(this.code.substring(3,5).replace(/^0/,""))-1,o=this.code.substring(5,7).replace(/^0/,""),r=this.code.charAt(0);return r==="1"||r==="2"?t+=1800:r==="3"||r==="4"?t+=1900:r==="5"||r==="6"?t+=2e3:(r==="7"||r==="8")&&(t+=2100),new Date(t,e,o)}parse(t){return t||(t=this.code),{gender:this.getGender(),birthDay:this.getBirthday(),age:this.getAge()}}static generate(t={}){let e,o,r,s=t.gender||(Math.round(Math.random())===0?this.GENDER.MALE:this.GENDER.FEMALE),i="";const l=["00","01","02","22","27","37","42","47","49","52","57","60","65","70","95"];if(![this.GENDER.MALE,this.GENDER.FEMALE].includes(s))return"";if(t.birthYear?e=t.birthYear:e=Math.round(Math.random()*100+1900+(new Date().getFullYear()-2e3)),t.birthMonth?o=t.birthMonth:o=Math.floor(Math.random()*12)+1,t.birthDay)r=t.birthDay;else{var M=new Date(e,o,0).getDate();r=Math.floor(Math.random()*M)+1}if(s===this.GENDER.MALE&&e>=1800&&e<=1899)i+="1";else if(s===this.GENDER.FEMALE&&e>=1800&&e<=1899)i+="2";else if(s===this.GENDER.MALE&&e>=1900&&e<=1999)i+="3";else if(s===this.GENDER.FEMALE&&e>=1900&&e<=1999)i+="4";else if(s===this.GENDER.MALE&&e>=2e3&&e<=2099)i+="5";else if(s===this.GENDER.FEMALE&&e>=2e3&&e<=2099)i+="6";else if(s===this.GENDER.MALE&&e>=2100&&e<=2199)i+="7";else if(s===this.GENDER.FEMALE&&e>=2100&&e<=2199)i+="8";else return"";return i+=String(e).substring(2,4),i+=String(o).length===1?"0"+o:o,i+=String(r).length===1?"0"+r:r,i+=l[Math.floor(Math.random()*l.length)],i+=Math.floor(Math.random()*10),i+=this.prototype.getControlNumber(i),i}}return f(h)})();window.Isikukood=ik.Isikukood; //# sourceMappingURL=isikukood.min.js.map diff --git a/dest/isikukood.min.js.map b/dest/isikukood.min.js.map index 7f36dc3..e33abd6 100644 --- a/dest/isikukood.min.js.map +++ b/dest/isikukood.min.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["isikukood.js"], - "sourcesContent": ["var ik = (() => {\n var __defProp = Object.defineProperty;\n var __getOwnPropDesc = Object.getOwnPropertyDescriptor;\n var __getOwnPropNames = Object.getOwnPropertyNames;\n var __hasOwnProp = Object.prototype.hasOwnProperty;\n var __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n };\n var __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n };\n var __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n var isikukood_exports = {};\n __export(isikukood_exports, {\n Isikukood: () => Isikukood\n });\n class Isikukood {\n constructor(c) {\n this.code = c;\n }\n get code() {\n return this._code;\n }\n set code(c) {\n this._code = String(c);\n }\n getControlNumber(code) {\n if (!code) {\n code = this.code;\n }\n const multiplier1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];\n const multiplier2 = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];\n let mod = 0;\n let total = 0;\n for (let i = 0; i < 10; ++i) {\n total += code.charAt(i) * multiplier1[i];\n }\n mod = total % 11;\n total = 0;\n if (mod === 10) {\n for (let i = 0; i < 10; ++i) {\n total += code.charAt(i) * multiplier2[i];\n }\n mod = total % 11;\n if (mod === 10) {\n mod = 0;\n }\n }\n return mod;\n }\n validate() {\n if (this.code.charAt(0) === \"0\") {\n return false;\n }\n if (this.code.length !== 11) {\n return false;\n }\n const control = this.getControlNumber();\n if (control !== parseInt(this.code.charAt(10))) {\n return false;\n }\n const year = Number(this.code.substring(1, 3));\n const month = Number(this.code.substring(3, 5));\n const day = Number(this.code.substring(5, 7));\n const birthDate = this.getBirthday();\n return year === birthDate.getFullYear() % 100 && birthDate.getMonth() + 1 === month && day === birthDate.getDate();\n }\n getGender() {\n const firstNumber = this.code.charAt(0);\n let retval = \"\";\n switch (firstNumber) {\n case \"1\":\n case \"3\":\n case \"5\":\n retval = \"male\";\n break;\n case \"2\":\n case \"4\":\n case \"6\":\n retval = \"female\";\n break;\n default:\n retval = \"unknown\";\n }\n return retval;\n }\n getAge() {\n return Math.floor((new Date().getTime() - this.getBirthday().getTime()) / (86400 * 1e3) / 365.25);\n }\n getBirthday() {\n let year = parseInt(this.code.substring(1, 3));\n const month = parseInt(this.code.substring(3, 5).replace(/^0/, \"\")) - 1;\n const day = this.code.substring(5, 7).replace(/^0/, \"\");\n const firstNumber = this.code.charAt(0);\n if (firstNumber === \"1\" || firstNumber === \"2\") {\n year += 1800;\n } else if (firstNumber === \"3\" || firstNumber === \"4\") {\n year += 1900;\n } else if (firstNumber === \"5\" || firstNumber === \"6\") {\n year += 2e3;\n } else if (firstNumber === \"7\" || firstNumber === \"8\") {\n year += 2100;\n }\n return new Date(year, month, day);\n }\n parse(code) {\n if (!code) {\n code = this.code;\n }\n return {\n gender: this.getGender(),\n birthDay: this.getBirthday(),\n age: this.getAge()\n };\n }\n static generate(params = {}) {\n let y;\n let m;\n let d;\n let gender = params.gender || Math.round(Math.random()) === 0 ? \"male\" : \"female\";\n let personalId = \"\";\n const hospitals = [\n \"00\",\n \"01\",\n \"02\",\n \"22\",\n \"27\",\n \"37\",\n \"42\",\n \"47\",\n \"49\",\n \"52\",\n \"57\",\n \"60\",\n \"65\",\n \"70\",\n \"95\"\n ];\n if (!(gender === \"female\" || gender === \"male\")) {\n return \"\";\n }\n if (params.birthYear) {\n y = params.birthYear;\n } else {\n y = Math.round(Math.random() * 100 + 1900 + (new Date().getFullYear() - 2e3));\n }\n if (params.birthMonth) {\n m = params.birthMonth;\n } else {\n m = Math.floor(Math.random() * 12) + 1;\n }\n if (params.birthDay) {\n d = params.birthDay;\n } else {\n var daysInMonth = new Date(y, m, 0).getDate();\n d = Math.floor(Math.random() * daysInMonth) + 1;\n }\n if (gender === \"male\" && y >= 1800 && y <= 1899) {\n personalId += \"1\";\n } else if (gender === \"female\" && y >= 1800 && y <= 1899) {\n personalId += \"2\";\n } else if (gender === \"male\" && y >= 1900 && y <= 1999) {\n personalId += \"3\";\n } else if (gender === \"female\" && y >= 1900 && y <= 1999) {\n personalId += \"4\";\n } else if (gender === \"male\" && y >= 2e3 && y <= 2099) {\n personalId += \"5\";\n } else if (gender === \"female\" && y >= 2e3 && y <= 2099) {\n personalId += \"6\";\n } else if (gender === \"male\" && y >= 2100 && y <= 2199) {\n personalId += \"7\";\n } else if (gender === \"female\" && y >= 2100 && y <= 2199) {\n personalId += \"8\";\n } else {\n return \"\";\n }\n personalId += String(y).substring(2, 4);\n personalId += String(m).length === 1 ? \"0\" + m : m;\n personalId += String(d).length === 1 ? \"0\" + d : d;\n personalId += hospitals[Math.floor(Math.random() * hospitals.length)];\n personalId += Math.floor(Math.random() * 10);\n personalId += this.prototype.getControlNumber(personalId);\n return personalId;\n }\n }\n return __toCommonJS(isikukood_exports);\n})();\nwindow.Isikukood=ik.Isikukood;\n"], - "mappings": ";AAAA,GAAI,IAAM,KAAM,CACd,GAAI,GAAY,OAAO,eACnB,EAAmB,OAAO,yBAC1B,EAAoB,OAAO,oBAC3B,EAAe,OAAO,UAAU,eAChC,EAAW,CAAC,EAAQ,IAAQ,CAC9B,OAAS,KAAQ,GACf,EAAU,EAAQ,EAAM,CAAE,IAAK,EAAI,GAAO,WAAY,EAAK,CAAC,CAChE,EACI,EAAc,CAAC,EAAI,EAAM,EAAQ,IAAS,CAC5C,GAAI,GAAQ,MAAO,IAAS,UAAY,MAAO,IAAS,WACtD,OAAS,KAAO,GAAkB,CAAI,EACpC,AAAI,CAAC,EAAa,KAAK,EAAI,CAAG,GAAK,IAAQ,GACzC,EAAU,EAAI,EAAK,CAAE,IAAK,IAAM,EAAK,GAAM,WAAY,CAAE,GAAO,EAAiB,EAAM,CAAG,IAAM,EAAK,UAAW,CAAC,EAEvH,MAAO,EACT,EACI,EAAe,AAAC,GAAQ,EAAY,EAAU,CAAC,EAAG,aAAc,CAAE,MAAO,EAAK,CAAC,EAAG,CAAG,EACrF,EAAoB,CAAC,EACzB,EAAS,EAAmB,CAC1B,UAAW,IAAM,CACnB,CAAC,EACD,MAAM,CAAU,CACd,YAAY,EAAG,CACb,KAAK,KAAO,CACd,CACA,GAAI,OAAO,CACT,MAAO,MAAK,KACd,CACA,GAAI,MAAK,EAAG,CACV,KAAK,MAAQ,OAAO,CAAC,CACvB,CACA,iBAAiB,EAAM,CACrB,AAAK,GACH,GAAO,KAAK,MAEd,KAAM,GAAc,CAAC,EAAG,EAAG,EAAG,EAAG,EAAG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QAAU,GAAK,MAAQ,GAAK,KACzC,GAAc,YACL,IAAW,UAAY,GAAK,MAAQ,GAAK,KAClD,GAAc,YACL,IAAW,QAAU,GAAK,MAAQ,GAAK,KAChD,GAAc,YACL,IAAW,UAAY,GAAK,MAAQ,GAAK,KAClD,GAAc,YACL,IAAW,QAAU,GAAK,KAAO,GAAK,KAC/C,GAAc,YACL,IAAW,UAAY,GAAK,KAAO,GAAK,KACjD,GAAc,YACL,IAAW,QAAU,GAAK,MAAQ,GAAK,KAChD,GAAc,YACL,IAAW,UAAY,GAAK,MAAQ,GAAK,KAClD,GAAc,QAEd,OAAO,GAET,UAAc,OAAO,CAAC,EAAE,UAAU,EAAG,CAAC,EACtC,GAAc,OAAO,CAAC,EAAE,SAAW,EAAI,IAAM,EAAI,EACjD,GAAc,OAAO,CAAC,EAAE,SAAW,EAAI,IAAM,EAAI,EACjD,GAAc,EAAU,KAAK,MAAM,KAAK,OAAO,EAAI,EAAU,MAAM,GACnE,GAAc,KAAK,MAAM,KAAK,OAAO,EAAI,EAAE,EAC3C,GAAc,KAAK,UAAU,iBAAiB,CAAU,EACjD,CACT,CACF,CACA,MAAO,GAAa,CAAiB,CACvC,GAAG,EACH,OAAO,UAAU,GAAG", + "sourcesContent": ["var ik = (() => {\n var __defProp = Object.defineProperty;\n var __getOwnPropDesc = Object.getOwnPropertyDescriptor;\n var __getOwnPropNames = Object.getOwnPropertyNames;\n var __hasOwnProp = Object.prototype.hasOwnProperty;\n var __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n };\n var __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n };\n var __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\n var isikukood_exports = {};\n __export(isikukood_exports, {\n Isikukood: () => Isikukood\n });\n class Isikukood {\n constructor(c) {\n this.code = c;\n }\n get code() {\n return this._code;\n }\n set code(c) {\n this._code = String(c);\n }\n static get GENDER() {\n return {\n MALE: \"male\",\n FEMALE: \"female\",\n UNKNOWN: \"unknown\"\n };\n }\n getControlNumber(code) {\n if (!code) {\n code = this.code;\n }\n const multiplier1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];\n const multiplier2 = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];\n let mod = 0;\n let total = 0;\n for (let i = 0; i < 10; ++i) {\n total += code.charAt(i) * multiplier1[i];\n }\n mod = total % 11;\n total = 0;\n if (mod === 10) {\n for (let i = 0; i < 10; ++i) {\n total += code.charAt(i) * multiplier2[i];\n }\n mod = total % 11;\n if (mod === 10) {\n mod = 0;\n }\n }\n return mod;\n }\n validate() {\n if (this.code.charAt(0) === \"0\") {\n return false;\n }\n if (this.code.length !== 11) {\n return false;\n }\n const control = this.getControlNumber();\n if (control !== parseInt(this.code.charAt(10))) {\n return false;\n }\n const year = Number(this.code.substring(1, 3));\n const month = Number(this.code.substring(3, 5));\n const day = Number(this.code.substring(5, 7));\n const birthDate = this.getBirthday();\n return year === birthDate.getFullYear() % 100 && birthDate.getMonth() + 1 === month && day === birthDate.getDate();\n }\n getGender() {\n const firstNumber = this.code.charAt(0);\n let retval = \"\";\n switch (firstNumber) {\n case \"1\":\n case \"3\":\n case \"5\":\n retval = this.constructor.GENDER.MALE;\n break;\n case \"2\":\n case \"4\":\n case \"6\":\n retval = this.constructor.GENDER.FEMALE;\n break;\n default:\n retval = this.constructor.GENDER.UNKNOWN;\n }\n return retval;\n }\n getAge() {\n return Math.floor((new Date().getTime() - this.getBirthday().getTime()) / (86400 * 1e3) / 365.25);\n }\n getBirthday() {\n let year = parseInt(this.code.substring(1, 3));\n const month = parseInt(this.code.substring(3, 5).replace(/^0/, \"\")) - 1;\n const day = this.code.substring(5, 7).replace(/^0/, \"\");\n const firstNumber = this.code.charAt(0);\n if (firstNumber === \"1\" || firstNumber === \"2\") {\n year += 1800;\n } else if (firstNumber === \"3\" || firstNumber === \"4\") {\n year += 1900;\n } else if (firstNumber === \"5\" || firstNumber === \"6\") {\n year += 2e3;\n } else if (firstNumber === \"7\" || firstNumber === \"8\") {\n year += 2100;\n }\n return new Date(year, month, day);\n }\n parse(code) {\n if (!code) {\n code = this.code;\n }\n return {\n gender: this.getGender(),\n birthDay: this.getBirthday(),\n age: this.getAge()\n };\n }\n static generate(params = {}) {\n let y;\n let m;\n let d;\n let gender = params.gender || (Math.round(Math.random()) === 0 ? this.GENDER.MALE : this.GENDER.FEMALE);\n let personalId = \"\";\n const hospitals = [\n \"00\",\n \"01\",\n \"02\",\n \"22\",\n \"27\",\n \"37\",\n \"42\",\n \"47\",\n \"49\",\n \"52\",\n \"57\",\n \"60\",\n \"65\",\n \"70\",\n \"95\"\n ];\n if (![this.GENDER.MALE, this.GENDER.FEMALE].includes(gender)) {\n return \"\";\n }\n if (params.birthYear) {\n y = params.birthYear;\n } else {\n y = Math.round(Math.random() * 100 + 1900 + (new Date().getFullYear() - 2e3));\n }\n if (params.birthMonth) {\n m = params.birthMonth;\n } else {\n m = Math.floor(Math.random() * 12) + 1;\n }\n if (params.birthDay) {\n d = params.birthDay;\n } else {\n var daysInMonth = new Date(y, m, 0).getDate();\n d = Math.floor(Math.random() * daysInMonth) + 1;\n }\n if (gender === this.GENDER.MALE && y >= 1800 && y <= 1899) {\n personalId += \"1\";\n } else if (gender === this.GENDER.FEMALE && y >= 1800 && y <= 1899) {\n personalId += \"2\";\n } else if (gender === this.GENDER.MALE && y >= 1900 && y <= 1999) {\n personalId += \"3\";\n } else if (gender === this.GENDER.FEMALE && y >= 1900 && y <= 1999) {\n personalId += \"4\";\n } else if (gender === this.GENDER.MALE && y >= 2e3 && y <= 2099) {\n personalId += \"5\";\n } else if (gender === this.GENDER.FEMALE && y >= 2e3 && y <= 2099) {\n personalId += \"6\";\n } else if (gender === this.GENDER.MALE && y >= 2100 && y <= 2199) {\n personalId += \"7\";\n } else if (gender === this.GENDER.FEMALE && y >= 2100 && y <= 2199) {\n personalId += \"8\";\n } else {\n return \"\";\n }\n personalId += String(y).substring(2, 4);\n personalId += String(m).length === 1 ? \"0\" + m : m;\n personalId += String(d).length === 1 ? \"0\" + d : d;\n personalId += hospitals[Math.floor(Math.random() * hospitals.length)];\n personalId += Math.floor(Math.random() * 10);\n personalId += this.prototype.getControlNumber(personalId);\n return personalId;\n }\n }\n return __toCommonJS(isikukood_exports);\n})();\nwindow.Isikukood=ik.Isikukood;\n"], + "mappings": ";AAAA,GAAI,IAAM,KAAM,CACd,GAAI,GAAY,OAAO,eACnB,EAAmB,OAAO,yBAC1B,EAAoB,OAAO,oBAC3B,EAAe,OAAO,UAAU,eAChC,EAAW,CAAC,EAAQ,IAAQ,CAC9B,OAAS,KAAQ,GACf,EAAU,EAAQ,EAAM,CAAE,IAAK,EAAI,GAAO,WAAY,EAAK,CAAC,CAChE,EACI,EAAc,CAAC,EAAI,EAAM,EAAQ,IAAS,CAC5C,GAAI,GAAQ,MAAO,IAAS,UAAY,MAAO,IAAS,WACtD,OAAS,KAAO,GAAkB,CAAI,EACpC,AAAI,CAAC,EAAa,KAAK,EAAI,CAAG,GAAK,IAAQ,GACzC,EAAU,EAAI,EAAK,CAAE,IAAK,IAAM,EAAK,GAAM,WAAY,CAAE,GAAO,EAAiB,EAAM,CAAG,IAAM,EAAK,UAAW,CAAC,EAEvH,MAAO,EACT,EACI,EAAe,AAAC,GAAQ,EAAY,EAAU,CAAC,EAAG,aAAc,CAAE,MAAO,EAAK,CAAC,EAAG,CAAG,EACrF,EAAoB,CAAC,EACzB,EAAS,EAAmB,CAC1B,UAAW,IAAM,CACnB,CAAC,EACD,MAAM,CAAU,CACd,YAAY,EAAG,CACb,KAAK,KAAO,CACd,CACA,GAAI,OAAO,CACT,MAAO,MAAK,KACd,CACA,GAAI,MAAK,EAAG,CACV,KAAK,MAAQ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176a6c4..42b3d23 100644 --- a/dest/isikukood.mjs +++ b/dest/isikukood.mjs @@ -8,6 +8,13 @@ class Isikukood { set code(c) { this._code = String(c); } + static get GENDER() { + return { + MALE: "male", + FEMALE: "female", + UNKNOWN: "unknown" + }; + } getControlNumber(code) { if (!code) { code = this.code; @@ -56,15 +63,15 @@ class Isikukood { case "1": case "3": case "5": - retval = "male"; + retval = this.constructor.GENDER.MALE; break; case "2": case "4": case "6": - retval = "female"; + retval = this.constructor.GENDER.FEMALE; break; default: - retval = "unknown"; + retval = this.constructor.GENDER.UNKNOWN; } return retval; } @@ -101,7 +108,7 @@ class Isikukood { let y; let m; let d; - let gender = params.gender || Math.round(Math.random()) === 0 ? "male" : "female"; + let gender = params.gender || (Math.round(Math.random()) === 0 ? this.GENDER.MALE : this.GENDER.FEMALE); let personalId = ""; const hospitals = [ "00", @@ -120,7 +127,7 @@ class Isikukood { "70", "95" ]; - if (!(gender === "female" || gender === "male")) { + if (![this.GENDER.MALE, this.GENDER.FEMALE].includes(gender)) { return ""; } if (params.birthYear) { @@ -139,21 +146,21 @@ class Isikukood { var daysInMonth = new Date(y, m, 0).getDate(); d = Math.floor(Math.random() * daysInMonth) + 1; } - if (gender === "male" && y >= 1800 && y <= 1899) { + if (gender === this.GENDER.MALE && y >= 1800 && y <= 1899) { personalId += "1"; - } else if (gender === "female" && y >= 1800 && y <= 1899) { + } else if (gender === this.GENDER.FEMALE && y >= 1800 && y <= 1899) { personalId += "2"; - } else if (gender === "male" && y >= 1900 && y <= 1999) { + } else if (gender === this.GENDER.MALE && y >= 1900 && y <= 1999) { personalId += "3"; - } else if (gender === "female" && y >= 1900 && y <= 1999) { + } else if (gender === this.GENDER.FEMALE && y >= 1900 && y <= 1999) { personalId += "4"; - } else if (gender === "male" && y >= 2e3 && y <= 2099) { + } else if (gender === this.GENDER.MALE && y >= 2e3 && y <= 2099) { personalId += "5"; - } else if (gender === "female" && y >= 2e3 && y <= 2099) { + } else if (gender === this.GENDER.FEMALE && y >= 2e3 && y <= 2099) { personalId += "6"; - } else if (gender === "male" && y >= 2100 && y <= 2199) { + } else if (gender === this.GENDER.MALE && y >= 2100 && y <= 2199) { personalId += "7"; - } else if (gender === "female" && y >= 2100 && y <= 2199) { + } else if (gender === this.GENDER.FEMALE && y >= 2100 && y <= 2199) { personalId += "8"; } else { return ""; diff --git a/package-lock.json b/package-lock.json index 5aa8ae0..28c6371 100644 --- a/package-lock.json +++ b/package-lock.json @@ -593,18 +593,6 @@ "node": "*" } }, - "node_modules/@eslint/eslintrc/node_modules/strip-json-comments": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", - "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", - "dev": true, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/@humanwhocodes/config-array": { "version": "0.9.5", "resolved": "https://registry.npmjs.org/@humanwhocodes/config-array/-/config-array-0.9.5.tgz", @@ -2610,18 +2598,6 @@ "node": ">=8" } }, - "node_modules/eslint/node_modules/strip-json-comments": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", - "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", - "dev": true, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/eslint/node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -3621,18 +3597,6 @@ "node": ">=8" } }, - "node_modules/jest-config/node_modules/strip-json-comments": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", - "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", - "dev": true, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/jest-config/node_modules/supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -5551,6 +5515,18 @@ "node": ">=6" } }, + "node_modules/strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, "node_modules/supports-hyperlinks": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-2.2.0.tgz", @@ -6321,12 +6297,6 @@ "requires": { "brace-expansion": "^1.1.7" } - }, - "strip-json-comments": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", - "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", - "dev": true } } }, @@ -7724,12 +7694,6 @@ "ansi-regex": "^5.0.1" } }, - "strip-json-comments": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", - "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", - "dev": true - }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -8490,12 +8454,6 @@ "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true }, - "strip-json-comments": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", - "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", - "dev": true - }, "supports-color": { "version": "7.2.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", @@ -9924,6 +9882,12 @@ "integrity": "sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA==", "dev": true }, + "strip-json-comments": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/strip-json-comments/-/strip-json-comments-3.1.1.tgz", + "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", + "dev": true + }, "supports-hyperlinks": { "version": "2.2.0", "resolved": "https://registry.npmjs.org/supports-hyperlinks/-/supports-hyperlinks-2.2.0.tgz", diff --git a/package.json b/package.json index 9e9715b..f1dc3f4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "isikukood", - "version": "2.0.0", + "version": "2.0.1", "description": "Estonian personal ID (isikukood) JavaScript module", "main": "isikukood.js", "directories": { @@ -17,6 +17,7 @@ "keywords": [ "isikukood", "estonia", + "eesti", "personalid" ], "author": "Dmitri Smirnov", @@ -26,12 +27,11 @@ }, "homepage": "https://github.com/dknight/Isikukood-js/", "devDependencies": { - "eslint": "8.18.0", "esbuild": "0.14.47", + "eslint": "8.18.0", "jest": "28.1.2" }, - "dependencies": {}, - "jest": { + "jest": { "verbose": true, "testEnvironmentOptions": { "url": "http://localhost:4000/" diff --git a/isikukood.js b/src/isikukood.js similarity index 88% rename from isikukood.js rename to src/isikukood.js index aafebfc..fbfa69f 100644 --- a/isikukood.js +++ b/src/isikukood.js @@ -43,8 +43,7 @@ export class Isikukood { } /** - * @public - * @return {string} + * @type {string} */ get code() { return this._code; @@ -57,6 +56,17 @@ export class Isikukood { this._code = String(c); } + /** + * @enum {string} + */ + static get GENDER() { + return { + MALE: 'male', + FEMALE: 'female', + UNKNOWN: 'unknown' + }; + } + /** * Gets the control number of personal ID. * @param {string} [code] @@ -126,15 +136,15 @@ export class Isikukood { case '1': case '3': case '5': - retval = 'male'; + retval = this.constructor.GENDER.MALE; break; case '2': case '4': case '6': - retval = 'female'; + retval = this.constructor.GENDER.FEMALE; break; default: - retval = 'unknown'; + retval = this.constructor.GENDER.UNKNOWN; } return retval; } @@ -202,9 +212,9 @@ export class Isikukood { let y; let m; let d; - let gender = params.gender || (Math.round(Math.random()) === 0) - ? 'male' - : 'female'; + let gender = params.gender || (Math.round(Math.random()) === 0 + ? this.GENDER.MALE + : this.GENDER.FEMALE); let personalId = ''; // Places of brith (Estonian Hospitals) @@ -226,7 +236,7 @@ export class Isikukood { '95' // Foreigners who are born in Estonia ]; - if (!(gender === 'female' || gender === 'male')) { + if (![this.GENDER.MALE, this.GENDER.FEMALE].includes(gender)) { return ''; } @@ -250,21 +260,21 @@ export class Isikukood { } // Set the gender - if (gender === 'male' && y >= 1800 && y <= 1899) { + if (gender === this.GENDER.MALE && y >= 1800 && y <= 1899) { personalId += '1'; - } else if (gender === 'female' && y >= 1800 && y <= 1899) { + } else if (gender === this.GENDER.FEMALE && y >= 1800 && y <= 1899) { personalId += '2'; - } else if (gender === 'male' && y >= 1900 && y <= 1999) { + } else if (gender === this.GENDER.MALE && y >= 1900 && y <= 1999) { personalId += '3'; - } else if (gender === 'female' && y >= 1900 && y <= 1999) { + } else if (gender === this.GENDER.FEMALE && y >= 1900 && y <= 1999) { personalId += '4'; - } else if (gender === 'male' && y >= 2000 && y <= 2099) { + } else if (gender === this.GENDER.MALE && y >= 2000 && y <= 2099) { personalId += '5'; - } else if (gender === 'female' && y >= 2000 && y <= 2099) { + } else if (gender === this.GENDER.FEMALE && y >= 2000 && y <= 2099) { personalId += '6'; - } else if (gender === 'male' && y >= 2100 && y <= 2199) { + } else if (gender === this.GENDER.MALE && y >= 2100 && y <= 2199) { personalId += '7'; - } else if (gender === 'female' && y >= 2100 && y <= 2199) { + } else if (gender === this.GENDER.FEMALE && y >= 2100 && y <= 2199) { personalId += '8'; } else { return '';