@slashlab/numerik-js 1.0.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/LICENSE +21 -0
- package/README.md +100 -0
- package/dist/VatEu-BNRumLqo.d.cts +142 -0
- package/dist/VatEu-BNRumLqo.d.ts +142 -0
- package/dist/chunk-3DAGKUXS.js +1210 -0
- package/dist/chunk-3DAGKUXS.js.map +1 -0
- package/dist/index.cjs +1263 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +189 -0
- package/dist/index.d.ts +189 -0
- package/dist/index.js +61 -0
- package/dist/index.js.map +1 -0
- package/dist/zod/index.cjs +1247 -0
- package/dist/zod/index.cjs.map +1 -0
- package/dist/zod/index.d.cts +23 -0
- package/dist/zod/index.d.ts +23 -0
- package/dist/zod/index.js +56 -0
- package/dist/zod/index.js.map +1 -0
- package/package.json +104 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Sqrcz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# numerik-js
|
|
2
|
+
|
|
3
|
+
[](LICENSE)
|
|
4
|
+
[](https://github.com/sqrcz/numerik-js/actions/workflows/tests.yml)
|
|
5
|
+
[](https://coderabbit.ai)
|
|
6
|
+
[](https://bundlephobia.com/package/@slashlab/numerik-js)
|
|
7
|
+
[](https://www.npmjs.com/package/@slashlab/numerik-js)
|
|
8
|
+
[](https://www.npmjs.com/package/@slashlab/numerik-js)
|
|
9
|
+
|
|
10
|
+
> Validate and parse Polish identification numbers — PESEL, NIP, REGON, KRS, NRB, VAT-EU, IBAN, ID Card, and Passport. Rich value objects, detailed error reasons, zero production dependencies. TypeScript-first.
|
|
11
|
+
|
|
12
|
+
JavaScript/TypeScript port of [slashlab/numerik](https://github.com/sqrcz/numerik) (PHP).
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npm install @slashlab/numerik-js
|
|
18
|
+
# or
|
|
19
|
+
pnpm add @slashlab/numerik-js
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Quick Start
|
|
23
|
+
|
|
24
|
+
```ts
|
|
25
|
+
import { Numerik } from '@slashlab/numerik-js'
|
|
26
|
+
|
|
27
|
+
// Simple boolean check
|
|
28
|
+
Numerik.pesel().isValid('92060512186') // true
|
|
29
|
+
Numerik.nip().isValid('5260250274') // true
|
|
30
|
+
|
|
31
|
+
// Rich validation result with failure reasons
|
|
32
|
+
const result = Numerik.pesel().validate('92060512185') // wrong checksum
|
|
33
|
+
result.isFailed() // true
|
|
34
|
+
result.getFirstFailure().reason // ValidationFailureReason.InvalidChecksum
|
|
35
|
+
|
|
36
|
+
// Parse to value object
|
|
37
|
+
const pesel = Numerik.pesel().parse('92060512186')
|
|
38
|
+
pesel.getBirthDate() // Date object: 1992-06-05
|
|
39
|
+
pesel.getGender() // Gender.Female
|
|
40
|
+
pesel.isAdult() // true
|
|
41
|
+
|
|
42
|
+
// Try-parse (returns null on failure instead of throwing)
|
|
43
|
+
const parsed = Numerik.nip().tryParse('5260250274')
|
|
44
|
+
parsed?.getFormatted() // '526-025-02-74'
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Strict mode
|
|
48
|
+
|
|
49
|
+
All identifiers accept an optional `strict` flag (default: `true`). In non-strict mode formatting variations (spaces, dashes) are accepted:
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
Numerik.nip(false).isValid('526 025 02 74') // true
|
|
53
|
+
Numerik.nip(true).isValid('526 025 02 74') // false
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Zod integration
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { peselSchema, nipParseSchema } from '@slashlab/numerik-js/zod'
|
|
60
|
+
import { z } from 'zod'
|
|
61
|
+
|
|
62
|
+
const schema = z.object({
|
|
63
|
+
pesel: peselSchema(), // validates, keeps string
|
|
64
|
+
nip: nipParseSchema(), // validates and transforms to Nip value object
|
|
65
|
+
})
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Supported identifiers
|
|
69
|
+
|
|
70
|
+
| Group | Identifier | Class |
|
|
71
|
+
| -------- | ---------- | -------------------- |
|
|
72
|
+
| Personal | PESEL | `PeselIdentifier` |
|
|
73
|
+
| Personal | ID Card | `IdCardIdentifier` |
|
|
74
|
+
| Personal | Passport | `PassportIdentifier` |
|
|
75
|
+
| Tax | NIP | `NipIdentifier` |
|
|
76
|
+
| Tax | VAT-EU | `VatEuIdentifier` |
|
|
77
|
+
| Business | REGON | `RegonIdentifier` |
|
|
78
|
+
| Business | KRS | `KrsIdentifier` |
|
|
79
|
+
| Banking | NRB | `NrbIdentifier` |
|
|
80
|
+
| Banking | IBAN | `IbanIdentifier` |
|
|
81
|
+
|
|
82
|
+
## Changelog
|
|
83
|
+
|
|
84
|
+
See [CHANGELOG.md](CHANGELOG.md).
|
|
85
|
+
|
|
86
|
+
## Contributing
|
|
87
|
+
|
|
88
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md).
|
|
89
|
+
|
|
90
|
+
## Security
|
|
91
|
+
|
|
92
|
+
See [SECURITY.md](SECURITY.md).
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT — see [LICENSE](LICENSE).
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
If this saved you time → [☕ Buy me a coffee](https://buymeacoffee.com/sqrcz)
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
interface IdentifierInterface {
|
|
2
|
+
getRaw(): string;
|
|
3
|
+
getNormalized(): string;
|
|
4
|
+
toString(): string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare enum Gender {
|
|
8
|
+
Male = "male",
|
|
9
|
+
Female = "female"
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare enum RegonType {
|
|
13
|
+
Individual = "individual",
|
|
14
|
+
LegalEntity = "legal_entity"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare class Iban implements IdentifierInterface {
|
|
18
|
+
private readonly raw;
|
|
19
|
+
private readonly normalized;
|
|
20
|
+
constructor(raw: string, normalized: string);
|
|
21
|
+
getRaw(): string;
|
|
22
|
+
getNormalized(): string;
|
|
23
|
+
toString(): string;
|
|
24
|
+
getFormatted(): string;
|
|
25
|
+
getCountryCode(): string;
|
|
26
|
+
getNrb(): string;
|
|
27
|
+
getCheckDigits(): string;
|
|
28
|
+
getSortCode(): string;
|
|
29
|
+
getBankCode(): string;
|
|
30
|
+
getAccountNumber(): string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare class IdCard implements IdentifierInterface {
|
|
34
|
+
private readonly raw;
|
|
35
|
+
private readonly normalized;
|
|
36
|
+
constructor(raw: string, normalized: string);
|
|
37
|
+
getRaw(): string;
|
|
38
|
+
getNormalized(): string;
|
|
39
|
+
toString(): string;
|
|
40
|
+
getSeries(): string;
|
|
41
|
+
getSequentialNumber(): string;
|
|
42
|
+
getCheckDigit(): string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare class Krs implements IdentifierInterface {
|
|
46
|
+
private readonly raw;
|
|
47
|
+
private readonly normalized;
|
|
48
|
+
constructor(raw: string, normalized: string);
|
|
49
|
+
getRaw(): string;
|
|
50
|
+
getNormalized(): string;
|
|
51
|
+
toString(): string;
|
|
52
|
+
getFormatted(): string;
|
|
53
|
+
getNumericValue(): number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare class Nip implements IdentifierInterface {
|
|
57
|
+
private readonly raw;
|
|
58
|
+
private readonly normalized;
|
|
59
|
+
constructor(raw: string, normalized: string);
|
|
60
|
+
getRaw(): string;
|
|
61
|
+
getNormalized(): string;
|
|
62
|
+
toString(): string;
|
|
63
|
+
getFormatted(): string;
|
|
64
|
+
getFormattedAlternative(): string;
|
|
65
|
+
getTaxOfficeCode(): string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
declare class Nrb implements IdentifierInterface {
|
|
69
|
+
private readonly raw;
|
|
70
|
+
private readonly normalized;
|
|
71
|
+
constructor(raw: string, normalized: string);
|
|
72
|
+
getRaw(): string;
|
|
73
|
+
getNormalized(): string;
|
|
74
|
+
toString(): string;
|
|
75
|
+
getFormatted(): string;
|
|
76
|
+
getIban(): string;
|
|
77
|
+
getFormattedIban(): string;
|
|
78
|
+
getCheckDigits(): string;
|
|
79
|
+
getSortCode(): string;
|
|
80
|
+
getBankCode(): string;
|
|
81
|
+
getAccountNumber(): string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
declare class Passport implements IdentifierInterface {
|
|
85
|
+
private readonly raw;
|
|
86
|
+
private readonly normalized;
|
|
87
|
+
constructor(raw: string, normalized: string);
|
|
88
|
+
getRaw(): string;
|
|
89
|
+
getNormalized(): string;
|
|
90
|
+
toString(): string;
|
|
91
|
+
getSeries(): string;
|
|
92
|
+
getSequentialNumber(): string;
|
|
93
|
+
getCheckDigit(): string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare class Pesel implements IdentifierInterface {
|
|
97
|
+
private readonly raw;
|
|
98
|
+
private readonly normalized;
|
|
99
|
+
private readonly gender;
|
|
100
|
+
private readonly ordinalNumber;
|
|
101
|
+
constructor(raw: string, normalized: string, birthDate: Date, gender: Gender, ordinalNumber: number);
|
|
102
|
+
private readonly birthDate;
|
|
103
|
+
getRaw(): string;
|
|
104
|
+
getNormalized(): string;
|
|
105
|
+
toString(): string;
|
|
106
|
+
getBirthDate(): Date;
|
|
107
|
+
getGender(): Gender;
|
|
108
|
+
getOrdinalNumber(): number;
|
|
109
|
+
isMale(): boolean;
|
|
110
|
+
isFemale(): boolean;
|
|
111
|
+
getAge(): number;
|
|
112
|
+
isAdult(): boolean;
|
|
113
|
+
getCentury(): number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
declare class Regon implements IdentifierInterface {
|
|
117
|
+
private readonly raw;
|
|
118
|
+
private readonly normalized;
|
|
119
|
+
private readonly type;
|
|
120
|
+
constructor(raw: string, normalized: string, type: RegonType);
|
|
121
|
+
getRaw(): string;
|
|
122
|
+
getNormalized(): string;
|
|
123
|
+
toString(): string;
|
|
124
|
+
getType(): RegonType;
|
|
125
|
+
getBaseRegon(): string;
|
|
126
|
+
getLocalUnitSuffix(): string | null;
|
|
127
|
+
isLocalUnit(): boolean;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
declare class VatEu implements IdentifierInterface {
|
|
131
|
+
private readonly raw;
|
|
132
|
+
private readonly normalized;
|
|
133
|
+
constructor(raw: string, normalized: string);
|
|
134
|
+
getRaw(): string;
|
|
135
|
+
getNormalized(): string;
|
|
136
|
+
toString(): string;
|
|
137
|
+
getCountryCode(): string;
|
|
138
|
+
getNip(): string;
|
|
139
|
+
getFormatted(): string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { Gender as G, type IdentifierInterface as I, Krs as K, Nip as N, Passport as P, Regon as R, VatEu as V, Iban as a, IdCard as b, Nrb as c, Pesel as d, RegonType as e };
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
interface IdentifierInterface {
|
|
2
|
+
getRaw(): string;
|
|
3
|
+
getNormalized(): string;
|
|
4
|
+
toString(): string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
declare enum Gender {
|
|
8
|
+
Male = "male",
|
|
9
|
+
Female = "female"
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare enum RegonType {
|
|
13
|
+
Individual = "individual",
|
|
14
|
+
LegalEntity = "legal_entity"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare class Iban implements IdentifierInterface {
|
|
18
|
+
private readonly raw;
|
|
19
|
+
private readonly normalized;
|
|
20
|
+
constructor(raw: string, normalized: string);
|
|
21
|
+
getRaw(): string;
|
|
22
|
+
getNormalized(): string;
|
|
23
|
+
toString(): string;
|
|
24
|
+
getFormatted(): string;
|
|
25
|
+
getCountryCode(): string;
|
|
26
|
+
getNrb(): string;
|
|
27
|
+
getCheckDigits(): string;
|
|
28
|
+
getSortCode(): string;
|
|
29
|
+
getBankCode(): string;
|
|
30
|
+
getAccountNumber(): string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare class IdCard implements IdentifierInterface {
|
|
34
|
+
private readonly raw;
|
|
35
|
+
private readonly normalized;
|
|
36
|
+
constructor(raw: string, normalized: string);
|
|
37
|
+
getRaw(): string;
|
|
38
|
+
getNormalized(): string;
|
|
39
|
+
toString(): string;
|
|
40
|
+
getSeries(): string;
|
|
41
|
+
getSequentialNumber(): string;
|
|
42
|
+
getCheckDigit(): string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
declare class Krs implements IdentifierInterface {
|
|
46
|
+
private readonly raw;
|
|
47
|
+
private readonly normalized;
|
|
48
|
+
constructor(raw: string, normalized: string);
|
|
49
|
+
getRaw(): string;
|
|
50
|
+
getNormalized(): string;
|
|
51
|
+
toString(): string;
|
|
52
|
+
getFormatted(): string;
|
|
53
|
+
getNumericValue(): number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
declare class Nip implements IdentifierInterface {
|
|
57
|
+
private readonly raw;
|
|
58
|
+
private readonly normalized;
|
|
59
|
+
constructor(raw: string, normalized: string);
|
|
60
|
+
getRaw(): string;
|
|
61
|
+
getNormalized(): string;
|
|
62
|
+
toString(): string;
|
|
63
|
+
getFormatted(): string;
|
|
64
|
+
getFormattedAlternative(): string;
|
|
65
|
+
getTaxOfficeCode(): string;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
declare class Nrb implements IdentifierInterface {
|
|
69
|
+
private readonly raw;
|
|
70
|
+
private readonly normalized;
|
|
71
|
+
constructor(raw: string, normalized: string);
|
|
72
|
+
getRaw(): string;
|
|
73
|
+
getNormalized(): string;
|
|
74
|
+
toString(): string;
|
|
75
|
+
getFormatted(): string;
|
|
76
|
+
getIban(): string;
|
|
77
|
+
getFormattedIban(): string;
|
|
78
|
+
getCheckDigits(): string;
|
|
79
|
+
getSortCode(): string;
|
|
80
|
+
getBankCode(): string;
|
|
81
|
+
getAccountNumber(): string;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
declare class Passport implements IdentifierInterface {
|
|
85
|
+
private readonly raw;
|
|
86
|
+
private readonly normalized;
|
|
87
|
+
constructor(raw: string, normalized: string);
|
|
88
|
+
getRaw(): string;
|
|
89
|
+
getNormalized(): string;
|
|
90
|
+
toString(): string;
|
|
91
|
+
getSeries(): string;
|
|
92
|
+
getSequentialNumber(): string;
|
|
93
|
+
getCheckDigit(): string;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
declare class Pesel implements IdentifierInterface {
|
|
97
|
+
private readonly raw;
|
|
98
|
+
private readonly normalized;
|
|
99
|
+
private readonly gender;
|
|
100
|
+
private readonly ordinalNumber;
|
|
101
|
+
constructor(raw: string, normalized: string, birthDate: Date, gender: Gender, ordinalNumber: number);
|
|
102
|
+
private readonly birthDate;
|
|
103
|
+
getRaw(): string;
|
|
104
|
+
getNormalized(): string;
|
|
105
|
+
toString(): string;
|
|
106
|
+
getBirthDate(): Date;
|
|
107
|
+
getGender(): Gender;
|
|
108
|
+
getOrdinalNumber(): number;
|
|
109
|
+
isMale(): boolean;
|
|
110
|
+
isFemale(): boolean;
|
|
111
|
+
getAge(): number;
|
|
112
|
+
isAdult(): boolean;
|
|
113
|
+
getCentury(): number;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
declare class Regon implements IdentifierInterface {
|
|
117
|
+
private readonly raw;
|
|
118
|
+
private readonly normalized;
|
|
119
|
+
private readonly type;
|
|
120
|
+
constructor(raw: string, normalized: string, type: RegonType);
|
|
121
|
+
getRaw(): string;
|
|
122
|
+
getNormalized(): string;
|
|
123
|
+
toString(): string;
|
|
124
|
+
getType(): RegonType;
|
|
125
|
+
getBaseRegon(): string;
|
|
126
|
+
getLocalUnitSuffix(): string | null;
|
|
127
|
+
isLocalUnit(): boolean;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
declare class VatEu implements IdentifierInterface {
|
|
131
|
+
private readonly raw;
|
|
132
|
+
private readonly normalized;
|
|
133
|
+
constructor(raw: string, normalized: string);
|
|
134
|
+
getRaw(): string;
|
|
135
|
+
getNormalized(): string;
|
|
136
|
+
toString(): string;
|
|
137
|
+
getCountryCode(): string;
|
|
138
|
+
getNip(): string;
|
|
139
|
+
getFormatted(): string;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export { Gender as G, type IdentifierInterface as I, Krs as K, Nip as N, Passport as P, Regon as R, VatEu as V, Iban as a, IdCard as b, Nrb as c, Pesel as d, RegonType as e };
|