|
| 1 | +module.exports = (inc, contents) => { |
| 2 | + const pic = contents.picture; |
| 3 | + delete contents.picture; |
| 4 | + |
| 5 | + include(inc, 'phone', randomItem([2, 3, 5, 6, 7, 8]) + random(3, 7)); |
| 6 | + include(inc, 'cell', randomItem([4, 9]) + random(3, 7)); |
| 7 | + include(inc, 'id', () => { |
| 8 | + const dobDate = new Date(contents.dob), |
| 9 | + dobISO = dobDate.toISOString(), |
| 10 | + birthDate = dobISO.substr(8, 2) + dobISO.substr(5, 2) + dobISO.substr(2, 2); |
| 11 | + |
| 12 | + const calculateCheckDigits = (tenDigits) => { |
| 13 | + const checkDigit = (staticSequence, input) => { |
| 14 | + input = input.split('').map(Number); |
| 15 | + let productSum = staticSequence.reduce((acc, value, index) => { |
| 16 | + return acc + value * input[index]; |
| 17 | + }, 0); |
| 18 | + |
| 19 | + const sumMod11 = productSum % 11; |
| 20 | + return (sumMod11 === 0 ? '0' : (11 - sumMod11)); |
| 21 | + }; |
| 22 | + const staticSequenceFirstCheckDigit = [3, 7, 6, 1, 8, 9, 4, 5, 2]; |
| 23 | + const staticSequenceSecondCheckDigit = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2]; |
| 24 | + |
| 25 | + const k1 = checkDigit(staticSequenceFirstCheckDigit, tenDigits); |
| 26 | + const k2 = checkDigit(staticSequenceSecondCheckDigit, tenDigits + k1); |
| 27 | + |
| 28 | + return k1 + '' + k2; |
| 29 | + }; |
| 30 | + |
| 31 | + const getPersonId = (birthDate, year, gender) => { |
| 32 | + let no; |
| 33 | + let isMale = (gender === 'male'); |
| 34 | + |
| 35 | + if (year >= 2000) { |
| 36 | + no = 999 - range(0, (999 - 500)); |
| 37 | + } else if (year <= 1899) { |
| 38 | + no = 749 - range(0, (749 - 500)); |
| 39 | + } else if (year >= 1900 && year <= 1999) { |
| 40 | + no = 499 - range(0, 499); |
| 41 | + } |
| 42 | + if ( ((no & 1) && isMale) || (!(no & 1) && !isMale) ) { |
| 43 | + no--; |
| 44 | + } |
| 45 | + no = pad(String(no), 3); |
| 46 | + |
| 47 | + const fNr = birthDate + no; |
| 48 | + const fNr11 = fNr + calculateCheckDigits(fNr); |
| 49 | + |
| 50 | + if (fNr11.length !== 11 || fNr11.substr(-1) === '0') { |
| 51 | + return getPersonId(birthDate, year, gender); |
| 52 | + } |
| 53 | + return fNr11; |
| 54 | + }; |
| 55 | + |
| 56 | + contents.id = { |
| 57 | + name: 'FN', |
| 58 | + value: getPersonId(birthDate, dobDate.getFullYear(), contents.gender), |
| 59 | + }; |
| 60 | + }); |
| 61 | + |
| 62 | + include(inc, 'location', () => { |
| 63 | + const version = Object.keys(datasets).reverse()[0]; |
| 64 | + const oldStreet = contents.location.street.replace(/(\d+) /, ''); |
| 65 | + contents.location.street = oldStreet + ' ' + range(1, 9998); |
| 66 | + contents.location.postcode = randomItem(datasets[version]['NO'].post_codes); |
| 67 | + }); |
| 68 | + include(inc, 'picture', pic); |
| 69 | +}; |
0 commit comments