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C7B,EAAgB,MACf,IAAwB,MAApB,GAA+C,SAApB,GACT,QAApB,EAEF,IAAwB,MAApB,GAA8C,UAAnB,EAChC,OAAO,EAEP,MAAM,IAAI,MAAM,8HACqF,CALrG,EAAgB,CAKqF,CACzG,OAAO,SAAS,GAAc,IAAM,CACxC,CAEA,SAAS,iBAAiB,GACtB,MAAM,EAAe,CAAC,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,GAEpD,IAAI,EAAM,EACV,IAAI,IAAI,EAAI,EAAG,EAAI,GAAI,IACnB,GAAO,SAAS,EAAM,OAAO,IAAM,EAAa,GAEpD,MAAM,EAAc,EAAM,GAAK,GAAK,EAAM,GAAK,EAC/C,OAAO,SAAS,EAAM,OAAO,OAAS,CAC1C,CAEA,SAAS,iBAAiB,EAAU,GAChC,IAAI,EAWJ,OATI,EADD,EAAU,WAAW,MAAQ,EAAU,WAAW,KACjC,KACZ,EAAU,WAAW,MAAQ,EAAU,WAAW,KACtC,KACZ,EAAU,WAAW,MAAQ,EAAU,WAAW,KACtC,KACZ,EAAU,WAAW,MAAQ,EAAU,WAAW,KACtC,KAEA,KACb,CACX,CAEA,SAAS,gBAAgB,GACrB,OAAO,SAAS,EAAU,OAAO,IAAM,EAAI,EAAU,OAAO,EAChE,CAEA,SAAS,WAAW,EAAO,EAAa,GACpC,GAAoB,iBAAV,EACN,MAAM,IAAI,UAAU,0BACxB,GAAG,KAAiB,aAAuB,QAAU,EAAY,aACJ,kBAAhD,OAAO,UAAU,SAAS,KAAK,IAAqC,MAAM,IACnF,MAAM,IAAI,UAAU,uDACxB,GAAG,IAA6B,iBAAX,IAAwB,OAAO,KAAK,aAAa,SAAS,EAAO,gBAClF,MAAM,IAAI,UAAU,4DAA8D,OAAO,KAAK,aAAa,KAAK,MAExH","file":"/npm/pesel-validator@1.0.3/src/peselValidator.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/pesel-validator@1.0.3/src/peselValidator.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import moment from \"moment\";\r\n\r\nconst GENDER_DICT = {\r\n    male: 'm',\r\n    man: 'm',\r\n    m: 'm',\r\n    female: 'f',\r\n    woman: 'f',\r\n    f: 'f',\r\n    w: 'w',\r\n    other: 'o',\r\n    o: 'o'\r\n}\r\n\r\nexport default function peselValidator(pesel, optionalArgs) {\r\n    const {dateOfBirth = null, gender = null} = optionalArgs || {};\r\n\r\n    checkTypes(pesel, dateOfBirth, gender);\r\n    if(!(/^\\d+$/.test(pesel) && pesel.length===11))\r\n        return false;\r\n    const datePart = pesel.substring(0, 6);\r\n    const genderPart = pesel.charAt(9);\r\n\r\n    return validateDatePart(datePart) && datesEqual(datePart, dateOfBirth)\r\n        && genderEqual(genderPart, gender) && validateCheckSum(pesel);\r\n}\r\n\r\nfunction validateDatePart(datePart) {\r\n    const yearPart = datePart.substring(0, 2);\r\n    const monthPart = datePart.substring(2, 4);\r\n    const dayPart = datePart.substring(4, 6);\r\n    if(!/^[0-9][0-9]([02468][1-9]|[13579][0-2])$/.test(yearPart + monthPart))\r\n        return false;\r\n    const dayPartInt = parseInt(dayPart);\r\n    return dayPartInt > 0 && dayPartInt <=\r\n        moment(`${getYearBeginning(yearPart, monthPart)}${yearPart}-${getDecodedMonth(monthPart)}`, \"YYYY-MM\").daysInMonth();\r\n}\r\n\r\nfunction datesEqual(datePart, dateOfBirth) {\r\n    if(!dateOfBirth)\r\n        return true;\r\n    const yearPart = datePart.substring(0, 2);\r\n    const monthPart = datePart.substring(2, 4);\r\n    const dayPart = datePart.substring(4, 6);\r\n    const dateString = getYearBeginning(yearPart, monthPart) + yearPart + \"-\" + getDecodedMonth(monthPart) + \"-\" + dayPart;\r\n    return moment(dateOfBirth).isSame(dateString, \"day\");\r\n}\r\n\r\nfunction genderEqual(genderPart, gender) {\r\n    if(!gender)\r\n        return true;\r\n    const lowerCaseGender = gender.toLowerCase();\r\n    let encodedGender;\r\n    if( lowerCaseGender === 'f' || lowerCaseGender === 'female'\r\n        || lowerCaseGender ==='w' || lowerCaseGender === 'woman')\r\n        encodedGender = 0;\r\n    else if (lowerCaseGender === 'm' || lowerCaseGender === 'male'\r\n        || lowerCaseGender === 'man')\r\n        encodedGender = 1;\r\n    else if (lowerCaseGender === 'o' || lowerCaseGender ==='other')\r\n        return true;\r\n    else\r\n        throw new Error(\"Gender parameter is invalid. \" +\r\n            \"Allowed case insensitive values ('f', 'female', 'w', 'woman', 'm, 'man', 'male', 'o', 'other')\");\r\n    return parseInt(genderPart) % 2 === encodedGender;\r\n}\r\n\r\nfunction validateCheckSum(pesel) {\r\n    const indexWeights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3, 1];\r\n\r\n    let sum = 0;\r\n    for(let i = 0; i < 10; i++) {\r\n        sum += parseInt(pesel.charAt(i)) * indexWeights[i];\r\n    }\r\n    const shouldEqual = sum % 10 ? 10 - sum % 10 : 0;\r\n    return parseInt(pesel.charAt(10)) === shouldEqual;\r\n}\r\n\r\nfunction getYearBeginning(yearPart, monthPart) {\r\n    let yearBeginning;\r\n    if(monthPart.startsWith('8') || monthPart.startsWith('9'))\r\n        yearBeginning = '18';\r\n    else if(monthPart.startsWith('0') || monthPart.startsWith('1'))\r\n        yearBeginning = '19';\r\n    else if(monthPart.startsWith('2') || monthPart.startsWith('3'))\r\n        yearBeginning = '20';\r\n    else if(monthPart.startsWith('4') || monthPart.startsWith('5'))\r\n        yearBeginning = '21';\r\n    else\r\n        yearBeginning = '22';\r\n    return yearBeginning;\r\n}\r\n\r\nfunction getDecodedMonth(monthPart) {\r\n    return parseInt(monthPart.charAt(0)) % 2 + monthPart.charAt(1);\r\n}\r\n\r\nfunction checkTypes(pesel, dateOfBirth, gender) {\r\n    if(typeof pesel !== 'string')\r\n        throw new TypeError(\"Pesel must be a string\")\r\n    if(dateOfBirth && !(dateOfBirth instanceof moment && dateOfBirth.isValid())\r\n            && !(Object.prototype.toString.call(dateOfBirth) === \"[object Date]\" && !isNaN(dateOfBirth)))\r\n        throw new TypeError(\"Date of birth must be a valid Date or Moment object\")\r\n    if(gender && (typeof gender !== 'string' || !Object.keys(GENDER_DICT).includes(gender.toLowerCase())))\r\n        throw new TypeError(\"Gender must be a string with one of the following values \" + Object.keys(GENDER_DICT).join(', '));\r\n\r\n}"]}