diff --git a/README.md b/README.md index 7241e9c..ff0a245 100644 --- a/README.md +++ b/README.md @@ -66,62 +66,24 @@ const maleIk = Isikukood.generate({ ## API - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
MethodDescriptionArgumentsReturn
new Isikukood()constructornumber|stringIsikukood
validate()Validates personal ID-boolean
generate()Static function generates a valid personal ID.Object { gender: "male|female", birthDay: day, birthMonth: month, birthYear: year }.r Month are beginning from 1, eg. 1 is January, 2 is February etc.string
getGender()Get the gender of a person.-string
getBirthday()Get the birthday of a person.-Date
getAge()Get the birthday of a person in years.-number
getControlNumber()Gets the control number of personal ID-number
parse()Parses the code and return it's data as object.-object
+### Instance methods + +| Method | Description | Arguments | Return | +| ------------------ | --------------------------------------------- | ---------------- | ------------ | +| new Isikukood() | constructor | number \| string | Isikukood | +| validate() | Validates personal ID | - | boolean | +| generate() | Static function generates a valid personal ID | GenerateInput | string | +| getGender() | Get the gender of a person | - | Gender | +| getBirthday() | Get the birthday of a person | - | Date | +| getAge() | Get the birthday of a person in years | - | number | +| getControlNumber() | Gets the control number of personal ID | - | number | +| parse() | Parses the code | - | PersonalData | + +### Static methods + +| Method | Description | Arguments | Return | +| ------- | --------------- | ---------------- | ------------ | +| parse() | Parses the code | number \| string | PersonalData | ## Development diff --git a/__tests__/isikukood.test.ts b/__tests__/isikukood.test.ts index 5ff205c..833bbcd 100644 --- a/__tests__/isikukood.test.ts +++ b/__tests__/isikukood.test.ts @@ -1,4 +1,4 @@ -import Isikukood, {Gender} from '../index'; +import Isikukood, {Gender, PersonalData} from '../index'; /** * Isikukood test suite. * @@ -118,6 +118,19 @@ describe('Isikukood 35703150220', () => { it('should have controlNumber 0', () => { expect(ik.getControlNumber()).toEqual(0); }); + + it('should parse the id', () => { + const expBD = new Date(1957, 2, 15); + const exp: PersonalData = { + gender: Gender.MALE, + age: getAge(expBD), + birthDay: expBD, + }; + let got = Isikukood.parse(ik.code); + expect(got).toStrictEqual(exp); + got = ik.parse(); + expect(got).toStrictEqual(exp); + }); }); describe('Isikukood 48709172756', () => { @@ -166,7 +179,6 @@ describe('Isikukood 28709172754', () => { describe('Isikukood 49200186017', () => { const ik: Isikukood = new Isikukood('49200186017'); - it('should not validate', () => { expect(ik.validate()).toBe(false); }); @@ -177,6 +189,19 @@ describe('Isikukood 60311213742 (#5)', () => { it('should validate', () => { expect(ik.validate()).toBe(true); }); + + it('should parse the id', () => { + const expBD = new Date(2003, 10, 21); + const exp: PersonalData = { + gender: Gender.FEMALE, + age: getAge(expBD), + birthDay: expBD, + }; + let got: PersonalData = Isikukood.parse(ik.code); + expect(got).toStrictEqual(exp); + got = ik.parse(); + expect(got).toStrictEqual(exp); + }); }); describe('Isikukood as a number', () => { diff --git a/dist/isikukood.esm.js b/dist/isikukood.esm.js index d4a1da8..3314d8f 100644 --- a/dist/isikukood.esm.js +++ b/dist/isikukood.esm.js @@ -84,14 +84,15 @@ class Isikukood { } return new Date(year, month, day); } - parse(code = "") { - if (!code) { - code = this.code; - } + parse() { + return Isikukood.parse(this.code); + } + static parse(code) { + const ik = new this(code); const data = { - gender: this.getGender(), - birthDay: this.getBirthday(), - age: this.getAge() + gender: ik.getGender(), + birthDay: ik.getBirthday(), + age: ik.getAge() }; return data; } diff --git a/dist/isikukood.esm.min.js b/dist/isikukood.esm.min.js index c7cb0d1..1a9af3c 100644 --- a/dist/isikukood.esm.min.js +++ b/dist/isikukood.esm.min.js @@ -1,3 +1,3 @@ "use strict";// isikukood.esm.js, https://github.com/dknight/Isikukood-js -class u{constructor(t){this._code=String(t)}get code(){return this._code}set code(t){this._code=String(t)}getControlNumber(t=""){t||(t=this.code);const r=[1,2,3,4,5,6,7,8,9,1],i=[3,4,5,6,7,8,9,1,2,3];let o=0,n=0;for(let e=0;e<10;++e)n+=Number(t.charAt(e))*r[e];if(o=n%11,n=0,o===10){for(let e=0;e<10;++e)n+=Number(t.charAt(e))*i[e];o=n%11,o===10&&(o=0)}return o}validate(){if(this.code.charAt(0)==="0"||this.code.length!==11||this.getControlNumber()!==Number(this.code.charAt(10)))return!1;const r=Number(this.code.substring(1,3)),i=Number(this.code.substring(3,5)),o=Number(this.code.substring(5,7)),n=this.getBirthday();return r===n.getFullYear()%100&&n.getMonth()+1===i&&o===n.getDate()}getGender(){const t=this.code.charAt(0);let r;switch(t){case"1":case"3":case"5":r=s.MALE;break;case"2":case"4":case"6":r=s.FEMALE;break;default:r=s.UNKNOWN}return r}getAge(){return Math.floor((Date.now()-this.getBirthday().getTime())/(86400*1e3)/365.25)}getBirthday(){let t=Number(this.code.substring(1,3));const r=Number(this.code.substring(3,5).replace(/^0/,""))-1,i=Number(this.code.substring(5,7).replace(/^0/,"")),o=this.code.charAt(0);for(let n=1,e=1800;n<=8;n+=2,e+=100)[n,n+1].map(String).includes(o)&&(t+=e);return new Date(t,r,i)}parse(t=""){return t||(t=this.code),{gender:this.getGender(),birthDay:this.getBirthday(),age:this.getAge()}}static generate(t={}){let r,i,o;const n=t.gender||(Math.round(Math.random())===0?s.MALE:s.FEMALE);let e="";const l=["00","01","02","22","27","37","42","47","49","52","57","60","65","70","95"];if(![s.MALE,s.FEMALE].includes(n))return"";if(t.birthYear?r=t.birthYear:r=Math.round(Math.random()*100+1900+(new Date().getFullYear()-2e3)),t.birthMonth?i=t.birthMonth:i=Math.floor(Math.random()*12)+1,t.birthDay)o=t.birthDay;else{const a=new Date(r,i,0).getDate();o=Math.floor(Math.random()*a)+1}for(let a=1800,c=2;a<=2100;a+=100,c+=2)if(r>=a&&r(h.MALE="male",h.FEMALE="female",h.UNKNOWN="unknown",h))(s||{});export{s as Gender,u as default}; +class l{constructor(t){this._code=String(t)}get code(){return this._code}set code(t){this._code=String(t)}getControlNumber(t=""){t||(t=this.code);const r=[1,2,3,4,5,6,7,8,9,1],s=[3,4,5,6,7,8,9,1,2,3];let o=0,n=0;for(let e=0;e<10;++e)n+=Number(t.charAt(e))*r[e];if(o=n%11,n=0,o===10){for(let e=0;e<10;++e)n+=Number(t.charAt(e))*s[e];o=n%11,o===10&&(o=0)}return o}validate(){if(this.code.charAt(0)==="0"||this.code.length!==11||this.getControlNumber()!==Number(this.code.charAt(10)))return!1;const r=Number(this.code.substring(1,3)),s=Number(this.code.substring(3,5)),o=Number(this.code.substring(5,7)),n=this.getBirthday();return r===n.getFullYear()%100&&n.getMonth()+1===s&&o===n.getDate()}getGender(){const t=this.code.charAt(0);let r;switch(t){case"1":case"3":case"5":r=a.MALE;break;case"2":case"4":case"6":r=a.FEMALE;break;default:r=a.UNKNOWN}return r}getAge(){return Math.floor((Date.now()-this.getBirthday().getTime())/(86400*1e3)/365.25)}getBirthday(){let t=Number(this.code.substring(1,3));const r=Number(this.code.substring(3,5).replace(/^0/,""))-1,s=Number(this.code.substring(5,7).replace(/^0/,"")),o=this.code.charAt(0);for(let n=1,e=1800;n<=8;n+=2,e+=100)[n,n+1].map(String).includes(o)&&(t+=e);return new Date(t,r,s)}parse(){return l.parse(this.code)}static parse(t){const r=new this(t);return{gender:r.getGender(),birthDay:r.getBirthday(),age:r.getAge()}}static generate(t={}){let r,s,o;const n=t.gender||(Math.round(Math.random())===0?a.MALE:a.FEMALE);let e="";const u=["00","01","02","22","27","37","42","47","49","52","57","60","65","70","95"];if(![a.MALE,a.FEMALE].includes(n))return"";if(t.birthYear?r=t.birthYear:r=Math.round(Math.random()*100+1900+(new Date().getFullYear()-2e3)),t.birthMonth?s=t.birthMonth:s=Math.floor(Math.random()*12)+1,t.birthDay)o=t.birthDay;else{const i=new Date(r,s,0).getDate();o=Math.floor(Math.random()*i)+1}for(let i=1800,c=2;i<=2100;i+=100,c+=2)if(r>=i&&r(h.MALE="male",h.FEMALE="female",h.UNKNOWN="unknown",h))(a||{});export{a as Gender,l as default}; //# sourceMappingURL=isikukood.esm.min.js.map diff --git a/dist/isikukood.esm.min.js.map b/dist/isikukood.esm.min.js.map index ca2928d..6959bff 100644 --- a/dist/isikukood.esm.min.js.map +++ b/dist/isikukood.esm.min.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["isikukood.esm.js"], - "sourcesContent": ["\"use strict\";\nclass Isikukood {\n constructor(c) {\n this._code = String(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 mul1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];\n const mul2 = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];\n let controlNum = 0;\n let total = 0;\n for (let i = 0; i < 10; ++i) {\n total += Number(code.charAt(i)) * mul1[i];\n }\n controlNum = total % 11;\n total = 0;\n if (controlNum === 10) {\n for (let i = 0; i < 10; ++i) {\n total += Number(code.charAt(i)) * mul2[i];\n }\n controlNum = total % 11;\n if (controlNum === 10) {\n controlNum = 0;\n }\n }\n return controlNum;\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 !== Number(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 genderNum = this.code.charAt(0);\n let retval;\n switch (genderNum) {\n case \"1\":\n case \"3\":\n case \"5\":\n retval = Gender.MALE;\n break;\n case \"2\":\n case \"4\":\n case \"6\":\n retval = Gender.FEMALE;\n break;\n default:\n retval = Gender.UNKNOWN;\n }\n return retval;\n }\n getAge() {\n return Math.floor((Date.now() - this.getBirthday().getTime()) / (86400 * 1e3) / 365.25);\n }\n getBirthday() {\n let year = Number(this.code.substring(1, 3));\n const month = Number(this.code.substring(3, 5).replace(/^0/, \"\")) - 1;\n const day = Number(this.code.substring(5, 7).replace(/^0/, \"\"));\n const firstNumber = this.code.charAt(0);\n for (let i = 1, j = 1800; i <= 8; i += 2, j += 100) {\n if ([i, i + 1].map(String).includes(firstNumber)) {\n year += j;\n }\n }\n return new Date(year, month, day);\n }\n parse(code = \"\") {\n if (!code) {\n code = this.code;\n }\n const data = {\n gender: this.getGender(),\n birthDay: this.getBirthday(),\n age: this.getAge()\n };\n return data;\n }\n static generate(params = {}) {\n let y;\n let m;\n let d;\n const gender = params.gender || (Math.round(Math.random()) === 0 ? Gender.MALE : 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 (![Gender.MALE, 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 const daysInMonth = new Date(y, m, 0).getDate();\n d = Math.floor(Math.random() * daysInMonth) + 1;\n }\n for (let i = 1800, j = 2; i <= 2100; i += 100, j += 2) {\n if (y >= i && y < i + 100) {\n switch (gender) {\n case Gender.MALE:\n personalId += String(j - 1);\n break;\n case Gender.FEMALE:\n personalId += String(j);\n break;\n default:\n return \"\";\n }\n }\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 += String(Math.floor(Math.random() * 10));\n personalId += String(this.prototype.getControlNumber(personalId));\n return personalId;\n }\n}\nvar Gender = /* @__PURE__ */ ((Gender2) => {\n Gender2[\"MALE\"] = \"male\";\n Gender2[\"FEMALE\"] = \"female\";\n Gender2[\"UNKNOWN\"] = \"unknown\";\n return Gender2;\n})(Gender || {});\nexport {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AAM,EAC/C,MAAO,GAYT,GAVA,AAAI,EAAO,UACT,EAAI,EAAO,UAEX,EAAI,KAAK,MAAM,KAAK,OAAO,EAAI,IAAM,KAAQ,IAAI,MAAK,EAAE,YAAY,EAAI,IAAI,EAE9E,AAAI,EAAO,WACT,EAAI,EAAO,WAEX,EAAI,KAAK,MAAM,KAAK,OAAO,EAAI,EAAE,EAAI,EAEnC,EAAO,SACT,EAAI,EAAO,aACN,CACL,KAAM,GAAc,GAAI,MAAK,EAAG,EAAG,CAAC,EAAE,QAAQ,EAC9C,EAAI,KAAK,MAAM,KAAK,OAAO,EAAI,CAAW,EAAI,CAChD,CACA,OAAS,GAAI,KAAM,EAAI,EAAG,GAAK,KAAM,GAAK,IAAK,GAAK,EAClD,GAAI,GAAK,GAAK,EAAI,EAAI,IACpB,OAAQ,OACD,GAAO,KACV,GAAc,OAAO,EAAI,CAAC,EAC1B,UACG,GAAO,OACV,GAAc,OAAO,CAAC,EACtB,cAEA,MAAO,GAIf,UAAc,OAAO,CAAC,EAAE,UAAU,EAAG,CAAC,EACtC,GAAc,OAAO,CAAC,EAAE,SAAW,EAAI,IAAI,IAAM,GAAG,IACpD,GAAc,OAAO,CAAC,EAAE,SAAW,EAAI,IAAI,IAAM,GAAG,IACpD,GAAc,EAAU,KAAK,MAAM,KAAK,OAAO,EAAI,EAAU,MAAM,GACnE,GAAc,OAAO,KAAK,MAAM,KAAK,OAAO,EAAI,EAAE,CAAC,EACnD,GAAc,OAAO,KAAK,UAAU,iBAAiB,CAAU,CAAC,EACzD,CACT,CACF,CACA,GAAI,GAA0B,CAAC,GAC7B,GAAQ,KAAU,OAClB,EAAQ,OAAY,SACpB,EAAQ,QAAa,UACd,IACN,GAAU,CAAC,CAAC,EACf", + "sourcesContent": ["\"use strict\";\nclass Isikukood {\n constructor(c) {\n this._code = String(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 mul1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];\n const mul2 = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];\n let controlNum = 0;\n let total = 0;\n for (let i = 0; i < 10; ++i) {\n total += Number(code.charAt(i)) * mul1[i];\n }\n controlNum = total % 11;\n total = 0;\n if (controlNum === 10) {\n for (let i = 0; i < 10; ++i) {\n total += Number(code.charAt(i)) * mul2[i];\n }\n controlNum = total % 11;\n if (controlNum === 10) {\n controlNum = 0;\n }\n }\n return controlNum;\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 !== Number(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 genderNum = this.code.charAt(0);\n let retval;\n switch (genderNum) {\n case \"1\":\n case \"3\":\n case \"5\":\n retval = Gender.MALE;\n break;\n case \"2\":\n case \"4\":\n case \"6\":\n retval = Gender.FEMALE;\n break;\n default:\n retval = Gender.UNKNOWN;\n }\n return retval;\n }\n getAge() {\n return Math.floor((Date.now() - this.getBirthday().getTime()) / (86400 * 1e3) / 365.25);\n }\n getBirthday() {\n let year = Number(this.code.substring(1, 3));\n const month = Number(this.code.substring(3, 5).replace(/^0/, \"\")) - 1;\n const day = Number(this.code.substring(5, 7).replace(/^0/, \"\"));\n const firstNumber = this.code.charAt(0);\n for (let i = 1, j = 1800; i <= 8; i += 2, j += 100) {\n if ([i, i + 1].map(String).includes(firstNumber)) {\n year += j;\n }\n }\n return new Date(year, month, day);\n }\n parse() {\n return Isikukood.parse(this.code);\n }\n static parse(code) {\n const ik = new this(code);\n const data = {\n gender: ik.getGender(),\n birthDay: ik.getBirthday(),\n age: ik.getAge()\n };\n return data;\n }\n static generate(params = {}) {\n let y;\n let m;\n let d;\n const gender = params.gender || (Math.round(Math.random()) === 0 ? Gender.MALE : 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 (![Gender.MALE, 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 const daysInMonth = new Date(y, m, 0).getDate();\n d = Math.floor(Math.random() * daysInMonth) + 1;\n }\n for (let i = 1800, j = 2; i <= 2100; i += 100, j += 2) {\n if (y >= i && y < i + 100) {\n switch (gender) {\n case Gender.MALE:\n personalId += String(j - 1);\n break;\n case Gender.FEMALE:\n personalId += String(j);\n break;\n default:\n return \"\";\n }\n }\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 += String(Math.floor(Math.random() * 10));\n personalId += String(this.prototype.getControlNumber(personalId));\n return personalId;\n }\n}\nvar Gender = /* @__PURE__ */ ((Gender2) => {\n Gender2[\"MALE\"] = \"male\";\n Gender2[\"FEMALE\"] = \"female\";\n Gender2[\"UNKNOWN\"] = \"unknown\";\n return Gender2;\n})(Gender || {});\nexport {\n Gender,\n Isikukood as default\n};\n"], + "mappings": ";AACA,MAAM,CAAU,CACd,YAAY,EAAG,CACb,KAAK,MAAQ,OAAO,CAAC,CACvB,CACA,GAAI,OAAO,CACT,MAAO,MAAK,KACd,CACA,GAAI,MAAK,EAAG,CACV,KAA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AAQ,IAAI,MAAK,EAAE,YAAY,EAAI,IAAI,EAE9E,AAAI,EAAO,WACT,EAAI,EAAO,WAEX,EAAI,KAAK,MAAM,KAAK,OAAO,EAAI,EAAE,EAAI,EAEnC,EAAO,SACT,EAAI,EAAO,aACN,CACL,KAAM,GAAc,GAAI,MAAK,EAAG,EAAG,CAAC,EAAE,QAAQ,EAC9C,EAAI,KAAK,MAAM,KAAK,OAAO,EAAI,CAAW,EAAI,CAChD,CACA,OAAS,GAAI,KAAM,EAAI,EAAG,GAAK,KAAM,GAAK,IAAK,GAAK,EAClD,GAAI,GAAK,GAAK,EAAI,EAAI,IACpB,OAAQ,OACD,GAAO,KACV,GAAc,OAAO,EAAI,CAAC,EAC1B,UACG,GAAO,OACV,GAAc,OAAO,CAAC,EACtB,cAEA,MAAO,GAIf,UAAc,OAAO,CAAC,EAAE,UAAU,EAAG,CAAC,EACtC,GAAc,OAAO,CAAC,EAAE,SAAW,EAAI,IAAI,IAAM,GAAG,IACpD,GAAc,OAAO,CAAC,EAAE,SAAW,EAAI,IAAI,IAAM,GAAG,IACpD,GAAc,EAAU,KAAK,MAAM,KAAK,OAAO,EAAI,EAAU,MAAM,GACnE,GAAc,OAAO,KAAK,MAAM,KAAK,OAAO,EAAI,EAAE,CAAC,EACnD,GAAc,OAAO,KAAK,UAAU,iBAAiB,CAAU,CAAC,EACzD,CACT,CACF,CACA,GAAI,GAA0B,CAAC,GAC7B,GAAQ,KAAU,OAClB,EAAQ,OAAY,SACpB,EAAQ,QAAa,UACd,IACN,GAAU,CAAC,CAAC,EACf", "names": [] } diff --git a/dist/isikukood.js b/dist/isikukood.js index a7ac184..eeb0a9e 100644 --- a/dist/isikukood.js +++ b/dist/isikukood.js @@ -107,14 +107,15 @@ var Isikukood = (() => { } return new Date(year, month, day); } - parse(code = "") { - if (!code) { - code = this.code; - } + parse() { + return Isikukood.parse(this.code); + } + static parse(code) { + const ik = new this(code); const data = { - gender: this.getGender(), - birthDay: this.getBirthday(), - age: this.getAge() + gender: ik.getGender(), + birthDay: ik.getBirthday(), + age: ik.getAge() }; return data; } diff --git a/dist/isikukood.min.js b/dist/isikukood.min.js index f8b4365..360a554 100644 --- a/dist/isikukood.min.js +++ b/dist/isikukood.min.js @@ -1,3 +1,3 @@ "use strict";// isikukood.js, https://github.com/dknight/Isikukood-js -var Isikukood=(()=>{var c=Object.defineProperty,d=Object.getOwnPropertyDescriptor,b=Object.getOwnPropertyNames,f=Object.prototype.hasOwnProperty,M=(i,t)=>{for(var e in t)c(i,e,{get:t[e],enumerable:!0})},m=(i,t,e,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of b(t))!f.call(i,o)&&o!==e&&c(i,o,{get:()=>t[o],enumerable:!(a=d(t,o))||a.enumerable});return i},y=i=>m(c({},"__esModule",{value:!0}),i),l={};M(l,{Gender:()=>s,default:()=>N});class N{constructor(t){this._code=String(t)}get code(){return this._code}set code(t){this._code=String(t)}getControlNumber(t=""){t||(t=this.code);const e=[1,2,3,4,5,6,7,8,9,1],a=[3,4,5,6,7,8,9,1,2,3];let o=0,n=0;for(let r=0;r<10;++r)n+=Number(t.charAt(r))*e[r];if(o=n%11,n=0,o===10){for(let r=0;r<10;++r)n+=Number(t.charAt(r))*a[r];o=n%11,o===10&&(o=0)}return o}validate(){if(this.code.charAt(0)==="0"||this.code.length!==11||this.getControlNumber()!==Number(this.code.charAt(10)))return!1;const e=Number(this.code.substring(1,3)),a=Number(this.code.substring(3,5)),o=Number(this.code.substring(5,7)),n=this.getBirthday();return e===n.getFullYear()%100&&n.getMonth()+1===a&&o===n.getDate()}getGender(){const t=this.code.charAt(0);let e;switch(t){case"1":case"3":case"5":e=s.MALE;break;case"2":case"4":case"6":e=s.FEMALE;break;default:e=s.UNKNOWN}return e}getAge(){return Math.floor((Date.now()-this.getBirthday().getTime())/864e5/365.25)}getBirthday(){let t=Number(this.code.substring(1,3));const e=Number(this.code.substring(3,5).replace(/^0/,""))-1,a=Number(this.code.substring(5,7).replace(/^0/,"")),o=this.code.charAt(0);for(let n=1,r=1800;n<=8;n+=2,r+=100)[n,n+1].map(String).includes(o)&&(t+=r);return new Date(t,e,a)}parse(t=""){return t||(t=this.code),{gender:this.getGender(),birthDay:this.getBirthday(),age:this.getAge()}}static generate(t={}){let e,a,o;const n=t.gender||(Math.round(Math.random())===0?s.MALE:s.FEMALE);let r="";const g=["00","01","02","22","27","37","42","47","49","52","57","60","65","70","95"];if(![s.MALE,s.FEMALE].includes(n))return"";if(t.birthYear?e=t.birthYear:e=Math.round(Math.random()*100+1900+(new Date().getFullYear()-2e3)),t.birthMonth?a=t.birthMonth:a=Math.floor(Math.random()*12)+1,t.birthDay)o=t.birthDay;else{const h=new Date(e,a,0).getDate();o=Math.floor(Math.random()*h)+1}for(let h=1800,u=2;h<=2100;h+=100,u+=2)if(e>=h&&e(i.MALE="male",i.FEMALE="female",i.UNKNOWN="unknown",i))(s||{});return y(l)})();window.Isikukood=Isikukood.default; +var Isikukood=(()=>{var h=Object.defineProperty,b=Object.getOwnPropertyDescriptor,f=Object.getOwnPropertyNames,M=Object.prototype.hasOwnProperty,m=(s,t)=>{for(var e in t)h(s,e,{get:t[e],enumerable:!0})},y=(s,t,e,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of f(t))!M.call(s,n)&&n!==e&&h(s,n,{get:()=>t[n],enumerable:!(a=b(t,n))||a.enumerable});return s},N=s=>y(h({},"__esModule",{value:!0}),s),g={};m(g,{Gender:()=>i,default:()=>u});class u{constructor(t){this._code=String(t)}get code(){return this._code}set code(t){this._code=String(t)}getControlNumber(t=""){t||(t=this.code);const e=[1,2,3,4,5,6,7,8,9,1],a=[3,4,5,6,7,8,9,1,2,3];let n=0,o=0;for(let r=0;r<10;++r)o+=Number(t.charAt(r))*e[r];if(n=o%11,o=0,n===10){for(let r=0;r<10;++r)o+=Number(t.charAt(r))*a[r];n=o%11,n===10&&(n=0)}return n}validate(){if(this.code.charAt(0)==="0"||this.code.length!==11||this.getControlNumber()!==Number(this.code.charAt(10)))return!1;const e=Number(this.code.substring(1,3)),a=Number(this.code.substring(3,5)),n=Number(this.code.substring(5,7)),o=this.getBirthday();return e===o.getFullYear()%100&&o.getMonth()+1===a&&n===o.getDate()}getGender(){const t=this.code.charAt(0);let e;switch(t){case"1":case"3":case"5":e=i.MALE;break;case"2":case"4":case"6":e=i.FEMALE;break;default:e=i.UNKNOWN}return e}getAge(){return Math.floor((Date.now()-this.getBirthday().getTime())/864e5/365.25)}getBirthday(){let t=Number(this.code.substring(1,3));const e=Number(this.code.substring(3,5).replace(/^0/,""))-1,a=Number(this.code.substring(5,7).replace(/^0/,"")),n=this.code.charAt(0);for(let o=1,r=1800;o<=8;o+=2,r+=100)[o,o+1].map(String).includes(n)&&(t+=r);return new Date(t,e,a)}parse(){return u.parse(this.code)}static parse(t){const e=new this(t);return{gender:e.getGender(),birthDay:e.getBirthday(),age:e.getAge()}}static generate(t={}){let e,a,n;const o=t.gender||(Math.round(Math.random())===0?i.MALE:i.FEMALE);let r="";const d=["00","01","02","22","27","37","42","47","49","52","57","60","65","70","95"];if(![i.MALE,i.FEMALE].includes(o))return"";if(t.birthYear?e=t.birthYear:e=Math.round(Math.random()*100+1900+(new Date().getFullYear()-2e3)),t.birthMonth?a=t.birthMonth:a=Math.floor(Math.random()*12)+1,t.birthDay)n=t.birthDay;else{const c=new Date(e,a,0).getDate();n=Math.floor(Math.random()*c)+1}for(let c=1800,l=2;c<=2100;c+=100,l+=2)if(e>=c&&e(s.MALE="male",s.FEMALE="female",s.UNKNOWN="unknown",s))(i||{});return N(g)})();window.Isikukood=Isikukood.default; //# sourceMappingURL=isikukood.min.js.map diff --git a/dist/isikukood.min.js.map b/dist/isikukood.min.js.map index 96c6c15..7b36f19 100644 --- a/dist/isikukood.min.js.map +++ b/dist/isikukood.min.js.map @@ -1,7 +1,7 @@ { "version": 3, "sources": ["isikukood.js"], - "sourcesContent": ["\"use strict\";\nvar Isikukood = (() => {\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 Gender: () => Gender,\n default: () => Isikukood\n });\n class Isikukood {\n constructor(c) {\n this._code = String(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 mul1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];\n const mul2 = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];\n let controlNum = 0;\n let total = 0;\n for (let i = 0; i < 10; ++i) {\n total += Number(code.charAt(i)) * mul1[i];\n }\n controlNum = total % 11;\n total = 0;\n if (controlNum === 10) {\n for (let i = 0; i < 10; ++i) {\n total += Number(code.charAt(i)) * mul2[i];\n }\n controlNum = total % 11;\n if (controlNum === 10) {\n controlNum = 0;\n }\n }\n return controlNum;\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 !== Number(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 genderNum = this.code.charAt(0);\n let retval;\n switch (genderNum) {\n case \"1\":\n case \"3\":\n case \"5\":\n retval = Gender.MALE;\n break;\n case \"2\":\n case \"4\":\n case \"6\":\n retval = Gender.FEMALE;\n break;\n default:\n retval = Gender.UNKNOWN;\n }\n return retval;\n }\n getAge() {\n return Math.floor((Date.now() - this.getBirthday().getTime()) / (86400 * 1e3) / 365.25);\n }\n getBirthday() {\n let year = Number(this.code.substring(1, 3));\n const month = Number(this.code.substring(3, 5).replace(/^0/, \"\")) - 1;\n const day = Number(this.code.substring(5, 7).replace(/^0/, \"\"));\n const firstNumber = this.code.charAt(0);\n for (let i = 1, j = 1800; i <= 8; i += 2, j += 100) {\n if ([i, i + 1].map(String).includes(firstNumber)) {\n year += j;\n }\n }\n return new Date(year, month, day);\n }\n parse(code = \"\") {\n if (!code) {\n code = this.code;\n }\n const data = {\n gender: this.getGender(),\n birthDay: this.getBirthday(),\n age: this.getAge()\n };\n return data;\n }\n static generate(params = {}) {\n let y;\n let m;\n let d;\n const gender = params.gender || (Math.round(Math.random()) === 0 ? Gender.MALE : 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 (![Gender.MALE, 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 const daysInMonth = new Date(y, m, 0).getDate();\n d = Math.floor(Math.random() * daysInMonth) + 1;\n }\n for (let i = 1800, j = 2; i <= 2100; i += 100, j += 2) {\n if (y >= i && y < i + 100) {\n switch (gender) {\n case Gender.MALE:\n personalId += String(j - 1);\n break;\n case Gender.FEMALE:\n personalId += String(j);\n break;\n default:\n return \"\";\n }\n }\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 += String(Math.floor(Math.random() * 10));\n personalId += String(this.prototype.getControlNumber(personalId));\n return personalId;\n }\n }\n var Gender = /* @__PURE__ */ ((Gender2) => {\n Gender2[\"MALE\"] = \"male\";\n Gender2[\"FEMALE\"] = \"female\";\n Gender2[\"UNKNOWN\"] = \"unknown\";\n return Gender2;\n })(Gender || {});\n return __toCommonJS(isikukood_exports);\n})();\nwindow.Isikukood=Isikukood.default;\n"], - "mappings": ";AACA,GAAI,WAAa,KAAM,CACrB,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,OAAQ,IAAM,EACd,QAAS,IAAM,CACjB,CAAC,EACD,MAAM,CAAU,CACd,YAAY,EAAG,CACb,KAAK,MA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AAO,EAAI,IAAM,KAAQ,IAAI,MAAK,EAAE,YAAY,EAAI,IAAI,EAE9E,AAAI,EAAO,WACT,EAAI,EAAO,WAEX,EAAI,KAAK,MAAM,KAAK,OAAO,EAAI,EAAE,EAAI,EAEnC,EAAO,SACT,EAAI,EAAO,aACN,CACL,KAAM,GAAc,GAAI,MAAK,EAAG,EAAG,CAAC,EAAE,QAAQ,EAC9C,EAAI,KAAK,MAAM,KAAK,OAAO,EAAI,CAAW,EAAI,CAChD,CACA,OAAS,GAAI,KAAM,EAAI,EAAG,GAAK,KAAM,GAAK,IAAK,GAAK,EAClD,GAAI,GAAK,GAAK,EAAI,EAAI,IACpB,OAAQ,OACD,GAAO,KACV,GAAc,OAAO,EAAI,CAAC,EAC1B,UACG,GAAO,OACV,GAAc,OAAO,CAAC,EACtB,cAEA,MAAO,GAIf,UAAc,OAAO,CAAC,EAAE,UAAU,EAAG,CAAC,EACtC,GAAc,OAAO,CAAC,EAAE,SAAW,EAAI,IAAI,IAAM,GAAG,IACpD,GAAc,OAAO,CAAC,EAAE,SAAW,EAAI,IAAI,IAAM,GAAG,IACpD,GAAc,EAAU,KAAK,MAAM,KAAK,OAAO,EAAI,EAAU,MAAM,GACnE,GAAc,OAAO,KAAK,MAAM,KAAK,OAAO,EAAI,EAAE,CAAC,EACnD,GAAc,OAAO,KAAK,UAAU,iBAAiB,CAAU,CAAC,EACzD,CACT,CACF,CACA,GAAI,GAA0B,CAAC,GAC7B,GAAQ,KAAU,OAClB,EAAQ,OAAY,SACpB,EAAQ,QAAa,UACd,IACN,GAAU,CAAC,CAAC,EACf,MAAO,GAAa,CAAiB,CACvC,GAAG,EACH,OAAO,UAAU,UAAU", + "sourcesContent": ["\"use strict\";\nvar Isikukood = (() => {\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 Gender: () => Gender,\n default: () => Isikukood\n });\n class Isikukood {\n constructor(c) {\n this._code = String(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 mul1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];\n const mul2 = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];\n let controlNum = 0;\n let total = 0;\n for (let i = 0; i < 10; ++i) {\n total += Number(code.charAt(i)) * mul1[i];\n }\n controlNum = total % 11;\n total = 0;\n if (controlNum === 10) {\n for (let i = 0; i < 10; ++i) {\n total += Number(code.charAt(i)) * mul2[i];\n }\n controlNum = total % 11;\n if (controlNum === 10) {\n controlNum = 0;\n }\n }\n return controlNum;\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 !== Number(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 genderNum = this.code.charAt(0);\n let retval;\n switch (genderNum) {\n case \"1\":\n case \"3\":\n case \"5\":\n retval = Gender.MALE;\n break;\n case \"2\":\n case \"4\":\n case \"6\":\n retval = Gender.FEMALE;\n break;\n default:\n retval = Gender.UNKNOWN;\n }\n return retval;\n }\n getAge() {\n return Math.floor((Date.now() - this.getBirthday().getTime()) / (86400 * 1e3) / 365.25);\n }\n getBirthday() {\n let year = Number(this.code.substring(1, 3));\n const month = Number(this.code.substring(3, 5).replace(/^0/, \"\")) - 1;\n const day = Number(this.code.substring(5, 7).replace(/^0/, \"\"));\n const firstNumber = this.code.charAt(0);\n for (let i = 1, j = 1800; i <= 8; i += 2, j += 100) {\n if ([i, i + 1].map(String).includes(firstNumber)) {\n year += j;\n }\n }\n return new Date(year, month, day);\n }\n parse() {\n return Isikukood.parse(this.code);\n }\n static parse(code) {\n const ik = new this(code);\n const data = {\n gender: ik.getGender(),\n birthDay: ik.getBirthday(),\n age: ik.getAge()\n };\n return data;\n }\n static generate(params = {}) {\n let y;\n let m;\n let d;\n const gender = params.gender || (Math.round(Math.random()) === 0 ? Gender.MALE : 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 (![Gender.MALE, 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 const daysInMonth = new Date(y, m, 0).getDate();\n d = Math.floor(Math.random() * daysInMonth) + 1;\n }\n for (let i = 1800, j = 2; i <= 2100; i += 100, j += 2) {\n if (y >= i && y < i + 100) {\n switch (gender) {\n case Gender.MALE:\n personalId += String(j - 1);\n break;\n case Gender.FEMALE:\n personalId += String(j);\n break;\n default:\n return \"\";\n }\n }\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 += String(Math.floor(Math.random() * 10));\n personalId += String(this.prototype.getControlNumber(personalId));\n return personalId;\n }\n }\n var Gender = /* @__PURE__ */ ((Gender2) => {\n Gender2[\"MALE\"] = \"male\";\n Gender2[\"FEMALE\"] = \"female\";\n Gender2[\"UNKNOWN\"] = \"unknown\";\n return Gender2;\n })(Gender || {});\n return __toCommonJS(isikukood_exports);\n})();\nwindow.Isikukood=Isikukood.default;\n"], + "mappings": ";AACA,GAAI,WAAa,KAAM,CACrB,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,OAAQ,IAAM,EACd,QAAS,IAAM,CACjB,CAAC,EACD,MAAM,CAAU,CACd,YAAY,EAAG,CACb,KAAK,MAAQ,OAAO,CAAC,CACvB,CACA,GAAI,OAAO,CACT,MAAO,MAAK,KACd,CACA,GAAI,MAAK,EAAG,CACV,KAAK,M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,MAAK,EAAE,YAAY,EAAI,IAAI,EAE9E,AAAI,EAAO,WACT,EAAI,EAAO,WAEX,EAAI,KAAK,MAAM,KAAK,OAAO,EAAI,EAAE,EAAI,EAEnC,EAAO,SACT,EAAI,EAAO,aACN,CACL,KAAM,GAAc,GAAI,MAAK,EAAG,EAAG,CAAC,EAAE,QAAQ,EAC9C,EAAI,KAAK,MAAM,KAAK,OAAO,EAAI,CAAW,EAAI,CAChD,CACA,OAAS,GAAI,KAAM,EAAI,EAAG,GAAK,KAAM,GAAK,IAAK,GAAK,EAClD,GAAI,GAAK,GAAK,EAAI,EAAI,IACpB,OAAQ,OACD,GAAO,KACV,GAAc,OAAO,EAAI,CAAC,EAC1B,UACG,GAAO,OACV,GAAc,OAAO,CAAC,EACtB,cAEA,MAAO,GAIf,UAAc,OAAO,CAAC,EAAE,UAAU,EAAG,CAAC,EACtC,GAAc,OAAO,CAAC,EAAE,SAAW,EAAI,IAAI,IAAM,GAAG,IACpD,GAAc,OAAO,CAAC,EAAE,SAAW,EAAI,IAAI,IAAM,GAAG,IACpD,GAAc,EAAU,KAAK,MAAM,KAAK,OAAO,EAAI,EAAU,MAAM,GACnE,GAAc,OAAO,KAAK,MAAM,KAAK,OAAO,EAAI,EAAE,CAAC,EACnD,GAAc,OAAO,KAAK,UAAU,iBAAiB,CAAU,CAAC,EACzD,CACT,CACF,CACA,GAAI,GAA0B,CAAC,GAC7B,GAAQ,KAAU,OAClB,EAAQ,OAAY,SACpB,EAAQ,QAAa,UACd,IACN,GAAU,CAAC,CAAC,EACf,MAAO,GAAa,CAAiB,CACvC,GAAG,EACH,OAAO,UAAU,UAAU", "names": [] } diff --git a/docs/isikukood.esm.js b/docs/isikukood.esm.js index d4a1da8..3314d8f 100644 --- a/docs/isikukood.esm.js +++ b/docs/isikukood.esm.js @@ -84,14 +84,15 @@ class Isikukood { } return new Date(year, month, day); } - parse(code = "") { - if (!code) { - code = this.code; - } + parse() { + return Isikukood.parse(this.code); + } + static parse(code) { + const ik = new this(code); const data = { - gender: this.getGender(), - birthDay: this.getBirthday(), - age: this.getAge() + gender: ik.getGender(), + birthDay: ik.getBirthday(), + age: ik.getAge() }; return data; } diff --git a/index.ts b/index.ts index a3e57e7..e79baaf 100644 --- a/index.ts +++ b/index.ts @@ -1,3 +1,3 @@ -import Isikukood, {Gender, PersonalData} from './src/isikukood'; -export {Gender, PersonalData}; +import Isikukood, {Gender, PersonalData, GenerateInput} from './src/isikukood'; +export {Gender, PersonalData, GenerateInput}; export default Isikukood; diff --git a/package-lock.json b/package-lock.json index 3a203a5..73c86f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "isikukood", - "version": "3.0.1", + "version": "3.1.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "isikukood", - "version": "3.0.1", + "version": "3.1.0", "license": "MIT", "dependencies": { "babel-jest": "^29.5.0", diff --git a/package.json b/package.json index 5324bcf..12494e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "isikukood", - "version": "3.0.1", + "version": "3.1.0", "description": "Estonian personal ID (isikukood) JavaScript module", "main": "index.ts", "type": "module", diff --git a/src/isikukood.ts b/src/isikukood.ts index 3639b5f..e642704 100644 --- a/src/isikukood.ts +++ b/src/isikukood.ts @@ -155,14 +155,16 @@ export default class Isikukood { /** * Parses the code and return it's data as object. */ - parse(code: string = ''): PersonalData { - if (!code) { - code = this.code; - } + parse(): PersonalData { + return Isikukood.parse(this.code); + } + + static parse(code: string | number): PersonalData { + const ik: Isikukood = new this(code); const data: PersonalData = { - gender: this.getGender(), - birthDay: this.getBirthday(), - age: this.getAge(), + gender: ik.getGender(), + birthDay: ik.getBirthday(), + age: ik.getAge(), }; return data; } @@ -176,14 +178,7 @@ export default class Isikukood { * 3 - March * etc. */ - static generate( - params: { - gender?: Gender; - birthYear?: number; - birthMonth?: number; - birthDay?: number; - } = {} - ): string { + static generate(params: GenerateInput = {}): string { let y: number; let m: number; let d: number; @@ -275,11 +270,18 @@ export default class Isikukood { } export interface PersonalData { - gender: string; + gender: Gender; birthDay: Date; age: number; } +export interface GenerateInput { + gender?: Gender; + birthYear?: number; + birthMonth?: number; + birthDay?: number; +} + export enum Gender { MALE = 'male', FEMALE = 'female',