identification-validator 3.0.5 → 3.0.6
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/dist/index.cjs +59 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +59 -54
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -17,37 +17,37 @@ var o = (n2, s2, c2) => {
|
|
|
17
17
|
if (!r(s2)) return false;
|
|
18
18
|
if (Array.isArray(n2)) {
|
|
19
19
|
if (!Array.isArray(s2)) return false;
|
|
20
|
-
let t2 = [], r2 = [],
|
|
20
|
+
let t2 = [], r2 = [], u = [];
|
|
21
21
|
for (const o2 of n2.keys()) {
|
|
22
22
|
const s3 = n2[o2];
|
|
23
|
-
i(s3) && s3[e] ?
|
|
23
|
+
i(s3) && s3[e] ? u.push(s3) : u.length ? r2.push(s3) : t2.push(s3);
|
|
24
24
|
}
|
|
25
|
-
if (
|
|
26
|
-
if (
|
|
25
|
+
if (u.length) {
|
|
26
|
+
if (u.length > 1) throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");
|
|
27
27
|
if (s2.length < t2.length + r2.length) return false;
|
|
28
28
|
const e2 = s2.slice(0, t2.length), n3 = 0 === r2.length ? [] : s2.slice(-r2.length), i2 = s2.slice(t2.length, 0 === r2.length ? Infinity : -r2.length);
|
|
29
|
-
return t2.every((t3, n4) => o(t3, e2[n4], c2)) && r2.every((t3, e3) => o(t3, n3[e3], c2)) && (0 ===
|
|
29
|
+
return t2.every((t3, n4) => o(t3, e2[n4], c2)) && r2.every((t3, e3) => o(t3, n3[e3], c2)) && (0 === u.length || o(u[0], i2, c2));
|
|
30
30
|
}
|
|
31
31
|
return n2.length === s2.length && n2.every((t3, e2) => o(t3, s2[e2], c2));
|
|
32
32
|
}
|
|
33
33
|
return Reflect.ownKeys(n2).every((e2) => {
|
|
34
34
|
const r2 = n2[e2];
|
|
35
|
-
return (e2 in s2 || i(
|
|
36
|
-
var
|
|
35
|
+
return (e2 in s2 || i(u = r2) && "optional" === u[t]().matcherType) && o(r2, s2[e2], c2);
|
|
36
|
+
var u;
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
39
|
return Object.is(s2, n2);
|
|
40
40
|
};
|
|
41
41
|
var s = (e2) => {
|
|
42
|
-
var n2, o2,
|
|
43
|
-
return r(e2) ? i(e2) ? null != (n2 = null == (o2 = (
|
|
42
|
+
var n2, o2, u;
|
|
43
|
+
return r(e2) ? i(e2) ? null != (n2 = null == (o2 = (u = e2[t]()).getSelectionKeys) ? void 0 : o2.call(u)) ? n2 : [] : Array.isArray(e2) ? c(e2, s) : c(Object.values(e2), s) : [];
|
|
44
44
|
};
|
|
45
45
|
var c = (t2, e2) => t2.reduce((t3, n2) => t3.concat(e2(n2)), []);
|
|
46
|
-
function
|
|
47
|
-
return Object.assign(t2, { optional: () => h(t2), and: (e2) =>
|
|
46
|
+
function a(t2) {
|
|
47
|
+
return Object.assign(t2, { optional: () => h(t2), and: (e2) => d(t2, e2), or: (e2) => y(t2, e2), select: (e2) => void 0 === e2 ? v(t2) : v(e2, t2) });
|
|
48
48
|
}
|
|
49
49
|
function h(e2) {
|
|
50
|
-
return
|
|
50
|
+
return a({ [t]: () => ({ match: (t2) => {
|
|
51
51
|
let n2 = {};
|
|
52
52
|
const r2 = (t3, e3) => {
|
|
53
53
|
n2[t3] = e3;
|
|
@@ -55,8 +55,8 @@ function h(e2) {
|
|
|
55
55
|
return void 0 === t2 ? (s(e2).forEach((t3) => r2(t3, void 0)), { matched: true, selections: n2 }) : { matched: o(e2, t2, r2), selections: n2 };
|
|
56
56
|
}, getSelectionKeys: () => s(e2), matcherType: "optional" }) });
|
|
57
57
|
}
|
|
58
|
-
function
|
|
59
|
-
return
|
|
58
|
+
function d(...e2) {
|
|
59
|
+
return a({ [t]: () => ({ match: (t2) => {
|
|
60
60
|
let n2 = {};
|
|
61
61
|
const r2 = (t3, e3) => {
|
|
62
62
|
n2[t3] = e3;
|
|
@@ -64,8 +64,8 @@ function m(...e2) {
|
|
|
64
64
|
return { matched: e2.every((e3) => o(e3, t2, r2)), selections: n2 };
|
|
65
65
|
}, getSelectionKeys: () => c(e2, s), matcherType: "and" }) });
|
|
66
66
|
}
|
|
67
|
-
function
|
|
68
|
-
return
|
|
67
|
+
function y(...e2) {
|
|
68
|
+
return a({ [t]: () => ({ match: (t2) => {
|
|
69
69
|
let n2 = {};
|
|
70
70
|
const r2 = (t3, e3) => {
|
|
71
71
|
n2[t3] = e3;
|
|
@@ -76,58 +76,60 @@ function d(...e2) {
|
|
|
76
76
|
function p(e2) {
|
|
77
77
|
return { [t]: () => ({ match: (t2) => ({ matched: Boolean(e2(t2)) }) }) };
|
|
78
78
|
}
|
|
79
|
-
function
|
|
79
|
+
function v(...e2) {
|
|
80
80
|
const r2 = "string" == typeof e2[0] ? e2[0] : void 0, i2 = 2 === e2.length ? e2[1] : "string" == typeof e2[0] ? void 0 : e2[0];
|
|
81
|
-
return
|
|
81
|
+
return a({ [t]: () => ({ match: (t2) => {
|
|
82
82
|
let e3 = { [null != r2 ? r2 : n]: t2 };
|
|
83
83
|
return { matched: void 0 === i2 || o(i2, t2, (t3, n2) => {
|
|
84
84
|
e3[t3] = n2;
|
|
85
85
|
}), selections: e3 };
|
|
86
86
|
}, getSelectionKeys: () => [null != r2 ? r2 : n].concat(void 0 === i2 ? [] : s(i2)) }) });
|
|
87
87
|
}
|
|
88
|
-
function
|
|
88
|
+
function b(t2) {
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
function w(t2) {
|
|
89
92
|
return "number" == typeof t2;
|
|
90
93
|
}
|
|
91
|
-
function
|
|
94
|
+
function S(t2) {
|
|
92
95
|
return "string" == typeof t2;
|
|
93
96
|
}
|
|
94
|
-
function
|
|
97
|
+
function j(t2) {
|
|
95
98
|
return "bigint" == typeof t2;
|
|
96
99
|
}
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
return j(m(t2, (n2 = e2, p((t3) => b(t3) && t3.startsWith(n2)))));
|
|
100
|
+
var K = a(p(b));
|
|
101
|
+
var O = a(p(b));
|
|
102
|
+
var x = (t2) => Object.assign(a(t2), { startsWith: (e2) => {
|
|
103
|
+
return x(d(t2, (n2 = e2, p((t3) => S(t3) && t3.startsWith(n2)))));
|
|
102
104
|
var n2;
|
|
103
105
|
}, endsWith: (e2) => {
|
|
104
|
-
return
|
|
106
|
+
return x(d(t2, (n2 = e2, p((t3) => S(t3) && t3.endsWith(n2)))));
|
|
105
107
|
var n2;
|
|
106
|
-
}, minLength: (e2) =>
|
|
107
|
-
return
|
|
108
|
+
}, minLength: (e2) => x(d(t2, ((t3) => p((e3) => S(e3) && e3.length >= t3))(e2))), length: (e2) => x(d(t2, ((t3) => p((e3) => S(e3) && e3.length === t3))(e2))), maxLength: (e2) => x(d(t2, ((t3) => p((e3) => S(e3) && e3.length <= t3))(e2))), includes: (e2) => {
|
|
109
|
+
return x(d(t2, (n2 = e2, p((t3) => S(t3) && t3.includes(n2)))));
|
|
108
110
|
var n2;
|
|
109
111
|
}, regex: (e2) => {
|
|
110
|
-
return
|
|
112
|
+
return x(d(t2, (n2 = e2, p((t3) => S(t3) && Boolean(t3.match(n2))))));
|
|
111
113
|
var n2;
|
|
112
114
|
} });
|
|
113
|
-
var
|
|
114
|
-
var
|
|
115
|
-
var
|
|
116
|
-
var
|
|
117
|
-
var
|
|
118
|
-
var
|
|
115
|
+
var A = x(p(S));
|
|
116
|
+
var N = (t2) => Object.assign(a(t2), { between: (e2, n2) => N(d(t2, ((t3, e3) => p((n3) => w(n3) && t3 <= n3 && e3 >= n3))(e2, n2))), lt: (e2) => N(d(t2, ((t3) => p((e3) => w(e3) && e3 < t3))(e2))), gt: (e2) => N(d(t2, ((t3) => p((e3) => w(e3) && e3 > t3))(e2))), lte: (e2) => N(d(t2, ((t3) => p((e3) => w(e3) && e3 <= t3))(e2))), gte: (e2) => N(d(t2, ((t3) => p((e3) => w(e3) && e3 >= t3))(e2))), int: () => N(d(t2, p((t3) => w(t3) && Number.isInteger(t3)))), finite: () => N(d(t2, p((t3) => w(t3) && Number.isFinite(t3)))), positive: () => N(d(t2, p((t3) => w(t3) && t3 > 0))), negative: () => N(d(t2, p((t3) => w(t3) && t3 < 0))) });
|
|
117
|
+
var P = N(p(w));
|
|
118
|
+
var k = (t2) => Object.assign(a(t2), { between: (e2, n2) => k(d(t2, ((t3, e3) => p((n3) => j(n3) && t3 <= n3 && e3 >= n3))(e2, n2))), lt: (e2) => k(d(t2, ((t3) => p((e3) => j(e3) && e3 < t3))(e2))), gt: (e2) => k(d(t2, ((t3) => p((e3) => j(e3) && e3 > t3))(e2))), lte: (e2) => k(d(t2, ((t3) => p((e3) => j(e3) && e3 <= t3))(e2))), gte: (e2) => k(d(t2, ((t3) => p((e3) => j(e3) && e3 >= t3))(e2))), positive: () => k(d(t2, p((t3) => j(t3) && t3 > 0))), negative: () => k(d(t2, p((t3) => j(t3) && t3 < 0))) });
|
|
119
|
+
var T = k(p(j));
|
|
120
|
+
var B = a(p(function(t2) {
|
|
119
121
|
return "boolean" == typeof t2;
|
|
120
122
|
}));
|
|
121
|
-
var
|
|
123
|
+
var _ = a(p(function(t2) {
|
|
122
124
|
return "symbol" == typeof t2;
|
|
123
125
|
}));
|
|
124
|
-
var
|
|
126
|
+
var W = a(p(function(t2) {
|
|
125
127
|
return null == t2;
|
|
126
128
|
}));
|
|
127
|
-
var
|
|
129
|
+
var $ = a(p(function(t2) {
|
|
128
130
|
return null != t2;
|
|
129
131
|
}));
|
|
130
|
-
var
|
|
132
|
+
var I = class extends Error {
|
|
131
133
|
constructor(t2) {
|
|
132
134
|
let e2;
|
|
133
135
|
try {
|
|
@@ -138,11 +140,11 @@ var W = class extends Error {
|
|
|
138
140
|
super(`Pattern matching error: no pattern matches value ${e2}`), this.input = void 0, this.input = t2;
|
|
139
141
|
}
|
|
140
142
|
};
|
|
141
|
-
var
|
|
142
|
-
function
|
|
143
|
-
return new
|
|
143
|
+
var L = { matched: false, value: void 0 };
|
|
144
|
+
function M(t2) {
|
|
145
|
+
return new R(t2, L);
|
|
144
146
|
}
|
|
145
|
-
var
|
|
147
|
+
var R = class _R {
|
|
146
148
|
constructor(t2, e2) {
|
|
147
149
|
this.input = void 0, this.state = void 0, this.input = t2, this.state = e2;
|
|
148
150
|
}
|
|
@@ -152,20 +154,20 @@ var I = class _I {
|
|
|
152
154
|
let i2;
|
|
153
155
|
3 === t2.length && "function" == typeof t2[1] ? i2 = t2[1] : t2.length > 2 && r2.push(...t2.slice(1, t2.length - 1));
|
|
154
156
|
let s2 = false, c2 = {};
|
|
155
|
-
const
|
|
157
|
+
const u = (t3, e3) => {
|
|
156
158
|
s2 = true, c2[t3] = e3;
|
|
157
|
-
},
|
|
158
|
-
return new
|
|
159
|
+
}, a2 = !r2.some((t3) => o(t3, this.input, u)) || i2 && !Boolean(i2(this.input)) ? L : { matched: true, value: e2(s2 ? n in c2 ? c2[n] : c2 : this.input, this.input) };
|
|
160
|
+
return new _R(this.input, a2);
|
|
159
161
|
}
|
|
160
162
|
when(t2, e2) {
|
|
161
163
|
if (this.state.matched) return this;
|
|
162
164
|
const n2 = Boolean(t2(this.input));
|
|
163
|
-
return new
|
|
165
|
+
return new _R(this.input, n2 ? { matched: true, value: e2(this.input, this.input) } : L);
|
|
164
166
|
}
|
|
165
167
|
otherwise(t2) {
|
|
166
168
|
return this.state.matched ? this.state.value : t2(this.input);
|
|
167
169
|
}
|
|
168
|
-
exhaustive(t2 =
|
|
170
|
+
exhaustive(t2 = F) {
|
|
169
171
|
return this.state.matched ? this.state.value : t2(this.input);
|
|
170
172
|
}
|
|
171
173
|
run() {
|
|
@@ -174,9 +176,12 @@ var I = class _I {
|
|
|
174
176
|
returnType() {
|
|
175
177
|
return this;
|
|
176
178
|
}
|
|
179
|
+
narrow() {
|
|
180
|
+
return this;
|
|
181
|
+
}
|
|
177
182
|
};
|
|
178
|
-
function
|
|
179
|
-
throw new
|
|
183
|
+
function F(t2) {
|
|
184
|
+
throw new I(t2);
|
|
180
185
|
}
|
|
181
186
|
|
|
182
187
|
// src/utils.ts
|
|
@@ -205,7 +210,7 @@ function getChecksumChar({
|
|
|
205
210
|
const weights = [2, 7, 6, 5, 4, 3, 2];
|
|
206
211
|
const st = ["J", "Z", "I", "H", "G", "F", "E", "D", "C", "B", "A"];
|
|
207
212
|
const fg = ["X", "W", "U", "T", "R", "Q", "P", "N", "M", "L", "K"];
|
|
208
|
-
const
|
|
213
|
+
const m = ["K", "L", "J", "N", "P", "Q", "R", "T", "U", "W", "X"];
|
|
209
214
|
const sum = idNumbers.reduce(
|
|
210
215
|
(acc, digit, idx) => acc + digit * weights[idx],
|
|
211
216
|
0
|
|
@@ -225,7 +230,7 @@ function getChecksumChar({
|
|
|
225
230
|
if (prefix === "F" || prefix === "G") {
|
|
226
231
|
expectedChar = fg[checksumIndex];
|
|
227
232
|
} else if (prefix === "M") {
|
|
228
|
-
expectedChar =
|
|
233
|
+
expectedChar = m[checksumIndex];
|
|
229
234
|
}
|
|
230
235
|
}
|
|
231
236
|
return expectedChar;
|
|
@@ -245,7 +250,7 @@ function generateByType(type) {
|
|
|
245
250
|
return randomPrefix + randomDigits + checksum;
|
|
246
251
|
}
|
|
247
252
|
function generateID({ type }) {
|
|
248
|
-
return
|
|
253
|
+
return M(type).with("NRIC", () => generateByType("NRIC")).with("FIN", () => generateByType("FIN")).with("BOTH", () => generateByType(Math.random() < 0.5 ? "NRIC" : "FIN")).exhaustive();
|
|
249
254
|
}
|
|
250
255
|
|
|
251
256
|
// src/validator.ts
|