@remato/personal-code-to-birthday 1.1.1 → 1.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "npm"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
7
+ cooldown:
8
+ default-days: 7
package/.oxlintrc.json ADDED
@@ -0,0 +1,34 @@
1
+ {
2
+ "$schema": "./node_modules/oxlint/configuration_schema.json",
3
+ "plugins": ["import"],
4
+ "categories": {
5
+ "correctness": "off"
6
+ },
7
+ "ignorePatterns": ["dist", "demo"],
8
+ "rules": {
9
+ "no-restricted-imports": [
10
+ "error",
11
+ {
12
+ "paths": [
13
+ {
14
+ "name": "lodash",
15
+ "message": "Use import from 'lodash/*' instead"
16
+ }
17
+ ]
18
+ }
19
+ ],
20
+ "no-undef": "off",
21
+ "no-unused-vars": ["error", { "ignoreRestSiblings": true }],
22
+ "no-var": "error",
23
+ "no-const-assign": "error",
24
+ "prefer-const": ["error", { "destructuring": "all" }],
25
+ "curly": "error",
26
+ "object-shorthand": "error",
27
+ "no-console": ["error", { "allow": ["warn", "error"] }],
28
+ "eqeqeq": ["error", "always", { "null": "ignore" }],
29
+ "no-unreachable": "error",
30
+ "no-fallthrough": "error",
31
+ "sort-imports": ["error", { "ignoreCase": true, "ignoreDeclarationSort": true }],
32
+ "import/no-duplicates": "error"
33
+ }
34
+ }
@@ -0,0 +1,128 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, religion, or sexual identity
10
+ and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the
26
+ overall community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or
31
+ advances of any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email
35
+ address, without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official e-mail address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ .
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series
86
+ of actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or
93
+ permanent ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within
113
+ the community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.0, available at
119
+ https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
120
+
121
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct
122
+ enforcement ladder](https://github.com/mozilla/diversity).
123
+
124
+ [homepage]: https://www.contributor-covenant.org
125
+
126
+ For answers to common questions about this code of conduct, see the FAQ at
127
+ https://www.contributor-covenant.org/faq. Translations are available at
128
+ https://www.contributor-covenant.org/translations.
@@ -0,0 +1,2 @@
1
+ - Make sure your changes are [prettified](https://prettier.io/) (you can use `npm run prettier`)
2
+ - Add unit tests to maintain 100% coverage
@@ -0,0 +1,4 @@
1
+ ##### Checklist
2
+
3
+ - [ ] Updated README.md
4
+ - [ ] Wrote tests
package/README.md CHANGED
@@ -1,17 +1,30 @@
1
1
  # Personal Code to Birthday
2
2
 
3
+ [![NPM Version](https://img.shields.io/npm/v/%40remato%2Fpersonal-code-to-birthday)](https://www.npmjs.com/package/@remato/personal-code-to-birthday)
3
4
  [![Build](https://img.shields.io/github/actions/workflow/status/rematocorp/personal-code-to-birthday/ci.yml)](https://github.com/rematocorp/personal-code-to-birthday/actions/workflows/ci.yml)
4
5
  [![Codecov](https://img.shields.io/codecov/c/github/rematocorp/personal-code-to-birthday?token=NDT35FM2LG&style=flat)](https://codecov.io/gh/rematocorp/personal-code-to-birthday)
5
6
 
6
- Converts personal identification codes (or national ID numbers) from various countries into birthdate.
7
+ Converts personal identification codes from various countries into birthdate.
7
8
 
8
- ### Install
9
+ **[Try it out](https://rematocorp.github.io/personal-code-to-birthday/)**
10
+
11
+ ### Features
12
+
13
+ - **Built-in Validation**: Confirms personal code validity using checksum verification before returning a date.
14
+ - **Country-Agnostic**: Automatically identifies and processes the country format, requiring no additional parameters.
15
+ - **Lightweight**: Designed for easy integration into any project with no extra dependencies.
16
+
17
+ ### Limitations
18
+
19
+ - Only supports personal codes issued from 1900 to the present. Future-dated codes are not currently supported.
20
+
21
+ ### Installation
9
22
 
10
23
  ```bash
11
24
  npm install @remato/personal-code-to-birthday
12
25
  ```
13
26
 
14
- ### How to use
27
+ ### Usage
15
28
 
16
29
  ```ts
17
30
  const birthday = personalCodeToBirthday('39309262855')
@@ -21,28 +34,32 @@ console.log(birthday) // outputs { day: 26, month: 9, year: 1993 }
21
34
 
22
35
  ### Countries supported
23
36
 
24
- - 🇪🇪 Estonia
25
- - 🇱🇻 Latvia
26
- - 🇱🇹 Lithuania
27
- - 🇫🇮 Finland
28
- - 🇸🇪 Sweden
29
- - 🇳🇴 Norway
30
- - 🇩🇰 Denmark
31
- - 🇺🇦 Ukraine
32
- - 🇵🇱 Poland
33
-
34
- Countries we would like to support (PRs are welcome):
35
-
36
- - Iceland
37
- - Romania
38
- - Hungary
39
- - Bulgaria
40
- - Moldova
41
- - Azerbaijan
42
- - North Macedonia
43
- - Czech Republic
44
- - Slovakia
45
- - South Korea
46
- - Turkey
47
- - South Africa
48
- - Russia
37
+ 1. 🇺🇦 Ukraine
38
+ 2. 🇪🇪 Estonia
39
+ 3. 🇱🇻 Latvia
40
+ 4. 🇱🇹 Lithuania
41
+ 5. 🇵🇱 Poland
42
+ 6. 🇫🇮 Finland
43
+ 7. 🇸🇪 Sweden
44
+ 8. 🇳🇴 Norway
45
+ 9. 🇩🇰 Denmark
46
+ 10. 🇷🇴 Romania
47
+
48
+ Need support for a new country or have feedback? [Create an issue.](https://github.com/rematocorp/personal-code-to-birthday/issues/new)
49
+
50
+ ### Random facts
51
+
52
+ 1. In Ukraine, the first five digits of the code indicate birthdate as days since January 1, 1900
53
+ 2. Lithuania and Estonia use a nearly identical personal code system.
54
+ 3. Estonia's personal code used to include hospital where the person was born.
55
+ 4. Denmark dropped the check digit in 2007 due to running out of available numbers.
56
+ 5. Latvia removed the birthdate component from their new personal codes starting in 2017.
57
+ 6. In Sweden, individuals who turn 100 receive a new personal code, where “-” is replaced by “+”.
58
+ 7. Norway plans to remove gender and century indicators from personal codes in 2032.
59
+ 8. Finland’s personal codes include both numbers and letters for the checksum.
60
+ 9. Romania’s personal code includes a county indicator.
61
+ 10. Poland’s system differentiates centuries by altering the month digits.
62
+
63
+ ### Authors
64
+
65
+ Created by the [Remato team](https://remato.com) to auto-complete birthdate entries based on the construction worker’s personal ID input (country unknown).
@@ -0,0 +1 @@
1
+ <svg width="96" height="96" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M0 12C0 5.373 5.373 0 12 0h72c6.627 0 12 5.373 12 12v72c0 6.627-5.373 12-12 12H12C5.373 96 0 90.627 0 84V12z" fill="#10191F"/><path fill-rule="evenodd" clip-rule="evenodd" d="M47.87 45.893c3.204 0 4.928-1.667 4.928-3.984 0-2.456-1.724-3.984-4.928-3.984h-3.939a.633.633 0 00-.643.623v6.722c0 .344.287.623.643.623h3.94zm-2.22 6.3h-1.718a.633.633 0 00-.643.623V63.8a.633.633 0 01-.644.623h-6.5a.633.633 0 01-.642-.623V32.2c0-.344.288-.623.643-.623H49.35c6.9 0 11.334 4.448 11.334 10.284 0 4.21-2.34 7.464-6.224 9.019-.355.142-.52.537-.344.868l6.28 11.766c.222.414-.089.909-.57.909h-7.12a.647.647 0 01-.577-.346l-5.903-11.538a.646.646 0 00-.577-.346z" fill="#fff"/><path fill-rule="evenodd" clip-rule="evenodd" d="M13.9 60.15l1.746-1.747a.634.634 0 01.896 0l5.676 5.675c.119.12.185.28.185.448v8.437c0 .35.284.633.634.633h8.436c.168 0 .33.067.448.186l5.676 5.676a.634.634 0 010 .895L35.85 82.1a.632.632 0 01-.447.185H14.348a.633.633 0 01-.634-.633V60.597c0-.168.067-.329.186-.448" fill="#F7DA61"/><path fill-rule="evenodd" clip-rule="evenodd" d="M23.037 73.597a.631.631 0 01-.448-.185l-8.69 8.688a.631.631 0 00.449.186h21.055a.634.634 0 00.447-.186l1.747-1.746a.633.633 0 000-.896l-5.676-5.676a.632.632 0 00-.447-.185h-8.437z" fill="#EEAD09"/><path fill-rule="evenodd" clip-rule="evenodd" d="M60.149 13.9l-1.747 1.746a.634.634 0 000 .896l5.676 5.676c.119.119.28.185.448.185h8.437c.35 0 .633.284.633.634v8.437c0 .168.067.33.186.448l5.675 5.676a.633.633 0 00.896 0L82.1 35.85a.634.634 0 00.185-.448V14.348a.633.633 0 00-.633-.634H60.597a.634.634 0 00-.448.186" fill="#F7DA61"/><path fill-rule="evenodd" clip-rule="evenodd" d="M82.1 13.9l-8.69 8.689a.633.633 0 01.186.448v8.437a.63.63 0 00.185.448l5.676 5.676a.633.633 0 00.896 0l1.746-1.747a.633.633 0 00.186-.448V14.348a.632.632 0 00-.186-.448z" fill="#EEAD09"/></svg>
@@ -0,0 +1 @@
1
+ <svg width="32" height="32" fill="none" xmlns="http://www.w3.org/2000/svg"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M15.952 0C7.132 0 0 7.333 0 16.406c0 7.252 4.57 13.39 10.908 15.563.792.163 1.083-.353 1.083-.787 0-.38-.027-1.684-.027-3.043-4.437.978-5.361-1.955-5.361-1.955-.713-1.902-1.77-2.39-1.77-2.39-1.452-1.005.106-1.005.106-1.005 1.61.108 2.456 1.684 2.456 1.684 1.426 2.498 3.724 1.792 4.648 1.358.132-1.06.555-1.793 1.004-2.2-3.54-.38-7.263-1.793-7.263-8.095 0-1.792.634-3.259 1.637-4.4-.158-.407-.713-2.091.16-4.346 0 0 1.346-.434 4.383 1.684 1.3-.359 2.641-.541 3.988-.543 1.347 0 2.72.19 3.988.543 3.038-2.118 4.385-1.684 4.385-1.684.871 2.255.316 3.939.158 4.346 1.03 1.141 1.637 2.608 1.637 4.4 0 6.302-3.723 7.687-7.289 8.095.581.516 1.083 1.493 1.083 3.042 0 2.2-.026 3.965-.026 4.508 0 .435.29.951 1.082.788 6.34-2.173 10.908-8.311 10.908-15.563C31.904 7.333 24.748 0 15.952 0Z" fill="#fff"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h32v32H0z"/></clipPath></defs></svg>
package/demo/index.js ADDED
@@ -0,0 +1,374 @@
1
+ "use strict";
2
+ var personalCodeToBirthday = (() => {
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ default: () => personalCodeToBirthday
25
+ });
26
+
27
+ // src/utils.ts
28
+ function isValidDate(day, month, year) {
29
+ const date = new Date(year, month - 1, day);
30
+ if (year < 1900 || year > (/* @__PURE__ */ new Date()).getFullYear()) {
31
+ return false;
32
+ }
33
+ return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
34
+ }
35
+
36
+ // src/parsers/denmark.ts
37
+ function denmarkParser(code) {
38
+ code = code.replace("-", "");
39
+ const day = parseInt(code.slice(0, 2), 10);
40
+ const month = parseInt(code.slice(2, 4), 10);
41
+ let year = parseInt(code.slice(4, 6), 10);
42
+ const centuryIndicator = parseInt(code.slice(6, 7), 10);
43
+ if (centuryIndicator >= 0 && centuryIndicator <= 3) {
44
+ year += 1900;
45
+ } else if (centuryIndicator >= 4 && centuryIndicator <= 9) {
46
+ if (year >= 0 && year <= 36) {
47
+ year += 2e3;
48
+ } else {
49
+ year += 1900;
50
+ }
51
+ }
52
+ if (year < 2007 && !isValidChecksum(code)) {
53
+ return null;
54
+ }
55
+ if (!isValidDate(day, month, year)) {
56
+ return null;
57
+ }
58
+ return { day, month, year };
59
+ }
60
+ function isValidChecksum(code) {
61
+ const weights = [4, 3, 2, 7, 6, 5, 4, 3, 2];
62
+ const digits = code.substring(0, 9).split("").map(Number);
63
+ const sum = digits.reduce((acc, digit, index) => acc + digit * weights[index], 0);
64
+ const checksum = sum % 11 === 0 ? 0 : 11 - sum % 11;
65
+ if (checksum === 10) {
66
+ return false;
67
+ }
68
+ return checksum === parseInt(code[9], 10);
69
+ }
70
+
71
+ // src/parsers/estoniaLithuania.ts
72
+ function estoniaLithuaniaParser(code) {
73
+ if (!isValidChecksum2(code)) {
74
+ return null;
75
+ }
76
+ const centuryCode = parseInt(code[0], 10);
77
+ const day = parseInt(code.slice(5, 7), 10);
78
+ const month = parseInt(code.slice(3, 5), 10);
79
+ let year = parseInt(code.slice(1, 3), 10);
80
+ if (centuryCode === 3 || centuryCode === 4) {
81
+ year += 1900;
82
+ }
83
+ if (centuryCode === 5 || centuryCode === 6) {
84
+ year += 2e3;
85
+ }
86
+ if (!isValidDate(day, month, year)) {
87
+ return null;
88
+ }
89
+ return { day, month, year };
90
+ }
91
+ function isValidChecksum2(code) {
92
+ const weights1 = [1, 2, 3, 4, 5, 6, 7, 8, 9, 1];
93
+ const weights2 = [3, 4, 5, 6, 7, 8, 9, 1, 2, 3];
94
+ let checksum = 0;
95
+ let total = 0;
96
+ for (let i = 0; i < 10; ++i) {
97
+ total += Number(code.charAt(i)) * weights1[i];
98
+ }
99
+ checksum = total % 11;
100
+ total = 0;
101
+ if (checksum === 10) {
102
+ for (let i = 0; i < 10; ++i) {
103
+ total += Number(code.charAt(i)) * weights2[i];
104
+ }
105
+ checksum = total % 11;
106
+ if (10 === checksum) {
107
+ checksum = 0;
108
+ }
109
+ }
110
+ return checksum === Number(code[10]);
111
+ }
112
+
113
+ // src/parsers/finland.ts
114
+ function finlandParser(code) {
115
+ if (!isValidChecksum3(code)) {
116
+ return null;
117
+ }
118
+ const day = parseInt(code.slice(0, 2), 10);
119
+ const month = parseInt(code.slice(2, 4), 10);
120
+ const yearSuffix = parseInt(code.slice(4, 6), 10);
121
+ const centuryMarker = code[6];
122
+ let year = yearSuffix;
123
+ if (centuryMarker === "-") {
124
+ year += 1900;
125
+ } else if (centuryMarker === "A") {
126
+ year += 2e3;
127
+ }
128
+ if (!isValidDate(day, month, year)) {
129
+ return null;
130
+ }
131
+ return { day, month, year };
132
+ }
133
+ function isValidChecksum3(code) {
134
+ const validChars = "0123456789ABCDEFHJKLMNPRSTUVWXY";
135
+ const serial = code.slice(0, 6) + code.slice(7, 10);
136
+ const checksum = code[10];
137
+ const num = parseInt(serial, 10);
138
+ const remainder = num % 31;
139
+ const expectedChecksum = validChars.charAt(remainder);
140
+ return expectedChecksum === checksum.toUpperCase();
141
+ }
142
+
143
+ // src/parsers/latvia.ts
144
+ function latviaParser(code) {
145
+ code = code.replace("-", "");
146
+ if (!isValidChecksum4(code)) {
147
+ return null;
148
+ }
149
+ const day = parseInt(code.slice(0, 2), 10);
150
+ const month = parseInt(code.slice(2, 4), 10);
151
+ let year = parseInt(code.slice(4, 6), 10);
152
+ const centuryCode = parseInt(code[6], 10);
153
+ if (centuryCode === 3) {
154
+ year += 2e3;
155
+ } else {
156
+ year += 1900;
157
+ }
158
+ if (!isValidDate(day, month, year)) {
159
+ return null;
160
+ }
161
+ return { day, month, year };
162
+ }
163
+ function isValidChecksum4(personalCode) {
164
+ const weights = [1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
165
+ const digits = personalCode.substring(0, 10).split("").map(Number);
166
+ const sum = digits.reduce((acc, digit, index) => acc + digit * weights[index], 0);
167
+ let checksum = sum % 11;
168
+ if (checksum === 10) {
169
+ checksum = 0;
170
+ }
171
+ return checksum === parseInt(personalCode[10], 10);
172
+ }
173
+
174
+ // src/parsers/norway.ts
175
+ function norwayParser(code) {
176
+ code = code.replace(" ", "");
177
+ if (!isValidChecksum5(code)) {
178
+ return null;
179
+ }
180
+ const day = parseInt(code.slice(0, 2), 10);
181
+ const month = parseInt(code.slice(2, 4), 10);
182
+ let year = parseInt(code.slice(4, 6), 10);
183
+ const centuryMarker = parseInt(code.slice(6, 7), 10);
184
+ if (centuryMarker <= 4 || centuryMarker === 9) {
185
+ year += year >= 40 ? 1900 : 2e3;
186
+ } else if (centuryMarker >= 5 && centuryMarker <= 8) {
187
+ year += 2e3;
188
+ }
189
+ if (!isValidDate(day, month, year)) {
190
+ return null;
191
+ }
192
+ return { day, month, year };
193
+ }
194
+ function isValidChecksum5(code) {
195
+ const weights1 = [3, 7, 6, 1, 8, 9, 4, 5, 2];
196
+ const weights2 = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2];
197
+ const digits = code.substring(0, 9).split("").map(Number);
198
+ const providedFirstCheckDigit = parseInt(code[9], 10);
199
+ const providedSecondCheckDigit = parseInt(code[10], 10);
200
+ const sum1 = digits.reduce((sum, digit, index) => sum + digit * weights1[index], 0);
201
+ let firstCheckDigit = 11 - sum1 % 11;
202
+ if (firstCheckDigit === 11) {
203
+ firstCheckDigit = 0;
204
+ }
205
+ if (firstCheckDigit === 10) {
206
+ return false;
207
+ }
208
+ const digitsWithFirstCheck = [...digits, firstCheckDigit];
209
+ const sum2 = digitsWithFirstCheck.reduce((sum, digit, index) => sum + digit * weights2[index], 0);
210
+ let secondCheckDigit = 11 - sum2 % 11;
211
+ if (secondCheckDigit === 11) {
212
+ secondCheckDigit = 0;
213
+ }
214
+ if (secondCheckDigit === 10) {
215
+ return false;
216
+ }
217
+ return firstCheckDigit === providedFirstCheckDigit && secondCheckDigit === providedSecondCheckDigit;
218
+ }
219
+
220
+ // src/parsers/poland.ts
221
+ function polandParser(code) {
222
+ if (!isValidChecksum6(code)) {
223
+ return null;
224
+ }
225
+ const day = parseInt(code.slice(4, 6), 10);
226
+ let month = parseInt(code.slice(2, 4), 10);
227
+ let year = parseInt(code.slice(0, 2), 10);
228
+ if (month >= 1 && month <= 12) {
229
+ year += 1900;
230
+ } else if (month >= 21 && month <= 32) {
231
+ year += 2e3;
232
+ month -= 20;
233
+ }
234
+ if (!isValidDate(day, month, year)) {
235
+ return null;
236
+ }
237
+ return { day, month, year };
238
+ }
239
+ function isValidChecksum6(code) {
240
+ const weights = [1, 3, 7, 9, 1, 3, 7, 9, 1, 3];
241
+ const digits = code.slice(0, 10).split("").map(Number);
242
+ const sum = digits.reduce((acc, digit, index) => acc + digit * weights[index], 0);
243
+ const expectedChecksum = (10 - sum % 10) % 10;
244
+ return expectedChecksum === parseInt(code[10], 10);
245
+ }
246
+
247
+ // src/parsers/romania.ts
248
+ function romaniaParser(code) {
249
+ if (!isValidChecksum7(code)) {
250
+ return null;
251
+ }
252
+ let year = parseInt(code.slice(1, 3), 10);
253
+ const month = parseInt(code.slice(3, 5), 10);
254
+ const day = parseInt(code.slice(5, 7), 10);
255
+ const gender = parseInt(code[0], 10);
256
+ if (gender === 1 || gender === 2) {
257
+ year += 1900;
258
+ } else if (gender === 5 || gender === 6) {
259
+ year += 2e3;
260
+ }
261
+ if (!isValidDate(day, month, year)) {
262
+ return null;
263
+ }
264
+ return { day, month, year };
265
+ }
266
+ function isValidChecksum7(code) {
267
+ const weights = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9];
268
+ let sum = 0;
269
+ for (let i = 0; i < 12; i++) {
270
+ sum += parseInt(code[i]) * weights[i];
271
+ }
272
+ const checksum = sum % 11 === 10 ? 1 : sum % 11;
273
+ return checksum === parseInt(code[12]);
274
+ }
275
+
276
+ // src/parsers/sweden.ts
277
+ function swedenParser(code) {
278
+ code = code.replace("-", "");
279
+ if (!isValidChecksum8(code)) {
280
+ return null;
281
+ }
282
+ let year;
283
+ let month;
284
+ let day;
285
+ if (code.length === 12) {
286
+ year = parseInt(code.slice(0, 4), 10);
287
+ month = parseInt(code.slice(4, 6), 10);
288
+ day = parseInt(code.slice(6, 8), 10);
289
+ } else {
290
+ year = parseInt(code.slice(0, 2), 10);
291
+ month = parseInt(code.slice(2, 4), 10);
292
+ day = parseInt(code.slice(4, 6), 10);
293
+ if ((/* @__PURE__ */ new Date()).getFullYear() - (1900 + year) > 99) {
294
+ year += 2e3;
295
+ } else {
296
+ year += 1900;
297
+ }
298
+ }
299
+ if (!isValidDate(day, month, year)) {
300
+ return null;
301
+ }
302
+ return { day, month, year };
303
+ }
304
+ function isValidChecksum8(code) {
305
+ const digits = code.length === 12 ? code.slice(2, 11) : code.slice(0, 9);
306
+ let sum = 0;
307
+ for (let i = 0; i < digits.length; i++) {
308
+ let digit = parseInt(digits[i]);
309
+ if (i % 2 === 0) {
310
+ digit *= 2;
311
+ if (digit > 9) {
312
+ digit -= 9;
313
+ }
314
+ }
315
+ sum += digit;
316
+ }
317
+ const expectedChecksum = (10 - sum % 10) % 10;
318
+ return expectedChecksum === Number(code[code.length - 1]);
319
+ }
320
+
321
+ // src/parsers/ukraine.ts
322
+ function ukrainianParser(code) {
323
+ if (!isValidChecksum9(code)) {
324
+ return null;
325
+ }
326
+ const daysSinceBaseDate = parseInt(code.slice(0, 5), 10);
327
+ const baseDate = new Date(1899, 11, 31);
328
+ const birthDate = new Date(baseDate.getTime() + daysSinceBaseDate * 24 * 60 * 60 * 1e3);
329
+ const day = birthDate.getDate();
330
+ const month = birthDate.getMonth() + 1;
331
+ const year = birthDate.getFullYear();
332
+ if (!isValidDate(day, month, year)) {
333
+ return null;
334
+ }
335
+ return { day, month, year };
336
+ }
337
+ function isValidChecksum9(code) {
338
+ const digits = code.slice(0, 9).split("").map(Number);
339
+ const weights = [-1, 5, 7, 9, 4, 6, 10, 5, 7];
340
+ const controlSum = digits.reduce((sum, digit, index) => sum + digit * weights[index], 0);
341
+ let controlNumber = controlSum % 11;
342
+ if (controlNumber === 10) {
343
+ controlNumber = 0;
344
+ }
345
+ return controlNumber === parseInt(code[9], 10);
346
+ }
347
+
348
+ // src/index.ts
349
+ function personalCodeToBirthday(code) {
350
+ if (/^\d{10}$/.test(code)) {
351
+ return ukrainianParser(code) || swedenParser(code);
352
+ } else if (/^\d{11}$/.test(code)) {
353
+ return estoniaLithuaniaParser(code) || polandParser(code) || norwayParser(code);
354
+ } else if (/^\d{12}$/.test(code)) {
355
+ return swedenParser(code);
356
+ } else if (/^\d{13}$/.test(code)) {
357
+ return romaniaParser(code);
358
+ } else if (/^\d{6}\s\d{5}$/.test(code)) {
359
+ return norwayParser(code);
360
+ } else if (/^\d{6}-\d{5}$/.test(code)) {
361
+ return latviaParser(code);
362
+ } else if (/^\d{6}[+-A]\d{3}[A-Za-z]$/.test(code)) {
363
+ return finlandParser(code);
364
+ } else if (/^\d{6}-\d{4}$/.test(code)) {
365
+ return finlandParser(code) || swedenParser(code) || denmarkParser(code);
366
+ } else if (/^\d{6}A\d{4}$/.test(code)) {
367
+ return finlandParser(code);
368
+ } else if (/^\d{8}-\d{4}$/.test(code)) {
369
+ return swedenParser(code);
370
+ }
371
+ return null;
372
+ }
373
+ return __toCommonJS(index_exports);
374
+ })();