@validex/core 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 +583 -0
- package/dist/checks/index.cjs +51 -0
- package/dist/checks/index.d.cts +207 -0
- package/dist/checks/index.d.ts +207 -0
- package/dist/checks/index.js +51 -0
- package/dist/chunk-2OTGUKO7.cjs +26 -0
- package/dist/chunk-4HUGF4EZ.js +0 -0
- package/dist/chunk-5CYBSNNG.cjs +33 -0
- package/dist/chunk-5DOFRLSB.js +30 -0
- package/dist/chunk-64X6D23X.cjs +24 -0
- package/dist/chunk-6MGS4JWP.js +152 -0
- package/dist/chunk-AGJWIOFF.js +24 -0
- package/dist/chunk-BAFEYOPS.js +43 -0
- package/dist/chunk-BYMZTDYD.js +56 -0
- package/dist/chunk-D232V332.cjs +30 -0
- package/dist/chunk-FD77PZXB.js +9 -0
- package/dist/chunk-H3XHQLZF.cjs +43 -0
- package/dist/chunk-ISY3F7TI.cjs +239 -0
- package/dist/chunk-JEKRBIPN.cjs +1 -0
- package/dist/chunk-KTN4NQQL.js +33 -0
- package/dist/chunk-LSQNDPFQ.cjs +9 -0
- package/dist/chunk-NDLUDRZJ.js +24 -0
- package/dist/chunk-OCTLUBGT.cjs +24 -0
- package/dist/chunk-OFT3FQPJ.cjs +152 -0
- package/dist/chunk-OOFMB7K5.js +34 -0
- package/dist/chunk-OTPQTLPM.js +50 -0
- package/dist/chunk-P3FRVJ3U.cjs +50 -0
- package/dist/chunk-PFPNNQGJ.js +30 -0
- package/dist/chunk-PQ4TUE2Q.cjs +2688 -0
- package/dist/chunk-SMDC2EAD.js +26 -0
- package/dist/chunk-TB6J73U7.js +239 -0
- package/dist/chunk-TBVAKZA5.js +2688 -0
- package/dist/chunk-TSPTIW3V.cjs +34 -0
- package/dist/chunk-WE2OD5XD.cjs +30 -0
- package/dist/chunk-WKVMDEA3.js +26 -0
- package/dist/chunk-ZAUX2RGL.cjs +56 -0
- package/dist/chunk-ZWIO2MJX.cjs +26 -0
- package/dist/cli/index.cjs +120 -0
- package/dist/cli/index.d.cts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +120 -0
- package/dist/commonPasswords-3BYUBARZ.cjs +10 -0
- package/dist/commonPasswords-ZYOEI6PG.js +10 -0
- package/dist/countryCodes-EKJKVHR5.cjs +10 -0
- package/dist/countryCodes-RTJZVCLB.js +10 -0
- package/dist/countryCodes-VY56VZPT.cjs +255 -0
- package/dist/countryCodes-YRY75MQP.js +255 -0
- package/dist/creditCardPrefixes-EXMJZGE7.cjs +10 -0
- package/dist/creditCardPrefixes-EZK7T4IZ.js +10 -0
- package/dist/creditCardPrefixes-HKWKCHNU.cjs +48 -0
- package/dist/creditCardPrefixes-QP3S4ZAU.js +48 -0
- package/dist/currencyCodes-GU6W3HSN.cjs +171 -0
- package/dist/currencyCodes-P67AASLW.js +171 -0
- package/dist/currencyCodes-RMRLGDME.cjs +10 -0
- package/dist/currencyCodes-U6TSAWDR.js +10 -0
- package/dist/disposableDomains-DCXSV422.js +10 -0
- package/dist/disposableDomains-USU2JQSF.cjs +10 -0
- package/dist/ibanPatterns-2PM32RIY.cjs +85 -0
- package/dist/ibanPatterns-BSQUWKLY.js +85 -0
- package/dist/ibanPatterns-KTLY6TZY.cjs +10 -0
- package/dist/ibanPatterns-LJRPR7FV.js +10 -0
- package/dist/index-Cid7Ygr_.d.cts +950 -0
- package/dist/index-Cid7Ygr_.d.ts +950 -0
- package/dist/index.cjs +361 -0
- package/dist/index.d.cts +132 -0
- package/dist/index.d.ts +132 -0
- package/dist/index.js +361 -0
- package/dist/locales/en.cjs +10 -0
- package/dist/locales/en.d.cts +234 -0
- package/dist/locales/en.d.ts +234 -0
- package/dist/locales/en.js +10 -0
- package/dist/passwordsTier1-NAZLSHKW.cjs +105 -0
- package/dist/passwordsTier1-OYRMLOWD.js +105 -0
- package/dist/passwordsTier2-GYJTYGY6.cjs +906 -0
- package/dist/passwordsTier2-JAEO5AYY.js +906 -0
- package/dist/passwordsTier3-BAPUFHZM.cjs +9006 -0
- package/dist/passwordsTier3-E6WBK5OB.js +9006 -0
- package/dist/phoneDetection-AFSSD4IB.cjs +6 -0
- package/dist/phoneDetection-G23LZ6MU.js +6 -0
- package/dist/phoneParser-2RTXDB6H.js +10 -0
- package/dist/phoneParser-CGRP2OUN.cjs +10 -0
- package/dist/postalCodes-4EZVDT2N.cjs +10 -0
- package/dist/postalCodes-ZPAJB3P5.js +10 -0
- package/dist/reservedUsernames-3QPPKUXR.cjs +246 -0
- package/dist/reservedUsernames-GIK6NX3J.js +246 -0
- package/dist/reservedUsernames-QR4ONXSL.js +10 -0
- package/dist/reservedUsernames-W65FGT6A.cjs +10 -0
- package/dist/rules/index.cjs +66 -0
- package/dist/rules/index.d.cts +2 -0
- package/dist/rules/index.d.ts +2 -0
- package/dist/rules/index.js +66 -0
- package/dist/utilities/index.cjs +8 -0
- package/dist/utilities/index.d.cts +47 -0
- package/dist/utilities/index.d.ts +47 -0
- package/dist/utilities/index.js +8 -0
- package/dist/vatPatterns-BLRXHNCP.js +36 -0
- package/dist/vatPatterns-DNVZJPTW.js +10 -0
- package/dist/vatPatterns-NPN6SV2Y.cjs +36 -0
- package/dist/vatPatterns-RRHUTA3U.cjs +10 -0
- package/package.json +133 -0
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// src/checks/composition.ts
|
|
2
|
+
function countMatches(value, pattern) {
|
|
3
|
+
const matches = value.match(pattern);
|
|
4
|
+
return matches ? matches.length : 0;
|
|
5
|
+
}
|
|
6
|
+
function inRange(count, min, max) {
|
|
7
|
+
return count >= min && (max === void 0 || count <= max);
|
|
8
|
+
}
|
|
9
|
+
var UPPERCASE_RE = /\p{Lu}/gu;
|
|
10
|
+
var LOWERCASE_RE = /\p{Ll}/gu;
|
|
11
|
+
var DIGIT_RE = /\p{Nd}/gu;
|
|
12
|
+
var SPECIAL_RE = /[^\p{L}\p{Nd}\s]/gu;
|
|
13
|
+
function hasUppercase(value, min, max) {
|
|
14
|
+
return inRange(countMatches(value, UPPERCASE_RE), min, max);
|
|
15
|
+
}
|
|
16
|
+
function hasLowercase(value, min, max) {
|
|
17
|
+
return inRange(countMatches(value, LOWERCASE_RE), min, max);
|
|
18
|
+
}
|
|
19
|
+
function hasDigits(value, min, max) {
|
|
20
|
+
return inRange(countMatches(value, DIGIT_RE), min, max);
|
|
21
|
+
}
|
|
22
|
+
function hasSpecial(value, min, max) {
|
|
23
|
+
return inRange(countMatches(value, SPECIAL_RE), min, max);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// src/checks/detection.ts
|
|
27
|
+
var EMAIL_RE = /[\w.%+-]+@[a-z0-9.-]+\.[a-z]{2,}/i;
|
|
28
|
+
function containsEmail(value) {
|
|
29
|
+
return EMAIL_RE.test(value);
|
|
30
|
+
}
|
|
31
|
+
var URL_PROTOCOL_RE = /https?:\/\/\S+/i;
|
|
32
|
+
var URL_WWW_RE = /\bwww\.\S+/i;
|
|
33
|
+
function containsUrl(value) {
|
|
34
|
+
return URL_PROTOCOL_RE.test(value) || URL_WWW_RE.test(value);
|
|
35
|
+
}
|
|
36
|
+
var HTML_TAG_RE = /<[a-z/][^>]*>/i;
|
|
37
|
+
function containsHtml(value) {
|
|
38
|
+
return HTML_TAG_RE.test(value);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// src/checks/limits.ts
|
|
42
|
+
var WHITESPACE_RE = /\s+/;
|
|
43
|
+
function maxWords(value, max) {
|
|
44
|
+
const words = value.split(WHITESPACE_RE).filter((segment) => segment.length > 0);
|
|
45
|
+
return words.length <= max;
|
|
46
|
+
}
|
|
47
|
+
function minWords(value, min) {
|
|
48
|
+
const words = value.trim().split(WHITESPACE_RE).filter((segment) => segment.length > 0);
|
|
49
|
+
return words.length >= min;
|
|
50
|
+
}
|
|
51
|
+
function maxConsecutive(value, max) {
|
|
52
|
+
const chars = Array.from(value);
|
|
53
|
+
let count = 1;
|
|
54
|
+
for (let i = 1; i < chars.length; i++) {
|
|
55
|
+
if (chars[i] === chars[i - 1]) {
|
|
56
|
+
count++;
|
|
57
|
+
if (count > max) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
} else {
|
|
61
|
+
count = 1;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
var ANY_WHITESPACE_RE = /\s/;
|
|
67
|
+
function noSpaces(value) {
|
|
68
|
+
return !ANY_WHITESPACE_RE.test(value);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// src/checks/restriction.ts
|
|
72
|
+
var ALPHA_RE = /^\p{L}+$/u;
|
|
73
|
+
function onlyAlpha(value) {
|
|
74
|
+
return ALPHA_RE.test(value);
|
|
75
|
+
}
|
|
76
|
+
var NUMERIC_RE = /^\d+$/;
|
|
77
|
+
function onlyNumeric(value) {
|
|
78
|
+
return NUMERIC_RE.test(value);
|
|
79
|
+
}
|
|
80
|
+
var ALPHANUMERIC_RE = /^[\p{L}\d]+$/u;
|
|
81
|
+
function onlyAlphanumeric(value) {
|
|
82
|
+
return ALPHANUMERIC_RE.test(value);
|
|
83
|
+
}
|
|
84
|
+
var ALPHANUMERIC_SPACE_HYPHEN_RE = /^[\p{L}\d\s-]+$/u;
|
|
85
|
+
function onlyAlphanumericSpaceHyphen(value) {
|
|
86
|
+
return ALPHANUMERIC_SPACE_HYPHEN_RE.test(value);
|
|
87
|
+
}
|
|
88
|
+
var ALPHA_SPACE_HYPHEN_RE = /^[\p{L}\s-]+$/u;
|
|
89
|
+
function onlyAlphaSpaceHyphen(value) {
|
|
90
|
+
return ALPHA_SPACE_HYPHEN_RE.test(value);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// src/checks/transforms.ts
|
|
94
|
+
function emptyToUndefined(value) {
|
|
95
|
+
if (value === "" || value === null) {
|
|
96
|
+
return void 0;
|
|
97
|
+
}
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
function toTitleCase(value) {
|
|
101
|
+
return value.toLowerCase().split(" ").map(
|
|
102
|
+
(word) => word.split("-").map((segment) => capitalizeSegment(segment)).join("-")
|
|
103
|
+
).join(" ");
|
|
104
|
+
}
|
|
105
|
+
var CAPITALIZE_RE = /(?:^|(?<='))./gu;
|
|
106
|
+
function capitalizeSegment(segment) {
|
|
107
|
+
if (segment.length === 0) {
|
|
108
|
+
return segment;
|
|
109
|
+
}
|
|
110
|
+
return segment.replace(
|
|
111
|
+
CAPITALIZE_RE,
|
|
112
|
+
(char) => char.toUpperCase()
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
var SLUG_NON_ALNUM_RE = /[^a-z\d]+/g;
|
|
116
|
+
var SLUG_MULTI_HYPHEN_RE = /-+/g;
|
|
117
|
+
var SLUG_EDGE_HYPHEN_RE = /^-|-$/g;
|
|
118
|
+
function toSlug(value) {
|
|
119
|
+
return value.toLowerCase().replace(SLUG_NON_ALNUM_RE, "-").replace(SLUG_MULTI_HYPHEN_RE, "-").replace(SLUG_EDGE_HYPHEN_RE, "");
|
|
120
|
+
}
|
|
121
|
+
var HTML_STRIP_RE = /<[^>]*>/g;
|
|
122
|
+
function stripHtml(value) {
|
|
123
|
+
return value.replace(HTML_STRIP_RE, "");
|
|
124
|
+
}
|
|
125
|
+
var MULTI_WHITESPACE_RE = /\s+/g;
|
|
126
|
+
function collapseWhitespace(value) {
|
|
127
|
+
return value.replace(MULTI_WHITESPACE_RE, " ").trim();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export {
|
|
131
|
+
hasUppercase,
|
|
132
|
+
hasLowercase,
|
|
133
|
+
hasDigits,
|
|
134
|
+
hasSpecial,
|
|
135
|
+
containsEmail,
|
|
136
|
+
containsUrl,
|
|
137
|
+
containsHtml,
|
|
138
|
+
maxWords,
|
|
139
|
+
minWords,
|
|
140
|
+
maxConsecutive,
|
|
141
|
+
noSpaces,
|
|
142
|
+
onlyAlpha,
|
|
143
|
+
onlyNumeric,
|
|
144
|
+
onlyAlphanumeric,
|
|
145
|
+
onlyAlphanumericSpaceHyphen,
|
|
146
|
+
onlyAlphaSpaceHyphen,
|
|
147
|
+
emptyToUndefined,
|
|
148
|
+
toTitleCase,
|
|
149
|
+
toSlug,
|
|
150
|
+
stripHtml,
|
|
151
|
+
collapseWhitespace
|
|
152
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/loaders/disposableDomains.ts
|
|
2
|
+
var cache;
|
|
3
|
+
async function loadDisposableDomains() {
|
|
4
|
+
if (cache !== void 0)
|
|
5
|
+
return cache;
|
|
6
|
+
const { disposableEmailBlocklistSet } = await import("disposable-email-domains-js");
|
|
7
|
+
cache = disposableEmailBlocklistSet();
|
|
8
|
+
return cache;
|
|
9
|
+
}
|
|
10
|
+
function getDisposableDomains() {
|
|
11
|
+
if (cache === void 0) {
|
|
12
|
+
throw new Error("Disposable domains not loaded. Call loadDisposableDomains() or preloadData({ disposable: true }) first.");
|
|
13
|
+
}
|
|
14
|
+
return cache;
|
|
15
|
+
}
|
|
16
|
+
function clearDisposableDomainsCache() {
|
|
17
|
+
cache = void 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
loadDisposableDomains,
|
|
22
|
+
getDisposableDomains,
|
|
23
|
+
clearDisposableDomainsCache
|
|
24
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
// src/utilities/requiredWhen.ts
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
function requiredWhen(field, condition, options) {
|
|
4
|
+
const lbl = options?.label ?? field;
|
|
5
|
+
const message = options?.message ?? `${lbl} is required`;
|
|
6
|
+
return (data, ctx) => {
|
|
7
|
+
if (!condition(data)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const value = data[field];
|
|
11
|
+
if (value === void 0 || value === null || value === "") {
|
|
12
|
+
ctx.addIssue({
|
|
13
|
+
code: z.ZodIssueCode.custom,
|
|
14
|
+
message,
|
|
15
|
+
path: [field],
|
|
16
|
+
params: { code: "required", namespace: "base", label: lbl }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/utilities/sameAs.ts
|
|
23
|
+
import { z as z2 } from "zod";
|
|
24
|
+
function sameAs(sourceField, targetField, options) {
|
|
25
|
+
const srcLabel = options?.label ?? sourceField;
|
|
26
|
+
const tgtLabel = options?.targetLabel ?? targetField;
|
|
27
|
+
const message = options?.message ?? `${srcLabel} must match ${tgtLabel}`;
|
|
28
|
+
return (data, ctx) => {
|
|
29
|
+
if (data[sourceField] !== data[targetField]) {
|
|
30
|
+
ctx.addIssue({
|
|
31
|
+
code: z2.ZodIssueCode.custom,
|
|
32
|
+
message,
|
|
33
|
+
path: [sourceField],
|
|
34
|
+
params: { code: "mismatch", namespace: "confirmation", label: srcLabel, targetLabel: tgtLabel }
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
requiredWhen,
|
|
42
|
+
sameAs
|
|
43
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/loaders/phoneParser.ts
|
|
2
|
+
var cache = /* @__PURE__ */ new Map();
|
|
3
|
+
async function loadPhoneParser(metadata = "min", customPath) {
|
|
4
|
+
const cached = cache.get(metadata);
|
|
5
|
+
if (cached !== void 0)
|
|
6
|
+
return cached;
|
|
7
|
+
let parser;
|
|
8
|
+
switch (metadata) {
|
|
9
|
+
case "min": {
|
|
10
|
+
const mod = await import("libphonenumber-js");
|
|
11
|
+
parser = mod.parsePhoneNumberWithError;
|
|
12
|
+
break;
|
|
13
|
+
}
|
|
14
|
+
case "mobile": {
|
|
15
|
+
const mod = await import("libphonenumber-js/mobile");
|
|
16
|
+
parser = mod.parsePhoneNumberWithError;
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
case "max": {
|
|
20
|
+
const mod = await import("libphonenumber-js/max");
|
|
21
|
+
parser = mod.parsePhoneNumberWithError;
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
/* v8 ignore start -- custom metadata requires user-provided path; not testable without fixtures */
|
|
25
|
+
case "custom": {
|
|
26
|
+
if (customPath === void 0 || customPath === "") {
|
|
27
|
+
throw new Error('validex: Phone metadata "custom" requires customMetadataPath');
|
|
28
|
+
}
|
|
29
|
+
const core = await import("libphonenumber-js/core");
|
|
30
|
+
const meta = await import(customPath);
|
|
31
|
+
parser = ((v, c) => (
|
|
32
|
+
// SAFETY: custom metadata default export is the metadata object by user contract; c cast avoids overload mismatch
|
|
33
|
+
core.parsePhoneNumberWithError(v, c, meta.default)
|
|
34
|
+
));
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
cache.set(metadata, parser);
|
|
39
|
+
return parser;
|
|
40
|
+
}
|
|
41
|
+
function getPhoneParser(metadata = "min") {
|
|
42
|
+
const parser = cache.get(metadata);
|
|
43
|
+
if (parser === void 0) {
|
|
44
|
+
throw new Error(`Phone parser (${metadata}) not loaded. Call loadPhoneParser() or preloadData({ phone: '${metadata}' }) first.`);
|
|
45
|
+
}
|
|
46
|
+
return parser;
|
|
47
|
+
}
|
|
48
|
+
function clearPhoneParserCache() {
|
|
49
|
+
cache.clear();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export {
|
|
53
|
+
loadPhoneParser,
|
|
54
|
+
getPhoneParser,
|
|
55
|
+
clearPhoneParserCache
|
|
56
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }// src/loaders/vatPatterns.ts
|
|
2
|
+
var cache;
|
|
3
|
+
async function loadVatPatterns() {
|
|
4
|
+
if (cache !== void 0)
|
|
5
|
+
return cache;
|
|
6
|
+
const raw = (await Promise.resolve().then(() => _interopRequireWildcard(require("./vatPatterns-NPN6SV2Y.cjs")))).default;
|
|
7
|
+
const map = /* @__PURE__ */ new Map();
|
|
8
|
+
for (const entry of raw) {
|
|
9
|
+
map.set(entry.country, new RegExp(entry.regex));
|
|
10
|
+
}
|
|
11
|
+
cache = map;
|
|
12
|
+
return cache;
|
|
13
|
+
}
|
|
14
|
+
function getVatPatterns() {
|
|
15
|
+
if (cache === void 0) {
|
|
16
|
+
throw new Error(
|
|
17
|
+
"validex: VAT patterns not loaded. Use parseAsync() or call preloadData() first."
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
return cache;
|
|
21
|
+
}
|
|
22
|
+
function clearVatPatternsCache() {
|
|
23
|
+
cache = void 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
exports.loadVatPatterns = loadVatPatterns; exports.getVatPatterns = getVatPatterns; exports.clearVatPatternsCache = clearVatPatternsCache;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/utilities/requiredWhen.ts
|
|
2
|
+
var _zod = require('zod');
|
|
3
|
+
function requiredWhen(field, condition, options) {
|
|
4
|
+
const lbl = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _ => _.label]), () => ( field));
|
|
5
|
+
const message = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _2 => _2.message]), () => ( `${lbl} is required`));
|
|
6
|
+
return (data, ctx) => {
|
|
7
|
+
if (!condition(data)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const value = data[field];
|
|
11
|
+
if (value === void 0 || value === null || value === "") {
|
|
12
|
+
ctx.addIssue({
|
|
13
|
+
code: _zod.z.ZodIssueCode.custom,
|
|
14
|
+
message,
|
|
15
|
+
path: [field],
|
|
16
|
+
params: { code: "required", namespace: "base", label: lbl }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// src/utilities/sameAs.ts
|
|
23
|
+
|
|
24
|
+
function sameAs(sourceField, targetField, options) {
|
|
25
|
+
const srcLabel = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _3 => _3.label]), () => ( sourceField));
|
|
26
|
+
const tgtLabel = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _4 => _4.targetLabel]), () => ( targetField));
|
|
27
|
+
const message = _nullishCoalesce(_optionalChain([options, 'optionalAccess', _5 => _5.message]), () => ( `${srcLabel} must match ${tgtLabel}`));
|
|
28
|
+
return (data, ctx) => {
|
|
29
|
+
if (data[sourceField] !== data[targetField]) {
|
|
30
|
+
ctx.addIssue({
|
|
31
|
+
code: _zod.z.ZodIssueCode.custom,
|
|
32
|
+
message,
|
|
33
|
+
path: [sourceField],
|
|
34
|
+
params: { code: "mismatch", namespace: "confirmation", label: srcLabel, targetLabel: tgtLabel }
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
exports.requiredWhen = requiredWhen; exports.sameAs = sameAs;
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/locales/en.json
|
|
2
|
+
var lang = "en";
|
|
3
|
+
var validation = {
|
|
4
|
+
labels: {
|
|
5
|
+
email: "Email",
|
|
6
|
+
personName: "Name",
|
|
7
|
+
businessName: "Business Name",
|
|
8
|
+
password: "Password",
|
|
9
|
+
passwordConfirmation: "Password Confirmation",
|
|
10
|
+
phone: "Phone",
|
|
11
|
+
website: "Website",
|
|
12
|
+
url: "URL",
|
|
13
|
+
username: "Username",
|
|
14
|
+
slug: "Slug",
|
|
15
|
+
postalCode: "Postal Code",
|
|
16
|
+
licenseKey: "License Key",
|
|
17
|
+
uuid: "UUID",
|
|
18
|
+
jwt: "JWT",
|
|
19
|
+
dateTime: "Date/Time",
|
|
20
|
+
token: "Token",
|
|
21
|
+
text: "Text",
|
|
22
|
+
country: "Country",
|
|
23
|
+
currency: "Currency",
|
|
24
|
+
color: "Color",
|
|
25
|
+
creditCard: "Credit Card",
|
|
26
|
+
iban: "IBAN",
|
|
27
|
+
vatNumber: "VAT Number",
|
|
28
|
+
macAddress: "MAC Address",
|
|
29
|
+
ipAddress: "IP Address",
|
|
30
|
+
string: "Value"
|
|
31
|
+
},
|
|
32
|
+
messages: {
|
|
33
|
+
base: {
|
|
34
|
+
required: "{{label}} is required",
|
|
35
|
+
min: "{{label}} must be at least {{minimum}} characters",
|
|
36
|
+
max: "{{label}} must be at most {{maximum}} characters",
|
|
37
|
+
type: "{{label}} must be a {{expected}}",
|
|
38
|
+
format: "{{label}} is not valid"
|
|
39
|
+
},
|
|
40
|
+
email: {
|
|
41
|
+
invalid: "{{label}} is not a valid email address",
|
|
42
|
+
disposableBlocked: "{{label}} must not use a disposable email provider",
|
|
43
|
+
plusAliasBlocked: "{{label}} must not use plus aliases",
|
|
44
|
+
domainBlocked: "Email domain '{{domain}}' is not allowed",
|
|
45
|
+
domainNotAllowed: "Email domain '{{domain}}' is not in the allowed list",
|
|
46
|
+
subdomainNotAllowed: "Subdomain email addresses are not allowed",
|
|
47
|
+
custom: "{{label}} failed custom validation"
|
|
48
|
+
},
|
|
49
|
+
personName: {
|
|
50
|
+
invalid: "{{label}} is not a valid name",
|
|
51
|
+
maxWords: "{{label}} must have at most {{maximum}} words",
|
|
52
|
+
boundary: "{{label}} must start and end with a letter",
|
|
53
|
+
maxConsecutive: "{{label}} must not repeat the same character more than {{maximum}} times",
|
|
54
|
+
custom: "{{label}} failed custom validation"
|
|
55
|
+
},
|
|
56
|
+
businessName: {
|
|
57
|
+
invalid: "{{label}} is not a valid business name",
|
|
58
|
+
boundary: "{{label}} must start and end with an alphanumeric character",
|
|
59
|
+
maxConsecutive: "{{label}} must not repeat the same character more than {{maximum}} times",
|
|
60
|
+
custom: "{{label}} failed custom validation"
|
|
61
|
+
},
|
|
62
|
+
password: {
|
|
63
|
+
minUppercase: "{{label}} must have at least {{minimum}} uppercase characters",
|
|
64
|
+
minLowercase: "{{label}} must have at least {{minimum}} lowercase characters",
|
|
65
|
+
minDigits: "{{label}} must have at least {{minimum}} digits",
|
|
66
|
+
minSpecial: "{{label}} must have at least {{minimum}} special characters",
|
|
67
|
+
maxUppercase: "{{label}} must have at most {{maximum}} uppercase characters",
|
|
68
|
+
maxLowercase: "{{label}} must have at most {{maximum}} lowercase characters",
|
|
69
|
+
maxDigits: "{{label}} must have at most {{maximum}} digits",
|
|
70
|
+
maxSpecial: "{{label}} must have at most {{maximum}} special characters",
|
|
71
|
+
maxConsecutive: "{{label}} must not have more than {{maximum}} consecutive identical characters",
|
|
72
|
+
commonBlocked: "{{label}} is too common",
|
|
73
|
+
custom: "{{label}} failed custom validation"
|
|
74
|
+
},
|
|
75
|
+
confirmation: {
|
|
76
|
+
mismatch: "{{label}} must match {{targetLabel}}",
|
|
77
|
+
custom: "{{label}} failed custom validation"
|
|
78
|
+
},
|
|
79
|
+
phone: {
|
|
80
|
+
invalid: "{{label}} is not a valid phone number",
|
|
81
|
+
requireMobile: "{{label}} must be a mobile phone number",
|
|
82
|
+
countryCodeRequired: "{{label}} must include a country code prefix",
|
|
83
|
+
countryBlocked: "Phone numbers from '{{country}}' are not allowed",
|
|
84
|
+
countryNotAllowed: "Phone numbers from '{{country}}' are not in the allowed list",
|
|
85
|
+
custom: "{{label}} failed custom validation"
|
|
86
|
+
},
|
|
87
|
+
website: {
|
|
88
|
+
invalid: "{{label}} is not a valid website URL",
|
|
89
|
+
httpsRequired: "{{label}} must use HTTPS",
|
|
90
|
+
wwwRequired: "{{label}} must include www prefix",
|
|
91
|
+
pathNotAllowed: "{{label}} must not contain URL paths",
|
|
92
|
+
queryNotAllowed: "{{label}} must not contain query strings",
|
|
93
|
+
domainBlocked: "Domain '{{domain}}' is not allowed",
|
|
94
|
+
domainNotAllowed: "Domain '{{domain}}' is not in the allowed list",
|
|
95
|
+
subdomainNotAllowed: "Subdomain URLs are not allowed",
|
|
96
|
+
custom: "{{label}} failed custom validation"
|
|
97
|
+
},
|
|
98
|
+
url: {
|
|
99
|
+
invalid: "{{label}} is not a valid URL",
|
|
100
|
+
protocolNotAllowed: "Protocol '{{protocol}}' is not allowed",
|
|
101
|
+
tldRequired: "{{label}} must include a top-level domain",
|
|
102
|
+
queryNotAllowed: "{{label}} must not contain query strings",
|
|
103
|
+
authNotAllowed: "{{label}} must not contain credentials",
|
|
104
|
+
domainBlocked: "Domain '{{domain}}' is not allowed",
|
|
105
|
+
domainNotAllowed: "Domain '{{domain}}' is not in the allowed list",
|
|
106
|
+
custom: "{{label}} failed custom validation"
|
|
107
|
+
},
|
|
108
|
+
username: {
|
|
109
|
+
invalid: "{{label}} is not a valid username",
|
|
110
|
+
reservedBlocked: "The username '{{value}}' is reserved",
|
|
111
|
+
boundary: "{{label}} must start and end with an alphanumeric character",
|
|
112
|
+
maxConsecutive: "{{label}} must not repeat the same character more than {{maximum}} times",
|
|
113
|
+
custom: "{{label}} failed custom validation"
|
|
114
|
+
},
|
|
115
|
+
slug: {
|
|
116
|
+
invalid: "{{label}} is not a valid slug",
|
|
117
|
+
custom: "{{label}} failed custom validation"
|
|
118
|
+
},
|
|
119
|
+
postalCode: {
|
|
120
|
+
invalid: "{{label}} is not a valid postal code",
|
|
121
|
+
custom: "{{label}} failed custom validation"
|
|
122
|
+
},
|
|
123
|
+
licenseKey: {
|
|
124
|
+
invalid: "{{label}} is not a valid license key",
|
|
125
|
+
custom: "{{label}} failed custom validation"
|
|
126
|
+
},
|
|
127
|
+
uuid: {
|
|
128
|
+
invalid: "{{label}} is not a valid UUID",
|
|
129
|
+
custom: "{{label}} failed custom validation"
|
|
130
|
+
},
|
|
131
|
+
jwt: {
|
|
132
|
+
invalid: "{{label}} is not a valid JWT",
|
|
133
|
+
expiryRequired: "{{label}} must have an expiration claim",
|
|
134
|
+
expired: "{{label}} has expired",
|
|
135
|
+
notYetValid: "{{label}} is not yet valid",
|
|
136
|
+
missingClaim: "Required claim '{{claim}}' is missing",
|
|
137
|
+
algorithmNotAllowed: "Algorithm '{{algorithm}}' is not allowed",
|
|
138
|
+
custom: "{{label}} failed custom validation"
|
|
139
|
+
},
|
|
140
|
+
dateTime: {
|
|
141
|
+
invalid: "{{label}} is not a valid date",
|
|
142
|
+
tooEarly: "{{label}} must be after {{minimum}}",
|
|
143
|
+
tooLate: "{{label}} must be before {{maximum}}",
|
|
144
|
+
noFuture: "{{label}} must not be in the future",
|
|
145
|
+
noPast: "{{label}} must not be in the past",
|
|
146
|
+
custom: "{{label}} failed custom validation"
|
|
147
|
+
},
|
|
148
|
+
token: {
|
|
149
|
+
invalid: "{{label}} is not a valid {{type}} token",
|
|
150
|
+
custom: "{{label}} failed custom validation"
|
|
151
|
+
},
|
|
152
|
+
text: {
|
|
153
|
+
invalid: "{{label}} is not valid text",
|
|
154
|
+
noEmails: "{{label}} must not contain email addresses",
|
|
155
|
+
noUrls: "{{label}} must not contain URLs",
|
|
156
|
+
noPhoneNumbers: "{{label}} must not contain phone numbers",
|
|
157
|
+
noHtml: "{{label}} must not contain HTML",
|
|
158
|
+
minWords: "{{label}} must have at least {{minimum}} words",
|
|
159
|
+
maxWords: "{{label}} must have at most {{maximum}} words",
|
|
160
|
+
maxConsecutive: "{{label}} must not repeat the same character more than {{maximum}} times",
|
|
161
|
+
custom: "{{label}} failed custom validation"
|
|
162
|
+
},
|
|
163
|
+
country: {
|
|
164
|
+
invalid: "{{label}} is not a valid country code",
|
|
165
|
+
blocked: "Country '{{country}}' is not allowed",
|
|
166
|
+
notAllowed: "Country '{{country}}' is not in the allowed list",
|
|
167
|
+
custom: "{{label}} failed custom validation"
|
|
168
|
+
},
|
|
169
|
+
currency: {
|
|
170
|
+
invalid: "{{label}} is not a valid currency code",
|
|
171
|
+
blocked: "Currency '{{currency}}' is not allowed",
|
|
172
|
+
notAllowed: "Currency '{{currency}}' is not in the allowed list",
|
|
173
|
+
custom: "{{label}} failed custom validation"
|
|
174
|
+
},
|
|
175
|
+
color: {
|
|
176
|
+
invalid: "{{label}} is not a valid color",
|
|
177
|
+
custom: "{{label}} failed custom validation"
|
|
178
|
+
},
|
|
179
|
+
creditCard: {
|
|
180
|
+
invalid: "{{label}} is not a valid credit card number",
|
|
181
|
+
issuerNotAllowed: "Card issuer '{{issuer}}' is not in the allowed list",
|
|
182
|
+
issuerBlocked: "Card issuer '{{issuer}}' is not allowed",
|
|
183
|
+
custom: "{{label}} failed custom validation"
|
|
184
|
+
},
|
|
185
|
+
iban: {
|
|
186
|
+
invalid: "{{label}} is not a valid IBAN",
|
|
187
|
+
countryBlocked: "IBANs from '{{country}}' are not allowed",
|
|
188
|
+
countryNotAllowed: "IBANs from '{{country}}' are not in the allowed list",
|
|
189
|
+
custom: "{{label}} failed custom validation"
|
|
190
|
+
},
|
|
191
|
+
vatNumber: {
|
|
192
|
+
invalid: "{{label}} is not a valid VAT number",
|
|
193
|
+
custom: "{{label}} failed custom validation"
|
|
194
|
+
},
|
|
195
|
+
macAddress: {
|
|
196
|
+
invalid: "{{label}} is not a valid MAC address",
|
|
197
|
+
custom: "{{label}} failed custom validation"
|
|
198
|
+
},
|
|
199
|
+
ipAddress: {
|
|
200
|
+
invalid: "{{label}} is not a valid IP address",
|
|
201
|
+
privateNotAllowed: "{{label}} must not be a private IP address",
|
|
202
|
+
custom: "{{label}} failed custom validation"
|
|
203
|
+
},
|
|
204
|
+
string: {
|
|
205
|
+
minUppercase: "{{label}} must have at least {{minimum}} uppercase characters",
|
|
206
|
+
maxUppercase: "{{label}} must have at most {{maximum}} uppercase characters",
|
|
207
|
+
minLowercase: "{{label}} must have at least {{minimum}} lowercase characters",
|
|
208
|
+
maxLowercase: "{{label}} must have at most {{maximum}} lowercase characters",
|
|
209
|
+
minDigits: "{{label}} must have at least {{minimum}} digits",
|
|
210
|
+
maxDigits: "{{label}} must have at most {{maximum}} digits",
|
|
211
|
+
minSpecial: "{{label}} must have at least {{minimum}} special characters",
|
|
212
|
+
maxSpecial: "{{label}} must have at most {{maximum}} special characters",
|
|
213
|
+
noEmails: "{{label}} must not contain email addresses",
|
|
214
|
+
noUrls: "{{label}} must not contain URLs",
|
|
215
|
+
noPhoneNumbers: "{{label}} must not contain phone numbers",
|
|
216
|
+
noHtml: "{{label}} must not contain HTML",
|
|
217
|
+
noSpaces: "{{label}} must not contain spaces",
|
|
218
|
+
onlyAlpha: "{{label}} must contain only letters",
|
|
219
|
+
onlyNumeric: "{{label}} must contain only digits",
|
|
220
|
+
onlyAlphanumeric: "{{label}} must contain only letters and digits",
|
|
221
|
+
onlyAlphaSpaceHyphen: "{{label}} must contain only letters, spaces, and hyphens",
|
|
222
|
+
onlyAlphanumericSpaceHyphen: "{{label}} must contain only letters, digits, spaces, and hyphens",
|
|
223
|
+
minWords: "{{label}} must have at least {{minimum}} words",
|
|
224
|
+
maxWords: "{{label}} must have at most {{maximum}} words",
|
|
225
|
+
maxConsecutive: "{{label}} must not repeat the same character more than {{maximum}} times",
|
|
226
|
+
custom: "{{label}} failed custom validation"
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
var en_default = {
|
|
231
|
+
lang,
|
|
232
|
+
validation
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
exports.lang = lang; exports.validation = validation; exports.en_default = en_default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// src/loaders/ibanPatterns.ts
|
|
2
|
+
var cache;
|
|
3
|
+
async function loadIbanPatterns() {
|
|
4
|
+
if (cache !== void 0)
|
|
5
|
+
return cache;
|
|
6
|
+
const raw = (await import("./ibanPatterns-BSQUWKLY.js")).default;
|
|
7
|
+
const map = /* @__PURE__ */ new Map();
|
|
8
|
+
for (const entry of raw) {
|
|
9
|
+
map.set(entry.country, {
|
|
10
|
+
length: entry.length,
|
|
11
|
+
regex: new RegExp(entry.regex)
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
cache = map;
|
|
15
|
+
return cache;
|
|
16
|
+
}
|
|
17
|
+
function getIbanPatterns() {
|
|
18
|
+
if (cache === void 0) {
|
|
19
|
+
throw new Error(
|
|
20
|
+
"validex: IBAN patterns not loaded. Use parseAsync() or call preloadData() first."
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
return cache;
|
|
24
|
+
}
|
|
25
|
+
function clearIbanPatternsCache() {
|
|
26
|
+
cache = void 0;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
loadIbanPatterns,
|
|
31
|
+
getIbanPatterns,
|
|
32
|
+
clearIbanPatternsCache
|
|
33
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }// src/checks/phoneDetection.ts
|
|
2
|
+
async function containsPhoneNumber(value) {
|
|
3
|
+
const { findPhoneNumbersInText } = await Promise.resolve().then(() => _interopRequireWildcard(require("libphonenumber-js")));
|
|
4
|
+
return findPhoneNumbersInText(value).length > 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.containsPhoneNumber = containsPhoneNumber;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// src/loaders/postalCodes.ts
|
|
2
|
+
var cache;
|
|
3
|
+
async function loadPostalCodes() {
|
|
4
|
+
if (cache !== void 0)
|
|
5
|
+
return cache;
|
|
6
|
+
const mod = await import("postcode-validator");
|
|
7
|
+
cache = {
|
|
8
|
+
postcodeValidator: mod.postcodeValidator,
|
|
9
|
+
postcodeValidatorExistsForCountry: mod.postcodeValidatorExistsForCountry
|
|
10
|
+
};
|
|
11
|
+
return cache;
|
|
12
|
+
}
|
|
13
|
+
function getPostalCodes() {
|
|
14
|
+
return cache;
|
|
15
|
+
}
|
|
16
|
+
function clearPostalCodesCache() {
|
|
17
|
+
cache = void 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
loadPostalCodes,
|
|
22
|
+
getPostalCodes,
|
|
23
|
+
clearPostalCodesCache
|
|
24
|
+
};
|