@remato/personal-code-to-birthday 1.1.1 → 1.2.0
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.
- package/.github/dependabot.yml +6 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +2 -0
- package/PULL_REQUEST_TEMPLATE.md +4 -0
- package/README.md +26 -28
- package/package.json +1 -1
- package/src/index.test.ts +11 -0
- package/src/index.ts +3 -0
- package/src/parsers/romania.ts +38 -0
- package/src/parsers/sweden.ts +1 -1
|
@@ -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.
|
package/CONTRIBUTING.md
ADDED
package/README.md
CHANGED
|
@@ -3,15 +3,26 @@
|
|
|
3
3
|
[](https://github.com/rematocorp/personal-code-to-birthday/actions/workflows/ci.yml)
|
|
4
4
|
[](https://codecov.io/gh/rematocorp/personal-code-to-birthday)
|
|
5
5
|
|
|
6
|
-
Converts personal identification codes
|
|
6
|
+
Converts personal identification codes from various countries into birthdate.
|
|
7
7
|
|
|
8
|
-
###
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **Automatic Birthdate Extraction**: Effortlessly extracts birthdates from national ID codes.
|
|
11
|
+
- **Built-in Validation**: Confirms personal code validity using checksum verification before returning a date.
|
|
12
|
+
- **Country-Agnostic**: Automatically identifies and processes the country format, requiring no additional parameters.
|
|
13
|
+
- **Lightweight & Seamless Integration**: Designed for easy integration into any project with minimal setup.
|
|
14
|
+
|
|
15
|
+
### Limitations
|
|
16
|
+
|
|
17
|
+
- **Date Range Restriction**: Only supports personal codes issued from 1900 to the present. Future-dated codes are not currently supported.
|
|
18
|
+
|
|
19
|
+
### Installation
|
|
9
20
|
|
|
10
21
|
```bash
|
|
11
22
|
npm install @remato/personal-code-to-birthday
|
|
12
23
|
```
|
|
13
24
|
|
|
14
|
-
###
|
|
25
|
+
### Usage
|
|
15
26
|
|
|
16
27
|
```ts
|
|
17
28
|
const birthday = personalCodeToBirthday('39309262855')
|
|
@@ -21,28 +32,15 @@ console.log(birthday) // outputs { day: 26, month: 9, year: 1993 }
|
|
|
21
32
|
|
|
22
33
|
### Countries supported
|
|
23
34
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
35
|
+
1. 🇺🇦 Ukraine
|
|
36
|
+
2. 🇪🇪 Estonia
|
|
37
|
+
3. 🇱🇻 Latvia
|
|
38
|
+
4. 🇱🇹 Lithuania
|
|
39
|
+
5. 🇵🇱 Poland
|
|
40
|
+
6. 🇫🇮 Finland
|
|
41
|
+
7. 🇸🇪 Sweden
|
|
42
|
+
8. 🇳🇴 Norway
|
|
43
|
+
9. 🇩🇰 Denmark
|
|
44
|
+
10. 🇷🇴 Romania
|
|
45
|
+
|
|
46
|
+
Need support for a new country or have feedback? [Create an issue.](https://github.com/rematocorp/personal-code-to-birthday/issues/new)
|
package/package.json
CHANGED
package/src/index.test.ts
CHANGED
|
@@ -58,6 +58,12 @@ describe('valid codes', () => {
|
|
|
58
58
|
expect(personalCodeToBirthday('02070803628')).toEqual({ day: 8, month: 7, year: 1902 })
|
|
59
59
|
expect(personalCodeToBirthday('24231012344')).toEqual({ day: 10, month: 3, year: 2024 })
|
|
60
60
|
})
|
|
61
|
+
|
|
62
|
+
test('Romania', () => {
|
|
63
|
+
expect(personalCodeToBirthday('1900101220018')).toEqual({ day: 1, month: 1, year: 1990 })
|
|
64
|
+
expect(personalCodeToBirthday('6010303275841')).toEqual({ day: 3, month: 3, year: 2001 })
|
|
65
|
+
expect(personalCodeToBirthday('2990721275847')).toEqual({ day: 21, month: 7, year: 1999 })
|
|
66
|
+
})
|
|
61
67
|
})
|
|
62
68
|
|
|
63
69
|
describe('invalid personal code', () => {
|
|
@@ -108,6 +114,11 @@ describe('invalid personal code', () => {
|
|
|
108
114
|
expect(personalCodeToBirthday('24234012341')).toBeNull()
|
|
109
115
|
})
|
|
110
116
|
|
|
117
|
+
test('Romania', () => {
|
|
118
|
+
expect(personalCodeToBirthday('1980521275840')).toBeNull()
|
|
119
|
+
expect(personalCodeToBirthday('1234567890128')).toBeNull()
|
|
120
|
+
})
|
|
121
|
+
|
|
111
122
|
test('unidentified personal code format', () => {
|
|
112
123
|
expect(personalCodeToBirthday('abcd1234')).toBeNull()
|
|
113
124
|
})
|
package/src/index.ts
CHANGED
|
@@ -4,6 +4,7 @@ import finlandParser from './parsers/finland'
|
|
|
4
4
|
import latviaParser from './parsers/latvia'
|
|
5
5
|
import norwayParser from './parsers/norway'
|
|
6
6
|
import polandParser from './parsers/poland'
|
|
7
|
+
import romaniaParser from './parsers/romania'
|
|
7
8
|
import swedenParser from './parsers/sweden'
|
|
8
9
|
import ukraineParser from './parsers/ukraine'
|
|
9
10
|
import { ParsedDate } from './types'
|
|
@@ -17,6 +18,8 @@ export default function personalCodeToBirthday(code: string): ParsedDate | null
|
|
|
17
18
|
return estoniaLithuaniaParser(code) || polandParser(code) || norwayParser(code)
|
|
18
19
|
} else if (/^\d{12}$/.test(code)) {
|
|
19
20
|
return swedenParser(code)
|
|
21
|
+
} else if (/^\d{13}$/.test(code)) {
|
|
22
|
+
return romaniaParser(code)
|
|
20
23
|
} else if (/^\d{6}-\d{5}$/.test(code)) {
|
|
21
24
|
return latviaParser(code)
|
|
22
25
|
} else if (/^\d{6}[+-A]\d{3}[A-Za-z]$/.test(code)) {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ParsedDate } from '../types'
|
|
2
|
+
import { isValidDate } from '../utils'
|
|
3
|
+
|
|
4
|
+
export default function romaniaParser(code: string): ParsedDate | null {
|
|
5
|
+
if (!isValidChecksum(code)) {
|
|
6
|
+
return null
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
let year = parseInt(code.slice(1, 3), 10)
|
|
10
|
+
const month = parseInt(code.slice(3, 5), 10)
|
|
11
|
+
const day = parseInt(code.slice(5, 7), 10)
|
|
12
|
+
const gender = parseInt(code[0], 10)
|
|
13
|
+
|
|
14
|
+
if (gender === 1 || gender === 2) {
|
|
15
|
+
year += 1900
|
|
16
|
+
} else if (gender === 5 || gender === 6) {
|
|
17
|
+
year += 2000
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (!isValidDate(day, month, year)) {
|
|
21
|
+
return null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return { day, month, year }
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function isValidChecksum(code: string): boolean {
|
|
28
|
+
const weights = [2, 7, 9, 1, 4, 6, 3, 5, 8, 2, 7, 9]
|
|
29
|
+
let sum = 0
|
|
30
|
+
|
|
31
|
+
for (let i = 0; i < 12; i++) {
|
|
32
|
+
sum += parseInt(code[i]) * weights[i]
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const checksum = sum % 11 === 10 ? 1 : sum % 11
|
|
36
|
+
|
|
37
|
+
return checksum === parseInt(code[12])
|
|
38
|
+
}
|
package/src/parsers/sweden.ts
CHANGED
|
@@ -35,7 +35,7 @@ export default function swedenParser(code: string): ParsedDate | null {
|
|
|
35
35
|
return { day, month, year }
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
function isValidChecksum(code: string) {
|
|
38
|
+
function isValidChecksum(code: string): boolean {
|
|
39
39
|
// Use the last 9 digits without checksum number
|
|
40
40
|
const digits = code.length === 12 ? code.slice(2, 11) : code.slice(0, 9)
|
|
41
41
|
|