{"version":3,"file":"isValidFodselsnummer.cjs","sources":["../../../../../src/utilities/validators/isValidFodselsnummer/isValidFodselsnummer.ts"],"sourcesContent":["/**\n * MIT License\n *\n * Copyright (c) 2019 Ivar Nilsen\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \"Software\"), to deal\n * in the Software without restriction, including without limitation the rights\n * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n * copies of the Software, and to permit persons to whom the Software is\n * furnished to do so, subject to the following conditions:\n *\n * The above copyright notice and this permission notice shall be included in all\n * copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n * SOFTWARE.\n */\n// https://github.com/ivarni/ninno\n\nconst K1_FACTORS = [3, 7, 6, 1, 8, 9, 4, 5, 2];\nconst K2_FACTORS = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2];\n\nconst getChecksumDigit = (fnr: string, factors: number[]) => {\n    const sum =\n        11 -\n        (Array.from(fnr.substring(0, factors.length)).reduce(\n            (_sum, digit, i) => _sum + Number(digit) * factors[i],\n            0,\n        ) %\n            11);\n    return sum === 11 ? 0 : sum;\n};\n\nexport const getChecksumDigits = (fnr: string) => {\n    const k1 = getChecksumDigit(fnr, K1_FACTORS);\n    return [k1, getChecksumDigit(fnr + k1, K2_FACTORS)];\n};\n\n/**\n * Sjekker om verdien validerer som et gyldig fødselsnummer.\n * @param value Verdien som skal valideres\n * @returns Om verdien er et gyldig fødselsnummer\n */\nexport const isValidFodselsnummer = (value: string): boolean => {\n    if (!value || value.length !== 11 || value === \"00000000000\") {\n        return false;\n    }\n\n    if (Number(value.charAt(9)) !== getChecksumDigit(value, K1_FACTORS)) {\n        return false;\n    }\n\n    return Number(value.charAt(10)) === getChecksumDigit(value, K2_FACTORS);\n};\n"],"names":["K1_FACTORS","K2_FACTORS","getChecksumDigit","fnr","factors","sum","Array","from","substring","length","reduce","_sum","digit","i","Number","k1","value","charAt"],"mappings":"gFAyBA,MAAMA,EAAa,CAAC,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,GACtCC,EAAa,CAAC,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,EAAG,GAEzCC,EAAmB,CAACC,EAAaC,KACnC,MAAMC,EACF,GACCC,MAAMC,KAAKJ,EAAIK,UAAU,EAAGJ,EAAQK,SAASC,OAC1C,CAACC,EAAMC,EAAOC,IAAMF,EAAOG,OAAOF,GAASR,EAAQS,GACnD,GAEA,GACR,OAAe,KAARR,EAAa,EAAIA,6BAGMF,IAC9B,MAAMY,EAAKb,EAAiBC,EAAKH,GACjC,MAAO,CAACe,EAAIb,EAAiBC,EAAMY,EAAId,kCAQNe,MAC5BA,GAA0B,KAAjBA,EAAMP,QAA2B,gBAAVO,GAIjCF,OAAOE,EAAMC,OAAO,MAAQf,EAAiBc,EAAOhB,KAIjDc,OAAOE,EAAMC,OAAO,OAASf,EAAiBc,EAAOf"}