Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const peselValidation = (pesel: number) => {
- const peselString = pesel.toFixed()
- const weights = [9, 7, 3, 1, 9, 7, 3, 1, 9, 7];
- let sum = 0;
- for (let index = 0; index < weights.length; index++) {
- sum += parseInt(peselString.substring(index, index + 1), 10) * weights[index];
- }
- sum = sum % 10;
- const response = (sum === parseInt(peselString.substring(10, 11), 10));
- return response;
- }
- const peselDate = (pesel: number) => {
- const peselString = pesel.toFixed()
- let year: number = parseInt(peselString.substring(0, 2)),
- month: number | string = parseInt(peselString.substring(2, 4), 10) - 1,
- day: number = parseInt(peselString.substring(4, 6), 10)
- const monthString = [
- 'stycznia',
- 'lutego',
- 'marca',
- 'kwietnia',
- 'maja',
- 'czerwca',
- 'lipca',
- 'sierpnia',
- 'września',
- 'października',
- 'listopada',
- 'grudnia'
- ];
- if (year > 80) {
- year = year + 1800
- month = month - 80
- } else if (month > 60) {
- year = year + 2200
- month = month - 60
- } else if (month > 40) {
- year = year + 2100
- month = month - 40
- } else if (month > 20) {
- year = year + 2200
- month = month - 80
- } else {
- year = year + 1900
- }
- return `${day} ${monthString[month - 1]} ${year}`;
- }
- console.log(peselValidation(73072255843));
- console.log(peselDate(73072255843));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement