{"version":3,"file":"nationalId-1a3130bb.js","sources":["../../../client-app/src/common/lib/norwegianSsn.ts","../../../client-app/src/common/validation/no/nationalId.ts"],"sourcesContent":["\n \n function isTestSsn(ssn: string) {\n const ssnMonth = parseInt(ssn.substring(2, 4));\n if (ssnMonth > 80) {\n return true;\n }\n return false;\n }\n function convertBackToCorrectMonth(ssn: string) {\n const ssnDay = ssn.substring(0, 2);\n const ssnMonth = parseInt(ssn.substring(2, 4)) - 80;\n const ssnRest = ssn.substring(4, 11);\n const ssnMonthPadded = ('0' + ssnMonth).slice(-2);\n return ssnDay + ssnMonthPadded + ssnRest;\n }\n\n function convertToNormalIfTest(number: string) {\n \n if (isTestSsn(number)) {\n return convertBackToCorrectMonth(number);\n }\n return number;\n }\n \n function isDateValid(date: string) {\n const day = parseInt(date.substring(0, 2)),\n month = parseInt(date.substring(2, 4)),\n monthLengths = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];\n\n if (day < 1 || month < 1) {\n return false;\n }\n\n if (day > monthLengths[month - 1]) {\n return false;\n }\n\n return true;\n }\n\n function isDNumber(date: string) {\n const day = parseInt(date.substring(0, 2));\n\n if (day > 40 && day < 72) {\n return true;\n }\n return false;\n }\n\n function calculateFirstChecksum(input: string) {\n if (typeof input !== \"string\") {\n return false;\n }\n\n if (input.length !== 9) {\n return false;\n }\n\n const arr = input.split(\"\").map(function (n) {\n return parseInt(n);\n });\n\n let checksum =\n 11\n - ((3 * arr[0]\n + 7 * arr[1]\n + 6 * arr[2]\n + 1 * arr[3]\n + 8 * arr[4]\n + 9 * arr[5]\n + 4 * arr[6]\n + 5 * arr[7]\n + 2 * arr[8]\n )\n % 11\n );\n\n if (checksum === 10) {\n return false;\n }\n\n if (checksum === 11) {\n checksum = 0;\n }\n\n return checksum;\n }\n\n function calculateSecondChecksum(input: string) {\n if (typeof input !== \"string\") {\n return false;\n }\n\n if (input.length !== 10) {\n return false;\n }\n\n const arr = input.split(\"\").map(function (n) {\n return parseInt(n);\n });\n\n let checksum =\n 11\n - ((5 * arr[0]\n + 4 * arr[1]\n + 3 * arr[2]\n + 2 * arr[3]\n + 7 * arr[4]\n + 6 * arr[5]\n + 5 * arr[6]\n + 4 * arr[7]\n + 3 * arr[8]\n + 2 * arr[9]\n )\n % 11\n );\n\n if (checksum === 10) {\n return false;\n }\n\n if (checksum === 11) {\n checksum = 0;\n }\n\n return checksum;\n }\n\n export function validateNorwegianSsn(val: string) {\n if (typeof val !== \"string\") {\n return false;\n }\n const number = val.trim();\n if (number.length !== 11) {\n return false;\n }\n\n \n if (!/^\\d+$/.test(number)) {\n return false;\n }\n \n const ssnOrig = convertToNormalIfTest(number);\n\n let date = ssnOrig.substring(0, 6);\n\n if (isDNumber(ssnOrig)) {\n date = (parseInt(date.substring(0, 1), 10) - 4).toString() + date.substring(1, 6);\n }\n\n if (!isDateValid(date)) {\n return false;\n }\n\n if (calculateFirstChecksum(number.substring(0, 9)).toString() !== ssnOrig[9]) {\n return false;\n }\n\n if (calculateSecondChecksum(number.substring(0, 10)).toString() !== ssnOrig[10]) {\n return false;\n }\n\n return true;\n }\n","\nimport { validateNorwegianSsn } from '@n2-common/lib/norwegianSsn';\nimport * as Yup from 'yup';\n\nexport const norwegianNationalId =() => Yup.string().nullable().typeError('Vennligst fyll ut feltet.')\n.required('Vennligst fyll ut feltet.').test('test-norwegiannationalid', // this is used internally by yup\n'Vennligst oppgi et gyldig fødselsnummer (11 siffer)', //validation message\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n value => {\n if (!value) {\n return false;\n }\n return validateNorwegianSsn(value);\n });\n"],"names":["isTestSsn","ssn","convertBackToCorrectMonth","ssnDay","ssnMonth","ssnRest","ssnMonthPadded","convertToNormalIfTest","number","isDateValid","date","day","month","monthLengths","isDNumber","calculateFirstChecksum","input","arr","n","checksum","calculateSecondChecksum","validateNorwegianSsn","val","ssnOrig","norwegianNationalId","Yup.string","value"],"mappings":"8CAEI,SAASA,EAAUC,EAAa,CAE5B,OADiB,SAASA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