anonyma 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/CHANGELOG.md +457 -0
- package/LICENSE +21 -0
- package/README.md +605 -0
- package/dist/crypto.cjs +142 -0
- package/dist/crypto.cjs.map +1 -0
- package/dist/crypto.d.cts +51 -0
- package/dist/crypto.d.ts +51 -0
- package/dist/crypto.js +139 -0
- package/dist/crypto.js.map +1 -0
- package/dist/detectors/index.cjs +1487 -0
- package/dist/detectors/index.cjs.map +1 -0
- package/dist/detectors/index.d.cts +754 -0
- package/dist/detectors/index.d.ts +754 -0
- package/dist/detectors/index.js +1451 -0
- package/dist/detectors/index.js.map +1 -0
- package/dist/index.cjs +2877 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +772 -0
- package/dist/index.d.ts +772 -0
- package/dist/index.js +2850 -0
- package/dist/index.js.map +1 -0
- package/dist/schemas.cjs +361 -0
- package/dist/schemas.cjs.map +1 -0
- package/dist/schemas.d.cts +1031 -0
- package/dist/schemas.d.ts +1031 -0
- package/dist/schemas.js +341 -0
- package/dist/schemas.js.map +1 -0
- package/dist/stream.cjs +2315 -0
- package/dist/stream.cjs.map +1 -0
- package/dist/stream.d.cts +76 -0
- package/dist/stream.d.ts +76 -0
- package/dist/stream.js +2311 -0
- package/dist/stream.js.map +1 -0
- package/dist/types-D-9HzVuy.d.cts +553 -0
- package/dist/types-D-9HzVuy.d.ts +553 -0
- package/dist/validators.cjs +186 -0
- package/dist/validators.cjs.map +1 -0
- package/dist/validators.d.cts +136 -0
- package/dist/validators.d.ts +136 -0
- package/dist/validators.js +176 -0
- package/dist/validators.js.map +1 -0
- package/package.json +158 -0
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// src/validators.ts
|
|
4
|
+
function luhn(digits) {
|
|
5
|
+
const stripped = digits.replace(/[\s-]/g, "");
|
|
6
|
+
if (!/^\d+$/.test(stripped) || stripped.length < 2) return false;
|
|
7
|
+
let sum = 0;
|
|
8
|
+
let isEven = false;
|
|
9
|
+
for (let i = stripped.length - 1; i >= 0; i--) {
|
|
10
|
+
let d = parseInt(stripped[i] ?? "0", 10);
|
|
11
|
+
if (isEven) {
|
|
12
|
+
d *= 2;
|
|
13
|
+
if (d > 9) d -= 9;
|
|
14
|
+
}
|
|
15
|
+
sum += d;
|
|
16
|
+
isEven = !isEven;
|
|
17
|
+
}
|
|
18
|
+
return sum % 10 === 0;
|
|
19
|
+
}
|
|
20
|
+
var VERHOEFF_D = [
|
|
21
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
|
22
|
+
[1, 2, 3, 4, 0, 6, 7, 8, 9, 5],
|
|
23
|
+
[2, 3, 4, 0, 1, 7, 8, 9, 5, 6],
|
|
24
|
+
[3, 4, 0, 1, 2, 8, 9, 5, 6, 7],
|
|
25
|
+
[4, 0, 1, 2, 3, 9, 5, 6, 7, 8],
|
|
26
|
+
[5, 9, 8, 7, 6, 0, 4, 3, 2, 1],
|
|
27
|
+
[6, 5, 9, 8, 7, 1, 0, 4, 3, 2],
|
|
28
|
+
[7, 6, 5, 9, 8, 2, 1, 0, 4, 3],
|
|
29
|
+
[8, 7, 6, 5, 9, 3, 2, 1, 0, 4],
|
|
30
|
+
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
|
|
31
|
+
];
|
|
32
|
+
var VERHOEFF_P = [
|
|
33
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
|
34
|
+
[1, 5, 7, 6, 2, 8, 3, 0, 9, 4],
|
|
35
|
+
[5, 8, 0, 3, 7, 9, 6, 1, 4, 2],
|
|
36
|
+
[8, 9, 1, 6, 0, 4, 3, 5, 2, 7],
|
|
37
|
+
[9, 4, 5, 3, 1, 2, 6, 8, 7, 0],
|
|
38
|
+
[4, 2, 8, 6, 5, 7, 3, 9, 0, 1],
|
|
39
|
+
[2, 7, 9, 3, 8, 0, 6, 4, 1, 5],
|
|
40
|
+
[7, 0, 4, 6, 9, 1, 3, 2, 5, 8]
|
|
41
|
+
];
|
|
42
|
+
function verhoeff(digits) {
|
|
43
|
+
const stripped = digits.replace(/[\s-]/g, "");
|
|
44
|
+
if (!/^\d+$/.test(stripped) || stripped.length === 0) return false;
|
|
45
|
+
let c = 0;
|
|
46
|
+
const reversed = stripped.split("").reverse();
|
|
47
|
+
for (let i = 0; i < reversed.length; i++) {
|
|
48
|
+
const digit = parseInt(reversed[i] ?? "0", 10);
|
|
49
|
+
const pRow = VERHOEFF_P[i % 8];
|
|
50
|
+
const pVal = pRow ? pRow[digit] ?? digit : digit;
|
|
51
|
+
const dRow = VERHOEFF_D[c];
|
|
52
|
+
c = dRow ? dRow[pVal] ?? 0 : 0;
|
|
53
|
+
}
|
|
54
|
+
return c === 0;
|
|
55
|
+
}
|
|
56
|
+
function nhsMod11(value) {
|
|
57
|
+
const stripped = value.replace(/[\s-]/g, "");
|
|
58
|
+
if (!/^\d{10}$/.test(stripped)) return false;
|
|
59
|
+
let sum = 0;
|
|
60
|
+
for (let i = 0; i < 9; i++) {
|
|
61
|
+
sum += parseInt(stripped[i] ?? "0", 10) * (10 - i);
|
|
62
|
+
}
|
|
63
|
+
const remainder = sum % 11;
|
|
64
|
+
if (remainder === 1) return false;
|
|
65
|
+
const checkDigit = remainder === 0 ? 0 : 11 - remainder;
|
|
66
|
+
return parseInt(stripped[9] ?? "0", 10) === checkDigit;
|
|
67
|
+
}
|
|
68
|
+
function cpfChecksum(value) {
|
|
69
|
+
const stripped = value.replace(/[.\-\s]/g, "");
|
|
70
|
+
if (!/^\d{11}$/.test(stripped)) return false;
|
|
71
|
+
if (/^(\d)\1{10}$/.test(stripped)) return false;
|
|
72
|
+
let sum = 0;
|
|
73
|
+
for (let i = 0; i < 9; i++) {
|
|
74
|
+
sum += parseInt(stripped[i] ?? "0", 10) * (10 - i);
|
|
75
|
+
}
|
|
76
|
+
let remainder = sum * 10 % 11;
|
|
77
|
+
if (remainder === 10 || remainder === 11) remainder = 0;
|
|
78
|
+
if (remainder !== parseInt(stripped[9] ?? "0", 10)) return false;
|
|
79
|
+
sum = 0;
|
|
80
|
+
for (let i = 0; i < 10; i++) {
|
|
81
|
+
sum += parseInt(stripped[i] ?? "0", 10) * (11 - i);
|
|
82
|
+
}
|
|
83
|
+
remainder = sum * 10 % 11;
|
|
84
|
+
if (remainder === 10 || remainder === 11) remainder = 0;
|
|
85
|
+
return remainder === parseInt(stripped[10] ?? "0", 10);
|
|
86
|
+
}
|
|
87
|
+
var VIN_TRANSLITERATION = {
|
|
88
|
+
A: 1,
|
|
89
|
+
B: 2,
|
|
90
|
+
C: 3,
|
|
91
|
+
D: 4,
|
|
92
|
+
E: 5,
|
|
93
|
+
F: 6,
|
|
94
|
+
G: 7,
|
|
95
|
+
H: 8,
|
|
96
|
+
J: 1,
|
|
97
|
+
K: 2,
|
|
98
|
+
L: 3,
|
|
99
|
+
M: 4,
|
|
100
|
+
N: 5,
|
|
101
|
+
P: 7,
|
|
102
|
+
R: 9,
|
|
103
|
+
S: 2,
|
|
104
|
+
T: 3,
|
|
105
|
+
U: 4,
|
|
106
|
+
V: 5,
|
|
107
|
+
W: 6,
|
|
108
|
+
X: 7,
|
|
109
|
+
Y: 8,
|
|
110
|
+
Z: 9,
|
|
111
|
+
0: 0,
|
|
112
|
+
1: 1,
|
|
113
|
+
2: 2,
|
|
114
|
+
3: 3,
|
|
115
|
+
4: 4,
|
|
116
|
+
5: 5,
|
|
117
|
+
6: 6,
|
|
118
|
+
7: 7,
|
|
119
|
+
8: 8,
|
|
120
|
+
9: 9
|
|
121
|
+
};
|
|
122
|
+
var VIN_WEIGHTS = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
123
|
+
function vinChecksum(vin) {
|
|
124
|
+
const upper = vin.toUpperCase();
|
|
125
|
+
if (!/^[A-HJ-NPR-Z0-9]{17}$/.test(upper)) return false;
|
|
126
|
+
let sum = 0;
|
|
127
|
+
for (let i = 0; i < 17; i++) {
|
|
128
|
+
const char = upper[i] ?? "";
|
|
129
|
+
const val = VIN_TRANSLITERATION[char];
|
|
130
|
+
const weight = VIN_WEIGHTS[i];
|
|
131
|
+
if (val === void 0 || weight === void 0) return false;
|
|
132
|
+
sum += val * weight;
|
|
133
|
+
}
|
|
134
|
+
const remainder = sum % 11;
|
|
135
|
+
const checkChar = upper[8] ?? "";
|
|
136
|
+
const expected = remainder === 10 ? "X" : String(remainder);
|
|
137
|
+
return checkChar === expected;
|
|
138
|
+
}
|
|
139
|
+
function deaChecksum(value) {
|
|
140
|
+
const stripped = value.replace(/[\s-]/g, "").toUpperCase();
|
|
141
|
+
if (!/^[ABCDEFGHJKLMNPRSTUX][A-Z9]\d{7}$/.test(stripped)) return false;
|
|
142
|
+
const digits = stripped.slice(2);
|
|
143
|
+
const oddSum = parseInt(digits[0] ?? "0", 10) + parseInt(digits[2] ?? "0", 10) + parseInt(digits[4] ?? "0", 10);
|
|
144
|
+
const evenSum = parseInt(digits[1] ?? "0", 10) + parseInt(digits[3] ?? "0", 10) + parseInt(digits[5] ?? "0", 10);
|
|
145
|
+
const checksum = (oddSum + 2 * evenSum) % 10;
|
|
146
|
+
return checksum === parseInt(digits[6] ?? "0", 10);
|
|
147
|
+
}
|
|
148
|
+
function ibanMod97(value) {
|
|
149
|
+
const stripped = value.replace(/\s/g, "").toUpperCase();
|
|
150
|
+
if (stripped.length < 15 || stripped.length > 34) return false;
|
|
151
|
+
const rearranged = stripped.slice(4) + stripped.slice(0, 4);
|
|
152
|
+
const numeric = rearranged.split("").map((c) => {
|
|
153
|
+
const code = c.charCodeAt(0);
|
|
154
|
+
return code >= 65 && code <= 90 ? String(code - 55) : c;
|
|
155
|
+
}).join("");
|
|
156
|
+
let remainder = 0;
|
|
157
|
+
for (let i = 0; i < numeric.length; i += 7) {
|
|
158
|
+
const chunk = String(remainder) + numeric.slice(i, i + 7);
|
|
159
|
+
remainder = parseInt(chunk, 10) % 97;
|
|
160
|
+
}
|
|
161
|
+
return remainder === 1;
|
|
162
|
+
}
|
|
163
|
+
function ninoValid(value) {
|
|
164
|
+
const stripped = value.replace(/\s/g, "").toUpperCase();
|
|
165
|
+
if (!/^[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z]\d{6}[A-D]$/.test(stripped)) return false;
|
|
166
|
+
const invalidPrefixes = ["BG", "GB", "KN", "NK", "NT", "TN", "ZZ"];
|
|
167
|
+
const prefix = stripped.slice(0, 2);
|
|
168
|
+
return !invalidPrefixes.includes(prefix);
|
|
169
|
+
}
|
|
170
|
+
function aadhaarFormat(value) {
|
|
171
|
+
const stripped = value.replace(/[\s-]/g, "");
|
|
172
|
+
if (!/^\d{12}$/.test(stripped)) return false;
|
|
173
|
+
return !stripped.startsWith("0") && !stripped.startsWith("1");
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
exports.aadhaarFormat = aadhaarFormat;
|
|
177
|
+
exports.cpfChecksum = cpfChecksum;
|
|
178
|
+
exports.deaChecksum = deaChecksum;
|
|
179
|
+
exports.ibanMod97 = ibanMod97;
|
|
180
|
+
exports.luhn = luhn;
|
|
181
|
+
exports.nhsMod11 = nhsMod11;
|
|
182
|
+
exports.ninoValid = ninoValid;
|
|
183
|
+
exports.verhoeff = verhoeff;
|
|
184
|
+
exports.vinChecksum = vinChecksum;
|
|
185
|
+
//# sourceMappingURL=validators.cjs.map
|
|
186
|
+
//# sourceMappingURL=validators.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/validators.ts"],"names":[],"mappings":";;;AAiCO,SAAS,KAAK,MAAA,EAAyB;AAC5C,EAAA,MAAM,QAAA,GAAW,MAAA,CAAO,OAAA,CAAQ,QAAA,EAAU,EAAE,CAAA;AAC5C,EAAA,IAAI,CAAC,QAAQ,IAAA,CAAK,QAAQ,KAAK,QAAA,CAAS,MAAA,GAAS,GAAG,OAAO,KAAA;AAE3D,EAAA,IAAI,G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,IAAA,EAAM,IAAA,EAAM,MAAM,IAAA,EAAM,IAAA,EAAM,MAAM,IAAI,CAAA;AACjE,EAAA,MAAM,MAAA,GAAS,QAAA,CAAS,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA;AAClC,EAAA,OAAO,CAAC,eAAA,CAAgB,QAAA,CAAS,MAAM,CAAA;AACzC;AAaO,SAAS,cAAc,KAAA,EAAwB;AACpD,EAAA,MAAM,QAAA,GAAW,KAAA,CAAM,OAAA,CAAQ,QAAA,EAAU,EAAE,CAAA;AAC3C,EAAA,IAAI,CAAC,UAAA,CAAW,IAAA,CAAK,QAAQ,GAAG,OAAO,KAAA;AAEvC,EAAA,OAAO,CAAC,SAAS,UAAA,CAAW,GAAG,KAAK,CAAC,QAAA,CAAS,WAAW,GAAG,CAAA;AAC9D","file":"validators.cjs","sourcesContent":["/**\n * @module validators\n * @description PII checksum and format validation algorithms.\n *\n * All validators are pure functions that accept a string and return a boolean.\n * Export them from `\"anonyma/validators\"` for standalone use.\n *\n * @example\n * ```ts\n * import { luhn, verhoeff, nhsMod11, cpfChecksum } from \"anonyma/validators\";\n *\n * luhn(\"4111111111111111\"); // true\n * nhsMod11(\"943-476-5919\"); // true\n * ```\n */\n\n// ---------------------------------------------------------------------------\n// Luhn Algorithm (credit cards, some national IDs)\n// ---------------------------------------------------------------------------\n\n/**\n * Validate a string of digits using the Luhn algorithm (ISO/IEC 7812).\n * Used for credit/debit card numbers and some national IDs.\n *\n * @param digits - Digit-only string (spaces/hyphens stripped before calling).\n * @returns `true` if the number passes the Luhn check.\n *\n * @example\n * ```ts\n * luhn(\"4111111111111111\"); // true\n * luhn(\"4111111111111112\"); // false\n * ```\n */\nexport function luhn(digits: string): boolean {\n const stripped = digits.replace(/[\\s-]/g, \"\");\n if (!/^\\d+$/.test(stripped) || stripped.length < 2) return false;\n\n let sum = 0;\n let isEven = false;\n\n for (let i = stripped.length - 1; i >= 0; i--) {\n /* v8 ignore next -- regex guarantees digit chars so stripped[i] is always defined */\n let d = parseInt(stripped[i] ?? \"0\", 10);\n if (isEven) {\n d *= 2;\n if (d > 9) d -= 9;\n }\n sum += d;\n isEven = !isEven;\n }\n\n return sum % 10 === 0;\n}\n\n// ---------------------------------------------------------------------------\n// Verhoeff Algorithm (Indian Aadhaar and others)\n// ---------------------------------------------------------------------------\n\n/** Verhoeff multiplication table. @internal */\nconst VERHOEFF_D: readonly number[][] = [\n [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],\n [1, 2, 3, 4, 0, 6, 7, 8, 9, 5],\n [2, 3, 4, 0, 1, 7, 8, 9, 5, 6],\n [3, 4, 0, 1, 2, 8, 9, 5, 6, 7],\n [4, 0, 1, 2, 3, 9, 5, 6, 7, 8],\n [5, 9, 8, 7, 6, 0, 4, 3, 2, 1],\n [6, 5, 9, 8, 7, 1, 0, 4, 3, 2],\n [7, 6, 5, 9, 8, 2, 1, 0, 4, 3],\n [8, 7, 6, 5, 9, 3, 2, 1, 0, 4],\n [9, 8, 7, 6, 5, 4, 3, 2, 1, 0],\n];\n\n/** Verhoeff permutation table. @internal */\nconst VERHOEFF_P: readonly number[][] = [\n [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],\n [1, 5, 7, 6, 2, 8, 3, 0, 9, 4],\n [5, 8, 0, 3, 7, 9, 6, 1, 4, 2],\n [8, 9, 1, 6, 0, 4, 3, 5, 2, 7],\n [9, 4, 5, 3, 1, 2, 6, 8, 7, 0],\n [4, 2, 8, 6, 5, 7, 3, 9, 0, 1],\n [2, 7, 9, 3, 8, 0, 6, 4, 1, 5],\n [7, 0, 4, 6, 9, 1, 3, 2, 5, 8],\n];\n\n/**\n * Validate a digit string using the Verhoeff algorithm.\n * Used for Indian Aadhaar numbers and some other national IDs.\n *\n * @param digits - Digit-only string.\n * @returns `true` if the number passes the Verhoeff check.\n *\n * @example\n * ```ts\n * verhoeff(\"236\"); // true (canonical Verhoeff test case)\n * ```\n */\nexport function verhoeff(digits: string): boolean {\n const stripped = digits.replace(/[\\s-]/g, \"\");\n if (!/^\\d+$/.test(stripped) || stripped.length === 0) return false;\n\n let c = 0;\n const reversed = stripped.split(\"\").reverse();\n\n for (let i = 0; i < reversed.length; i++) {\n /* v8 ignore next -- reversed array is same length as stripped so reversed[i] is always defined */\n const digit = parseInt(reversed[i] ?? \"0\", 10);\n const pRow = VERHOEFF_P[i % 8];\n /* v8 ignore next 3 -- lookup tables always cover valid indices (0-7 for P, 0-9 for D) */\n const pVal = pRow ? pRow[digit] ?? digit : digit;\n const dRow = VERHOEFF_D[c];\n c = dRow ? dRow[pVal] ?? 0 : 0;\n }\n\n return c === 0;\n}\n\n// ---------------------------------------------------------------------------\n// NHS Mod-11 (UK NHS numbers)\n// ---------------------------------------------------------------------------\n\n/**\n * Validate a UK NHS number using the mod-11 algorithm.\n * NHS numbers are 10 digits. Weighting factors are 10..2 for the first 9 digits;\n * the 10th digit is the check digit (11 - sum mod 11, or 0 if sum mod 11 == 0).\n *\n * @param value - NHS number (digits or with spaces/hyphens).\n * @returns `true` if valid.\n *\n * @example\n * ```ts\n * nhsMod11(\"9434765919\"); // true\n * nhsMod11(\"943 476 5919\"); // true\n * ```\n */\nexport function nhsMod11(value: string): boolean {\n const stripped = value.replace(/[\\s-]/g, \"\");\n if (!/^\\d{10}$/.test(stripped)) return false;\n\n let sum = 0;\n /* v8 ignore start -- regex guarantees \\d{10} so indices 0-9 are always defined */\n for (let i = 0; i < 9; i++) {\n sum += parseInt(stripped[i] ?? \"0\", 10) * (10 - i);\n }\n /* v8 ignore stop */\n\n const remainder = sum % 11;\n if (remainder === 1) return false; // Invalid NHS number\n const checkDigit = remainder === 0 ? 0 : 11 - remainder;\n\n /* v8 ignore next -- regex guarantees \\d{10} so stripped[9] is always defined */\n return parseInt(stripped[9] ?? \"0\", 10) === checkDigit;\n}\n\n// ---------------------------------------------------------------------------\n// Brazilian CPF Checksum\n// ---------------------------------------------------------------------------\n\n/**\n * Validate a Brazilian CPF (Cadastro de Pessoas Físicas) number.\n * CPF has 11 digits with two check digits at positions 10 and 11.\n *\n * @param value - CPF with or without formatting (e.g. `\"123.456.789-09\"` or `\"12345678909\"`).\n * @returns `true` if valid.\n *\n * @example\n * ```ts\n * cpfChecksum(\"529.982.247-25\"); // true\n * cpfChecksum(\"529.982.247-26\"); // false\n * ```\n */\nexport function cpfChecksum(value: string): boolean {\n const stripped = value.replace(/[.\\-\\s]/g, \"\");\n if (!/^\\d{11}$/.test(stripped)) return false;\n\n // Reject known invalid patterns (all same digit)\n if (/^(\\d)\\1{10}$/.test(stripped)) return false;\n\n // Compute first check digit\n let sum = 0;\n /* v8 ignore start -- regex guarantees \\d{11} so all string indices are defined */\n for (let i = 0; i < 9; i++) {\n sum += parseInt(stripped[i] ?? \"0\", 10) * (10 - i);\n }\n let remainder = (sum * 10) % 11;\n if (remainder === 10 || remainder === 11) remainder = 0;\n if (remainder !== parseInt(stripped[9] ?? \"0\", 10)) return false;\n\n // Compute second check digit\n sum = 0;\n for (let i = 0; i < 10; i++) {\n sum += parseInt(stripped[i] ?? \"0\", 10) * (11 - i);\n }\n remainder = (sum * 10) % 11;\n if (remainder === 10 || remainder === 11) remainder = 0;\n return remainder === parseInt(stripped[10] ?? \"0\", 10);\n /* v8 ignore stop */\n}\n\n// ---------------------------------------------------------------------------\n// VIN Transliteration Checksum (ISO 3779)\n// ---------------------------------------------------------------------------\n\n/** VIN transliteration map: letters → numeric values. @internal */\nconst VIN_TRANSLITERATION: Readonly<Record<string, number>> = {\n A: 1, B: 2, C: 3, D: 4, E: 5, F: 6, G: 7, H: 8,\n J: 1, K: 2, L: 3, M: 4, N: 5, P: 7, R: 9,\n S: 2, T: 3, U: 4, V: 5, W: 6, X: 7, Y: 8, Z: 9,\n 0: 0, 1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 7: 7, 8: 8, 9: 9,\n} as const;\n\n/** VIN position weight factors (positions 1–9 = check, 1-based). @internal */\nconst VIN_WEIGHTS: readonly number[] = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2];\n\n/**\n * Validate a Vehicle Identification Number (VIN) using the ISO 3779 mod-11 checksum.\n * The check digit is position 9 (index 8).\n *\n * @param vin - 17-character VIN string. Must contain only A-Z (excluding I, O, Q) and 0-9.\n * @returns `true` if the VIN passes the checksum and has valid characters.\n *\n * @example\n * ```ts\n * vinChecksum(\"1HGBH41JXMN109186\"); // true\n * vinChecksum(\"1HGBH41JXMN109187\"); // false\n * ```\n */\nexport function vinChecksum(vin: string): boolean {\n const upper = vin.toUpperCase();\n if (!/^[A-HJ-NPR-Z0-9]{17}$/.test(upper)) return false;\n\n let sum = 0;\n for (let i = 0; i < 17; i++) {\n /* v8 ignore next -- regex guarantees 17 chars so upper[i] is always defined */\n const char = upper[i] ?? \"\";\n const val = VIN_TRANSLITERATION[char];\n const weight = VIN_WEIGHTS[i];\n /* v8 ignore next -- regex already guarantees all chars are in the translation table */\n if (val === undefined || weight === undefined) return false;\n sum += val * weight;\n }\n\n const remainder = sum % 11;\n /* v8 ignore next -- regex guarantees 17 chars so upper[8] is always defined */\n const checkChar = upper[8] ?? \"\";\n const expected = remainder === 10 ? \"X\" : String(remainder);\n\n return checkChar === expected;\n}\n\n// ---------------------------------------------------------------------------\n// DEA Registration Number Checksum\n// ---------------------------------------------------------------------------\n\n/**\n * Validate a US DEA (Drug Enforcement Administration) registration number.\n * Format: two letters (registrant type + first letter of last name) + 7 digits.\n * Check digit = (sum of digits 1,3,5 + 2 * sum of digits 2,4,6) mod 10.\n *\n * @param value - DEA number, e.g. `\"AB1234563\"`.\n * @returns `true` if valid.\n *\n * @example\n * ```ts\n * deaChecksum(\"AB1234563\"); // true\n * ```\n */\nexport function deaChecksum(value: string): boolean {\n const stripped = value.replace(/[\\s-]/g, \"\").toUpperCase();\n if (!/^[ABCDEFGHJKLMNPRSTUX][A-Z9]\\d{7}$/.test(stripped)) return false;\n\n const digits = stripped.slice(2);\n /* v8 ignore start -- regex guarantees \\d{7} so indices 0-6 are always defined */\n const oddSum = parseInt(digits[0] ?? \"0\", 10) +\n parseInt(digits[2] ?? \"0\", 10) +\n parseInt(digits[4] ?? \"0\", 10);\n const evenSum = parseInt(digits[1] ?? \"0\", 10) +\n parseInt(digits[3] ?? \"0\", 10) +\n parseInt(digits[5] ?? \"0\", 10);\n const checksum = (oddSum + 2 * evenSum) % 10;\n\n return checksum === parseInt(digits[6] ?? \"0\", 10);\n /* v8 ignore stop */\n}\n\n// ---------------------------------------------------------------------------\n// IBAN Mod-97 Checksum\n// ---------------------------------------------------------------------------\n\n/**\n * Validate an IBAN using the ISO 13616 mod-97 algorithm.\n *\n * @param value - IBAN string, with or without spaces.\n * @returns `true` if valid.\n *\n * @example\n * ```ts\n * ibanMod97(\"GB82 WEST 1234 5698 7654 32\"); // true\n * ```\n */\nexport function ibanMod97(value: string): boolean {\n const stripped = value.replace(/\\s/g, \"\").toUpperCase();\n if (stripped.length < 15 || stripped.length > 34) return false;\n\n // Move first 4 chars to end\n const rearranged = stripped.slice(4) + stripped.slice(0, 4);\n\n // Convert letters to digits (A=10, B=11, ..., Z=35)\n const numeric = rearranged.split(\"\").map((c) => {\n const code = c.charCodeAt(0);\n return code >= 65 && code <= 90 ? String(code - 55) : c;\n }).join(\"\");\n\n // Compute mod-97 on large number via chunking\n let remainder = 0;\n for (let i = 0; i < numeric.length; i += 7) {\n const chunk = String(remainder) + numeric.slice(i, i + 7);\n remainder = parseInt(chunk, 10) % 97;\n }\n\n return remainder === 1;\n}\n\n// ---------------------------------------------------------------------------\n// UK NINO Validation\n// ---------------------------------------------------------------------------\n\n/**\n * Validate a UK National Insurance Number (NINO) format.\n * Format: two letters + six digits + one letter (A-D).\n * Excludes certain invalid prefixes.\n *\n * @param value - NINO string, with or without spaces.\n * @returns `true` if the format is valid.\n *\n * @example\n * ```ts\n * ninoValid(\"AB 12 34 56 A\"); // true\n * ninoValid(\"DA 12 34 56 A\"); // false (invalid prefix DA)\n * ```\n */\nexport function ninoValid(value: string): boolean {\n const stripped = value.replace(/\\s/g, \"\").toUpperCase();\n // Exclude invalid prefixes: D, F, I, Q, U, V as first letter\n // BG, GB, KN, NK, NT, TN, ZZ as first two letters\n if (!/^[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z]\\d{6}[A-D]$/.test(stripped)) return false;\n const invalidPrefixes = [\"BG\", \"GB\", \"KN\", \"NK\", \"NT\", \"TN\", \"ZZ\"];\n const prefix = stripped.slice(0, 2);\n return !invalidPrefixes.includes(prefix);\n}\n\n// ---------------------------------------------------------------------------\n// Indian Aadhaar format check (12 digits, not starting with 0 or 1)\n// ---------------------------------------------------------------------------\n\n/**\n * Validate the format of an Indian Aadhaar number.\n * Does not include Verhoeff checksum by default (call `verhoeff()` for that).\n *\n * @param value - Aadhaar number, 12 digits optionally separated by spaces.\n * @returns `true` if the format is valid.\n */\nexport function aadhaarFormat(value: string): boolean {\n const stripped = value.replace(/[\\s-]/g, \"\");\n if (!/^\\d{12}$/.test(stripped)) return false;\n // Must not start with 0 or 1\n return !stripped.startsWith(\"0\") && !stripped.startsWith(\"1\");\n}\n"]}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module validators
|
|
3
|
+
* @description PII checksum and format validation algorithms.
|
|
4
|
+
*
|
|
5
|
+
* All validators are pure functions that accept a string and return a boolean.
|
|
6
|
+
* Export them from `"anonyma/validators"` for standalone use.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { luhn, verhoeff, nhsMod11, cpfChecksum } from "anonyma/validators";
|
|
11
|
+
*
|
|
12
|
+
* luhn("4111111111111111"); // true
|
|
13
|
+
* nhsMod11("943-476-5919"); // true
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Validate a string of digits using the Luhn algorithm (ISO/IEC 7812).
|
|
18
|
+
* Used for credit/debit card numbers and some national IDs.
|
|
19
|
+
*
|
|
20
|
+
* @param digits - Digit-only string (spaces/hyphens stripped before calling).
|
|
21
|
+
* @returns `true` if the number passes the Luhn check.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* luhn("4111111111111111"); // true
|
|
26
|
+
* luhn("4111111111111112"); // false
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function luhn(digits: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Validate a digit string using the Verhoeff algorithm.
|
|
32
|
+
* Used for Indian Aadhaar numbers and some other national IDs.
|
|
33
|
+
*
|
|
34
|
+
* @param digits - Digit-only string.
|
|
35
|
+
* @returns `true` if the number passes the Verhoeff check.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* verhoeff("236"); // true (canonical Verhoeff test case)
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare function verhoeff(digits: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Validate a UK NHS number using the mod-11 algorithm.
|
|
45
|
+
* NHS numbers are 10 digits. Weighting factors are 10..2 for the first 9 digits;
|
|
46
|
+
* the 10th digit is the check digit (11 - sum mod 11, or 0 if sum mod 11 == 0).
|
|
47
|
+
*
|
|
48
|
+
* @param value - NHS number (digits or with spaces/hyphens).
|
|
49
|
+
* @returns `true` if valid.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* nhsMod11("9434765919"); // true
|
|
54
|
+
* nhsMod11("943 476 5919"); // true
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function nhsMod11(value: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Validate a Brazilian CPF (Cadastro de Pessoas Físicas) number.
|
|
60
|
+
* CPF has 11 digits with two check digits at positions 10 and 11.
|
|
61
|
+
*
|
|
62
|
+
* @param value - CPF with or without formatting (e.g. `"123.456.789-09"` or `"12345678909"`).
|
|
63
|
+
* @returns `true` if valid.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* cpfChecksum("529.982.247-25"); // true
|
|
68
|
+
* cpfChecksum("529.982.247-26"); // false
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare function cpfChecksum(value: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Validate a Vehicle Identification Number (VIN) using the ISO 3779 mod-11 checksum.
|
|
74
|
+
* The check digit is position 9 (index 8).
|
|
75
|
+
*
|
|
76
|
+
* @param vin - 17-character VIN string. Must contain only A-Z (excluding I, O, Q) and 0-9.
|
|
77
|
+
* @returns `true` if the VIN passes the checksum and has valid characters.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* vinChecksum("1HGBH41JXMN109186"); // true
|
|
82
|
+
* vinChecksum("1HGBH41JXMN109187"); // false
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare function vinChecksum(vin: string): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Validate a US DEA (Drug Enforcement Administration) registration number.
|
|
88
|
+
* Format: two letters (registrant type + first letter of last name) + 7 digits.
|
|
89
|
+
* Check digit = (sum of digits 1,3,5 + 2 * sum of digits 2,4,6) mod 10.
|
|
90
|
+
*
|
|
91
|
+
* @param value - DEA number, e.g. `"AB1234563"`.
|
|
92
|
+
* @returns `true` if valid.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* deaChecksum("AB1234563"); // true
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function deaChecksum(value: string): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Validate an IBAN using the ISO 13616 mod-97 algorithm.
|
|
102
|
+
*
|
|
103
|
+
* @param value - IBAN string, with or without spaces.
|
|
104
|
+
* @returns `true` if valid.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* ibanMod97("GB82 WEST 1234 5698 7654 32"); // true
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function ibanMod97(value: string): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Validate a UK National Insurance Number (NINO) format.
|
|
114
|
+
* Format: two letters + six digits + one letter (A-D).
|
|
115
|
+
* Excludes certain invalid prefixes.
|
|
116
|
+
*
|
|
117
|
+
* @param value - NINO string, with or without spaces.
|
|
118
|
+
* @returns `true` if the format is valid.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* ninoValid("AB 12 34 56 A"); // true
|
|
123
|
+
* ninoValid("DA 12 34 56 A"); // false (invalid prefix DA)
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
declare function ninoValid(value: string): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Validate the format of an Indian Aadhaar number.
|
|
129
|
+
* Does not include Verhoeff checksum by default (call `verhoeff()` for that).
|
|
130
|
+
*
|
|
131
|
+
* @param value - Aadhaar number, 12 digits optionally separated by spaces.
|
|
132
|
+
* @returns `true` if the format is valid.
|
|
133
|
+
*/
|
|
134
|
+
declare function aadhaarFormat(value: string): boolean;
|
|
135
|
+
|
|
136
|
+
export { aadhaarFormat, cpfChecksum, deaChecksum, ibanMod97, luhn, nhsMod11, ninoValid, verhoeff, vinChecksum };
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module validators
|
|
3
|
+
* @description PII checksum and format validation algorithms.
|
|
4
|
+
*
|
|
5
|
+
* All validators are pure functions that accept a string and return a boolean.
|
|
6
|
+
* Export them from `"anonyma/validators"` for standalone use.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { luhn, verhoeff, nhsMod11, cpfChecksum } from "anonyma/validators";
|
|
11
|
+
*
|
|
12
|
+
* luhn("4111111111111111"); // true
|
|
13
|
+
* nhsMod11("943-476-5919"); // true
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
/**
|
|
17
|
+
* Validate a string of digits using the Luhn algorithm (ISO/IEC 7812).
|
|
18
|
+
* Used for credit/debit card numbers and some national IDs.
|
|
19
|
+
*
|
|
20
|
+
* @param digits - Digit-only string (spaces/hyphens stripped before calling).
|
|
21
|
+
* @returns `true` if the number passes the Luhn check.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* luhn("4111111111111111"); // true
|
|
26
|
+
* luhn("4111111111111112"); // false
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
declare function luhn(digits: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Validate a digit string using the Verhoeff algorithm.
|
|
32
|
+
* Used for Indian Aadhaar numbers and some other national IDs.
|
|
33
|
+
*
|
|
34
|
+
* @param digits - Digit-only string.
|
|
35
|
+
* @returns `true` if the number passes the Verhoeff check.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* verhoeff("236"); // true (canonical Verhoeff test case)
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
declare function verhoeff(digits: string): boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Validate a UK NHS number using the mod-11 algorithm.
|
|
45
|
+
* NHS numbers are 10 digits. Weighting factors are 10..2 for the first 9 digits;
|
|
46
|
+
* the 10th digit is the check digit (11 - sum mod 11, or 0 if sum mod 11 == 0).
|
|
47
|
+
*
|
|
48
|
+
* @param value - NHS number (digits or with spaces/hyphens).
|
|
49
|
+
* @returns `true` if valid.
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* nhsMod11("9434765919"); // true
|
|
54
|
+
* nhsMod11("943 476 5919"); // true
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function nhsMod11(value: string): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Validate a Brazilian CPF (Cadastro de Pessoas Físicas) number.
|
|
60
|
+
* CPF has 11 digits with two check digits at positions 10 and 11.
|
|
61
|
+
*
|
|
62
|
+
* @param value - CPF with or without formatting (e.g. `"123.456.789-09"` or `"12345678909"`).
|
|
63
|
+
* @returns `true` if valid.
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```ts
|
|
67
|
+
* cpfChecksum("529.982.247-25"); // true
|
|
68
|
+
* cpfChecksum("529.982.247-26"); // false
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
declare function cpfChecksum(value: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Validate a Vehicle Identification Number (VIN) using the ISO 3779 mod-11 checksum.
|
|
74
|
+
* The check digit is position 9 (index 8).
|
|
75
|
+
*
|
|
76
|
+
* @param vin - 17-character VIN string. Must contain only A-Z (excluding I, O, Q) and 0-9.
|
|
77
|
+
* @returns `true` if the VIN passes the checksum and has valid characters.
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* vinChecksum("1HGBH41JXMN109186"); // true
|
|
82
|
+
* vinChecksum("1HGBH41JXMN109187"); // false
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
declare function vinChecksum(vin: string): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Validate a US DEA (Drug Enforcement Administration) registration number.
|
|
88
|
+
* Format: two letters (registrant type + first letter of last name) + 7 digits.
|
|
89
|
+
* Check digit = (sum of digits 1,3,5 + 2 * sum of digits 2,4,6) mod 10.
|
|
90
|
+
*
|
|
91
|
+
* @param value - DEA number, e.g. `"AB1234563"`.
|
|
92
|
+
* @returns `true` if valid.
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* deaChecksum("AB1234563"); // true
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
declare function deaChecksum(value: string): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* Validate an IBAN using the ISO 13616 mod-97 algorithm.
|
|
102
|
+
*
|
|
103
|
+
* @param value - IBAN string, with or without spaces.
|
|
104
|
+
* @returns `true` if valid.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* ibanMod97("GB82 WEST 1234 5698 7654 32"); // true
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
111
|
+
declare function ibanMod97(value: string): boolean;
|
|
112
|
+
/**
|
|
113
|
+
* Validate a UK National Insurance Number (NINO) format.
|
|
114
|
+
* Format: two letters + six digits + one letter (A-D).
|
|
115
|
+
* Excludes certain invalid prefixes.
|
|
116
|
+
*
|
|
117
|
+
* @param value - NINO string, with or without spaces.
|
|
118
|
+
* @returns `true` if the format is valid.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```ts
|
|
122
|
+
* ninoValid("AB 12 34 56 A"); // true
|
|
123
|
+
* ninoValid("DA 12 34 56 A"); // false (invalid prefix DA)
|
|
124
|
+
* ```
|
|
125
|
+
*/
|
|
126
|
+
declare function ninoValid(value: string): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Validate the format of an Indian Aadhaar number.
|
|
129
|
+
* Does not include Verhoeff checksum by default (call `verhoeff()` for that).
|
|
130
|
+
*
|
|
131
|
+
* @param value - Aadhaar number, 12 digits optionally separated by spaces.
|
|
132
|
+
* @returns `true` if the format is valid.
|
|
133
|
+
*/
|
|
134
|
+
declare function aadhaarFormat(value: string): boolean;
|
|
135
|
+
|
|
136
|
+
export { aadhaarFormat, cpfChecksum, deaChecksum, ibanMod97, luhn, nhsMod11, ninoValid, verhoeff, vinChecksum };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// src/validators.ts
|
|
2
|
+
function luhn(digits) {
|
|
3
|
+
const stripped = digits.replace(/[\s-]/g, "");
|
|
4
|
+
if (!/^\d+$/.test(stripped) || stripped.length < 2) return false;
|
|
5
|
+
let sum = 0;
|
|
6
|
+
let isEven = false;
|
|
7
|
+
for (let i = stripped.length - 1; i >= 0; i--) {
|
|
8
|
+
let d = parseInt(stripped[i] ?? "0", 10);
|
|
9
|
+
if (isEven) {
|
|
10
|
+
d *= 2;
|
|
11
|
+
if (d > 9) d -= 9;
|
|
12
|
+
}
|
|
13
|
+
sum += d;
|
|
14
|
+
isEven = !isEven;
|
|
15
|
+
}
|
|
16
|
+
return sum % 10 === 0;
|
|
17
|
+
}
|
|
18
|
+
var VERHOEFF_D = [
|
|
19
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
|
20
|
+
[1, 2, 3, 4, 0, 6, 7, 8, 9, 5],
|
|
21
|
+
[2, 3, 4, 0, 1, 7, 8, 9, 5, 6],
|
|
22
|
+
[3, 4, 0, 1, 2, 8, 9, 5, 6, 7],
|
|
23
|
+
[4, 0, 1, 2, 3, 9, 5, 6, 7, 8],
|
|
24
|
+
[5, 9, 8, 7, 6, 0, 4, 3, 2, 1],
|
|
25
|
+
[6, 5, 9, 8, 7, 1, 0, 4, 3, 2],
|
|
26
|
+
[7, 6, 5, 9, 8, 2, 1, 0, 4, 3],
|
|
27
|
+
[8, 7, 6, 5, 9, 3, 2, 1, 0, 4],
|
|
28
|
+
[9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
|
|
29
|
+
];
|
|
30
|
+
var VERHOEFF_P = [
|
|
31
|
+
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
|
|
32
|
+
[1, 5, 7, 6, 2, 8, 3, 0, 9, 4],
|
|
33
|
+
[5, 8, 0, 3, 7, 9, 6, 1, 4, 2],
|
|
34
|
+
[8, 9, 1, 6, 0, 4, 3, 5, 2, 7],
|
|
35
|
+
[9, 4, 5, 3, 1, 2, 6, 8, 7, 0],
|
|
36
|
+
[4, 2, 8, 6, 5, 7, 3, 9, 0, 1],
|
|
37
|
+
[2, 7, 9, 3, 8, 0, 6, 4, 1, 5],
|
|
38
|
+
[7, 0, 4, 6, 9, 1, 3, 2, 5, 8]
|
|
39
|
+
];
|
|
40
|
+
function verhoeff(digits) {
|
|
41
|
+
const stripped = digits.replace(/[\s-]/g, "");
|
|
42
|
+
if (!/^\d+$/.test(stripped) || stripped.length === 0) return false;
|
|
43
|
+
let c = 0;
|
|
44
|
+
const reversed = stripped.split("").reverse();
|
|
45
|
+
for (let i = 0; i < reversed.length; i++) {
|
|
46
|
+
const digit = parseInt(reversed[i] ?? "0", 10);
|
|
47
|
+
const pRow = VERHOEFF_P[i % 8];
|
|
48
|
+
const pVal = pRow ? pRow[digit] ?? digit : digit;
|
|
49
|
+
const dRow = VERHOEFF_D[c];
|
|
50
|
+
c = dRow ? dRow[pVal] ?? 0 : 0;
|
|
51
|
+
}
|
|
52
|
+
return c === 0;
|
|
53
|
+
}
|
|
54
|
+
function nhsMod11(value) {
|
|
55
|
+
const stripped = value.replace(/[\s-]/g, "");
|
|
56
|
+
if (!/^\d{10}$/.test(stripped)) return false;
|
|
57
|
+
let sum = 0;
|
|
58
|
+
for (let i = 0; i < 9; i++) {
|
|
59
|
+
sum += parseInt(stripped[i] ?? "0", 10) * (10 - i);
|
|
60
|
+
}
|
|
61
|
+
const remainder = sum % 11;
|
|
62
|
+
if (remainder === 1) return false;
|
|
63
|
+
const checkDigit = remainder === 0 ? 0 : 11 - remainder;
|
|
64
|
+
return parseInt(stripped[9] ?? "0", 10) === checkDigit;
|
|
65
|
+
}
|
|
66
|
+
function cpfChecksum(value) {
|
|
67
|
+
const stripped = value.replace(/[.\-\s]/g, "");
|
|
68
|
+
if (!/^\d{11}$/.test(stripped)) return false;
|
|
69
|
+
if (/^(\d)\1{10}$/.test(stripped)) return false;
|
|
70
|
+
let sum = 0;
|
|
71
|
+
for (let i = 0; i < 9; i++) {
|
|
72
|
+
sum += parseInt(stripped[i] ?? "0", 10) * (10 - i);
|
|
73
|
+
}
|
|
74
|
+
let remainder = sum * 10 % 11;
|
|
75
|
+
if (remainder === 10 || remainder === 11) remainder = 0;
|
|
76
|
+
if (remainder !== parseInt(stripped[9] ?? "0", 10)) return false;
|
|
77
|
+
sum = 0;
|
|
78
|
+
for (let i = 0; i < 10; i++) {
|
|
79
|
+
sum += parseInt(stripped[i] ?? "0", 10) * (11 - i);
|
|
80
|
+
}
|
|
81
|
+
remainder = sum * 10 % 11;
|
|
82
|
+
if (remainder === 10 || remainder === 11) remainder = 0;
|
|
83
|
+
return remainder === parseInt(stripped[10] ?? "0", 10);
|
|
84
|
+
}
|
|
85
|
+
var VIN_TRANSLITERATION = {
|
|
86
|
+
A: 1,
|
|
87
|
+
B: 2,
|
|
88
|
+
C: 3,
|
|
89
|
+
D: 4,
|
|
90
|
+
E: 5,
|
|
91
|
+
F: 6,
|
|
92
|
+
G: 7,
|
|
93
|
+
H: 8,
|
|
94
|
+
J: 1,
|
|
95
|
+
K: 2,
|
|
96
|
+
L: 3,
|
|
97
|
+
M: 4,
|
|
98
|
+
N: 5,
|
|
99
|
+
P: 7,
|
|
100
|
+
R: 9,
|
|
101
|
+
S: 2,
|
|
102
|
+
T: 3,
|
|
103
|
+
U: 4,
|
|
104
|
+
V: 5,
|
|
105
|
+
W: 6,
|
|
106
|
+
X: 7,
|
|
107
|
+
Y: 8,
|
|
108
|
+
Z: 9,
|
|
109
|
+
0: 0,
|
|
110
|
+
1: 1,
|
|
111
|
+
2: 2,
|
|
112
|
+
3: 3,
|
|
113
|
+
4: 4,
|
|
114
|
+
5: 5,
|
|
115
|
+
6: 6,
|
|
116
|
+
7: 7,
|
|
117
|
+
8: 8,
|
|
118
|
+
9: 9
|
|
119
|
+
};
|
|
120
|
+
var VIN_WEIGHTS = [8, 7, 6, 5, 4, 3, 2, 10, 0, 9, 8, 7, 6, 5, 4, 3, 2];
|
|
121
|
+
function vinChecksum(vin) {
|
|
122
|
+
const upper = vin.toUpperCase();
|
|
123
|
+
if (!/^[A-HJ-NPR-Z0-9]{17}$/.test(upper)) return false;
|
|
124
|
+
let sum = 0;
|
|
125
|
+
for (let i = 0; i < 17; i++) {
|
|
126
|
+
const char = upper[i] ?? "";
|
|
127
|
+
const val = VIN_TRANSLITERATION[char];
|
|
128
|
+
const weight = VIN_WEIGHTS[i];
|
|
129
|
+
if (val === void 0 || weight === void 0) return false;
|
|
130
|
+
sum += val * weight;
|
|
131
|
+
}
|
|
132
|
+
const remainder = sum % 11;
|
|
133
|
+
const checkChar = upper[8] ?? "";
|
|
134
|
+
const expected = remainder === 10 ? "X" : String(remainder);
|
|
135
|
+
return checkChar === expected;
|
|
136
|
+
}
|
|
137
|
+
function deaChecksum(value) {
|
|
138
|
+
const stripped = value.replace(/[\s-]/g, "").toUpperCase();
|
|
139
|
+
if (!/^[ABCDEFGHJKLMNPRSTUX][A-Z9]\d{7}$/.test(stripped)) return false;
|
|
140
|
+
const digits = stripped.slice(2);
|
|
141
|
+
const oddSum = parseInt(digits[0] ?? "0", 10) + parseInt(digits[2] ?? "0", 10) + parseInt(digits[4] ?? "0", 10);
|
|
142
|
+
const evenSum = parseInt(digits[1] ?? "0", 10) + parseInt(digits[3] ?? "0", 10) + parseInt(digits[5] ?? "0", 10);
|
|
143
|
+
const checksum = (oddSum + 2 * evenSum) % 10;
|
|
144
|
+
return checksum === parseInt(digits[6] ?? "0", 10);
|
|
145
|
+
}
|
|
146
|
+
function ibanMod97(value) {
|
|
147
|
+
const stripped = value.replace(/\s/g, "").toUpperCase();
|
|
148
|
+
if (stripped.length < 15 || stripped.length > 34) return false;
|
|
149
|
+
const rearranged = stripped.slice(4) + stripped.slice(0, 4);
|
|
150
|
+
const numeric = rearranged.split("").map((c) => {
|
|
151
|
+
const code = c.charCodeAt(0);
|
|
152
|
+
return code >= 65 && code <= 90 ? String(code - 55) : c;
|
|
153
|
+
}).join("");
|
|
154
|
+
let remainder = 0;
|
|
155
|
+
for (let i = 0; i < numeric.length; i += 7) {
|
|
156
|
+
const chunk = String(remainder) + numeric.slice(i, i + 7);
|
|
157
|
+
remainder = parseInt(chunk, 10) % 97;
|
|
158
|
+
}
|
|
159
|
+
return remainder === 1;
|
|
160
|
+
}
|
|
161
|
+
function ninoValid(value) {
|
|
162
|
+
const stripped = value.replace(/\s/g, "").toUpperCase();
|
|
163
|
+
if (!/^[A-CEGHJ-PR-TW-Z][A-CEGHJ-NPR-TW-Z]\d{6}[A-D]$/.test(stripped)) return false;
|
|
164
|
+
const invalidPrefixes = ["BG", "GB", "KN", "NK", "NT", "TN", "ZZ"];
|
|
165
|
+
const prefix = stripped.slice(0, 2);
|
|
166
|
+
return !invalidPrefixes.includes(prefix);
|
|
167
|
+
}
|
|
168
|
+
function aadhaarFormat(value) {
|
|
169
|
+
const stripped = value.replace(/[\s-]/g, "");
|
|
170
|
+
if (!/^\d{12}$/.test(stripped)) return false;
|
|
171
|
+
return !stripped.startsWith("0") && !stripped.startsWith("1");
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export { aadhaarFormat, cpfChecksum, deaChecksum, ibanMod97, luhn, nhsMod11, ninoValid, verhoeff, vinChecksum };
|
|
175
|
+
//# sourceMappingURL=validators.js.map
|
|
176
|
+
//# sourceMappingURL=validators.js.map
|