@optique/core 1.0.0-dev.1252 → 1.0.0-dev.1258
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/valueparser.cjs +64 -24
- package/dist/valueparser.js +64 -24
- package/package.json +1 -1
package/dist/valueparser.cjs
CHANGED
|
@@ -499,6 +499,7 @@ function url(options = {}) {
|
|
|
499
499
|
originalProtocolsList.push(protocol);
|
|
500
500
|
normalizedProtocolsList.push(normalized);
|
|
501
501
|
}
|
|
502
|
+
if (originalProtocolsList.length === 0) throw new TypeError("allowedProtocols must not be empty.");
|
|
502
503
|
}
|
|
503
504
|
const originalProtocols = options.allowedProtocols != null ? Object.freeze(originalProtocolsList) : void 0;
|
|
504
505
|
const allowedProtocols = options.allowedProtocols != null ? Object.freeze(normalizedProtocolsList) : void 0;
|
|
@@ -517,7 +518,25 @@ function url(options = {}) {
|
|
|
517
518
|
const url$1 = new URL(input);
|
|
518
519
|
if (allowedProtocols != null && !allowedProtocols.includes(url$1.protocol)) return {
|
|
519
520
|
success: false,
|
|
520
|
-
error: disallowedProtocol ? typeof disallowedProtocol === "function" ? disallowedProtocol(url$1.protocol, originalProtocols) : disallowedProtocol :
|
|
521
|
+
error: disallowedProtocol ? typeof disallowedProtocol === "function" ? disallowedProtocol(url$1.protocol, originalProtocols) : disallowedProtocol : [
|
|
522
|
+
{
|
|
523
|
+
type: "text",
|
|
524
|
+
text: "URL protocol "
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
type: "value",
|
|
528
|
+
value: url$1.protocol
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
type: "text",
|
|
532
|
+
text: " is not allowed. Allowed protocols: "
|
|
533
|
+
},
|
|
534
|
+
...require_message.valueSet(originalProtocols, { locale: "en-US" }),
|
|
535
|
+
{
|
|
536
|
+
type: "text",
|
|
537
|
+
text: "."
|
|
538
|
+
}
|
|
539
|
+
]
|
|
521
540
|
};
|
|
522
541
|
return {
|
|
523
542
|
success: true,
|
|
@@ -1364,16 +1383,19 @@ function email(options) {
|
|
|
1364
1383
|
const allowDisplayName = options?.allowDisplayName ?? false;
|
|
1365
1384
|
const lowercase = options?.lowercase ?? false;
|
|
1366
1385
|
const allowedDomains = options?.allowedDomains != null ? Object.freeze([...options.allowedDomains]) : void 0;
|
|
1367
|
-
if (allowedDomains != null)
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1386
|
+
if (allowedDomains != null) {
|
|
1387
|
+
if (allowedDomains.length === 0) throw new TypeError("allowedDomains must not be empty.");
|
|
1388
|
+
for (let i = 0; i < allowedDomains.length; i++) {
|
|
1389
|
+
const entry = allowedDomains[i];
|
|
1390
|
+
if (typeof entry !== "string") throw new TypeError(`allowedDomains[${i}] must be a string, got ${typeof entry}.`);
|
|
1391
|
+
if (entry !== entry.trim()) throw new TypeError(`allowedDomains[${i}] must not have leading or trailing whitespace: ${JSON.stringify(entry)}`);
|
|
1392
|
+
if (entry.startsWith("@")) throw new TypeError(`allowedDomains[${i}] must not start with "@": ${JSON.stringify(entry)}`);
|
|
1393
|
+
if (entry === "" || !entry.includes(".")) throw new TypeError(`allowedDomains[${i}] is not a valid domain: ${JSON.stringify(entry)}`);
|
|
1394
|
+
if (entry.startsWith(".") || entry.endsWith(".") || entry.startsWith("-") || entry.endsWith("-")) throw new TypeError(`allowedDomains[${i}] is not a valid domain: ${JSON.stringify(entry)}`);
|
|
1395
|
+
const labels = entry.split(".");
|
|
1396
|
+
for (const label of labels) if (label.length === 0 || label.length > 63 || label.startsWith("-") || label.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(label)) throw new TypeError(`allowedDomains[${i}] is not a valid domain: ${JSON.stringify(entry)}`);
|
|
1397
|
+
if (labels.length === 4 && labels.every((label) => /^[0-9]+$/.test(label))) throw new TypeError(`allowedDomains[${i}] is not a valid domain: ${JSON.stringify(entry)}`);
|
|
1398
|
+
}
|
|
1377
1399
|
}
|
|
1378
1400
|
const invalidEmail = options?.errors?.invalidEmail;
|
|
1379
1401
|
const domainNotAllowed = options?.errors?.domainNotAllowed;
|
|
@@ -1489,7 +1511,12 @@ function email(options) {
|
|
|
1489
1511
|
},
|
|
1490
1512
|
{
|
|
1491
1513
|
type: "text",
|
|
1492
|
-
text:
|
|
1514
|
+
text: " is not allowed. Allowed domains: "
|
|
1515
|
+
},
|
|
1516
|
+
...require_message.valueSet(allowedDomains, { locale: "en-US" }),
|
|
1517
|
+
{
|
|
1518
|
+
type: "text",
|
|
1519
|
+
text: "."
|
|
1493
1520
|
}
|
|
1494
1521
|
];
|
|
1495
1522
|
return {
|
|
@@ -1535,7 +1562,12 @@ function email(options) {
|
|
|
1535
1562
|
},
|
|
1536
1563
|
{
|
|
1537
1564
|
type: "text",
|
|
1538
|
-
text:
|
|
1565
|
+
text: " is not allowed. Allowed domains: "
|
|
1566
|
+
},
|
|
1567
|
+
...require_message.valueSet(allowedDomains, { locale: "en-US" }),
|
|
1568
|
+
{
|
|
1569
|
+
type: "text",
|
|
1570
|
+
text: "."
|
|
1539
1571
|
}
|
|
1540
1572
|
];
|
|
1541
1573
|
return {
|
|
@@ -1849,8 +1881,8 @@ function macAddress(options) {
|
|
|
1849
1881
|
const caseOption = options?.case ?? "preserve";
|
|
1850
1882
|
const outputSeparator = options?.outputSeparator;
|
|
1851
1883
|
const metavar = options?.metavar ?? "MAC";
|
|
1852
|
-
const colonRegex = /^([0-9a-fA-F]{
|
|
1853
|
-
const hyphenRegex = /^([0-9a-fA-F]{
|
|
1884
|
+
const colonRegex = /^([0-9a-fA-F]{2}):([0-9a-fA-F]{2}):([0-9a-fA-F]{2}):([0-9a-fA-F]{2}):([0-9a-fA-F]{2}):([0-9a-fA-F]{2})$/;
|
|
1885
|
+
const hyphenRegex = /^([0-9a-fA-F]{2})-([0-9a-fA-F]{2})-([0-9a-fA-F]{2})-([0-9a-fA-F]{2})-([0-9a-fA-F]{2})-([0-9a-fA-F]{2})$/;
|
|
1854
1886
|
const dotRegex = /^([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})$/;
|
|
1855
1887
|
const noneRegex = /^([0-9a-fA-F]{12})$/;
|
|
1856
1888
|
return {
|
|
@@ -1983,15 +2015,18 @@ function domain(options) {
|
|
|
1983
2015
|
const allowSubdomains = options?.allowSubdomains ?? true;
|
|
1984
2016
|
const allowedTlds = options?.allowedTlds != null ? Object.freeze([...options.allowedTlds]) : void 0;
|
|
1985
2017
|
const labelRegex = /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/;
|
|
1986
|
-
if (allowedTlds !== void 0)
|
|
1987
|
-
if (
|
|
1988
|
-
|
|
1989
|
-
|
|
2018
|
+
if (allowedTlds !== void 0) {
|
|
2019
|
+
if (allowedTlds.length === 0) throw new TypeError("allowedTlds must not be empty.");
|
|
2020
|
+
for (const [i, tld] of allowedTlds.entries()) {
|
|
2021
|
+
if (typeof tld !== "string") {
|
|
2022
|
+
const actualType = Array.isArray(tld) ? "array" : typeof tld;
|
|
2023
|
+
throw new TypeError(`allowedTlds[${i}] must be a string, but got ${actualType}.`);
|
|
2024
|
+
}
|
|
2025
|
+
if (tld.length === 0) throw new TypeError(`allowedTlds[${i}] must not be an empty string.`);
|
|
2026
|
+
if (tld.includes(".")) throw new TypeError(`allowedTlds[${i}] must not contain dots: ${JSON.stringify(tld)}.`);
|
|
2027
|
+
if (tld !== tld.trim()) throw new TypeError(`allowedTlds[${i}] must not have leading or trailing whitespace: ${JSON.stringify(tld)}.`);
|
|
2028
|
+
if (!labelRegex.test(tld)) throw new TypeError(`allowedTlds[${i}] is not a valid DNS label: ${JSON.stringify(tld)}.`);
|
|
1990
2029
|
}
|
|
1991
|
-
if (tld.length === 0) throw new TypeError(`allowedTlds[${i}] must not be an empty string.`);
|
|
1992
|
-
if (tld.includes(".")) throw new TypeError(`allowedTlds[${i}] must not contain dots: ${JSON.stringify(tld)}.`);
|
|
1993
|
-
if (tld !== tld.trim()) throw new TypeError(`allowedTlds[${i}] must not have leading or trailing whitespace: ${JSON.stringify(tld)}.`);
|
|
1994
|
-
if (!labelRegex.test(tld)) throw new TypeError(`allowedTlds[${i}] is not a valid DNS label: ${JSON.stringify(tld)}.`);
|
|
1995
2030
|
}
|
|
1996
2031
|
const allowedTldsLower = allowedTlds != null ? Object.freeze(allowedTlds.map((t) => t.toLowerCase())) : void 0;
|
|
1997
2032
|
const minLabels = options?.minLabels ?? 2;
|
|
@@ -2188,7 +2223,12 @@ function domain(options) {
|
|
|
2188
2223
|
},
|
|
2189
2224
|
{
|
|
2190
2225
|
type: "text",
|
|
2191
|
-
text:
|
|
2226
|
+
text: " is not allowed. Allowed TLDs: "
|
|
2227
|
+
},
|
|
2228
|
+
...require_message.valueSet(allowedTlds, { locale: "en-US" }),
|
|
2229
|
+
{
|
|
2230
|
+
type: "text",
|
|
2231
|
+
text: "."
|
|
2192
2232
|
}
|
|
2193
2233
|
];
|
|
2194
2234
|
return {
|
package/dist/valueparser.js
CHANGED
|
@@ -499,6 +499,7 @@ function url(options = {}) {
|
|
|
499
499
|
originalProtocolsList.push(protocol);
|
|
500
500
|
normalizedProtocolsList.push(normalized);
|
|
501
501
|
}
|
|
502
|
+
if (originalProtocolsList.length === 0) throw new TypeError("allowedProtocols must not be empty.");
|
|
502
503
|
}
|
|
503
504
|
const originalProtocols = options.allowedProtocols != null ? Object.freeze(originalProtocolsList) : void 0;
|
|
504
505
|
const allowedProtocols = options.allowedProtocols != null ? Object.freeze(normalizedProtocolsList) : void 0;
|
|
@@ -517,7 +518,25 @@ function url(options = {}) {
|
|
|
517
518
|
const url$1 = new URL(input);
|
|
518
519
|
if (allowedProtocols != null && !allowedProtocols.includes(url$1.protocol)) return {
|
|
519
520
|
success: false,
|
|
520
|
-
error: disallowedProtocol ? typeof disallowedProtocol === "function" ? disallowedProtocol(url$1.protocol, originalProtocols) : disallowedProtocol :
|
|
521
|
+
error: disallowedProtocol ? typeof disallowedProtocol === "function" ? disallowedProtocol(url$1.protocol, originalProtocols) : disallowedProtocol : [
|
|
522
|
+
{
|
|
523
|
+
type: "text",
|
|
524
|
+
text: "URL protocol "
|
|
525
|
+
},
|
|
526
|
+
{
|
|
527
|
+
type: "value",
|
|
528
|
+
value: url$1.protocol
|
|
529
|
+
},
|
|
530
|
+
{
|
|
531
|
+
type: "text",
|
|
532
|
+
text: " is not allowed. Allowed protocols: "
|
|
533
|
+
},
|
|
534
|
+
...valueSet(originalProtocols, { locale: "en-US" }),
|
|
535
|
+
{
|
|
536
|
+
type: "text",
|
|
537
|
+
text: "."
|
|
538
|
+
}
|
|
539
|
+
]
|
|
521
540
|
};
|
|
522
541
|
return {
|
|
523
542
|
success: true,
|
|
@@ -1364,16 +1383,19 @@ function email(options) {
|
|
|
1364
1383
|
const allowDisplayName = options?.allowDisplayName ?? false;
|
|
1365
1384
|
const lowercase = options?.lowercase ?? false;
|
|
1366
1385
|
const allowedDomains = options?.allowedDomains != null ? Object.freeze([...options.allowedDomains]) : void 0;
|
|
1367
|
-
if (allowedDomains != null)
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1386
|
+
if (allowedDomains != null) {
|
|
1387
|
+
if (allowedDomains.length === 0) throw new TypeError("allowedDomains must not be empty.");
|
|
1388
|
+
for (let i = 0; i < allowedDomains.length; i++) {
|
|
1389
|
+
const entry = allowedDomains[i];
|
|
1390
|
+
if (typeof entry !== "string") throw new TypeError(`allowedDomains[${i}] must be a string, got ${typeof entry}.`);
|
|
1391
|
+
if (entry !== entry.trim()) throw new TypeError(`allowedDomains[${i}] must not have leading or trailing whitespace: ${JSON.stringify(entry)}`);
|
|
1392
|
+
if (entry.startsWith("@")) throw new TypeError(`allowedDomains[${i}] must not start with "@": ${JSON.stringify(entry)}`);
|
|
1393
|
+
if (entry === "" || !entry.includes(".")) throw new TypeError(`allowedDomains[${i}] is not a valid domain: ${JSON.stringify(entry)}`);
|
|
1394
|
+
if (entry.startsWith(".") || entry.endsWith(".") || entry.startsWith("-") || entry.endsWith("-")) throw new TypeError(`allowedDomains[${i}] is not a valid domain: ${JSON.stringify(entry)}`);
|
|
1395
|
+
const labels = entry.split(".");
|
|
1396
|
+
for (const label of labels) if (label.length === 0 || label.length > 63 || label.startsWith("-") || label.endsWith("-") || !/^[a-zA-Z0-9-]+$/.test(label)) throw new TypeError(`allowedDomains[${i}] is not a valid domain: ${JSON.stringify(entry)}`);
|
|
1397
|
+
if (labels.length === 4 && labels.every((label) => /^[0-9]+$/.test(label))) throw new TypeError(`allowedDomains[${i}] is not a valid domain: ${JSON.stringify(entry)}`);
|
|
1398
|
+
}
|
|
1377
1399
|
}
|
|
1378
1400
|
const invalidEmail = options?.errors?.invalidEmail;
|
|
1379
1401
|
const domainNotAllowed = options?.errors?.domainNotAllowed;
|
|
@@ -1489,7 +1511,12 @@ function email(options) {
|
|
|
1489
1511
|
},
|
|
1490
1512
|
{
|
|
1491
1513
|
type: "text",
|
|
1492
|
-
text:
|
|
1514
|
+
text: " is not allowed. Allowed domains: "
|
|
1515
|
+
},
|
|
1516
|
+
...valueSet(allowedDomains, { locale: "en-US" }),
|
|
1517
|
+
{
|
|
1518
|
+
type: "text",
|
|
1519
|
+
text: "."
|
|
1493
1520
|
}
|
|
1494
1521
|
];
|
|
1495
1522
|
return {
|
|
@@ -1535,7 +1562,12 @@ function email(options) {
|
|
|
1535
1562
|
},
|
|
1536
1563
|
{
|
|
1537
1564
|
type: "text",
|
|
1538
|
-
text:
|
|
1565
|
+
text: " is not allowed. Allowed domains: "
|
|
1566
|
+
},
|
|
1567
|
+
...valueSet(allowedDomains, { locale: "en-US" }),
|
|
1568
|
+
{
|
|
1569
|
+
type: "text",
|
|
1570
|
+
text: "."
|
|
1539
1571
|
}
|
|
1540
1572
|
];
|
|
1541
1573
|
return {
|
|
@@ -1849,8 +1881,8 @@ function macAddress(options) {
|
|
|
1849
1881
|
const caseOption = options?.case ?? "preserve";
|
|
1850
1882
|
const outputSeparator = options?.outputSeparator;
|
|
1851
1883
|
const metavar = options?.metavar ?? "MAC";
|
|
1852
|
-
const colonRegex = /^([0-9a-fA-F]{
|
|
1853
|
-
const hyphenRegex = /^([0-9a-fA-F]{
|
|
1884
|
+
const colonRegex = /^([0-9a-fA-F]{2}):([0-9a-fA-F]{2}):([0-9a-fA-F]{2}):([0-9a-fA-F]{2}):([0-9a-fA-F]{2}):([0-9a-fA-F]{2})$/;
|
|
1885
|
+
const hyphenRegex = /^([0-9a-fA-F]{2})-([0-9a-fA-F]{2})-([0-9a-fA-F]{2})-([0-9a-fA-F]{2})-([0-9a-fA-F]{2})-([0-9a-fA-F]{2})$/;
|
|
1854
1886
|
const dotRegex = /^([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})\.([0-9a-fA-F]{4})$/;
|
|
1855
1887
|
const noneRegex = /^([0-9a-fA-F]{12})$/;
|
|
1856
1888
|
return {
|
|
@@ -1983,15 +2015,18 @@ function domain(options) {
|
|
|
1983
2015
|
const allowSubdomains = options?.allowSubdomains ?? true;
|
|
1984
2016
|
const allowedTlds = options?.allowedTlds != null ? Object.freeze([...options.allowedTlds]) : void 0;
|
|
1985
2017
|
const labelRegex = /^[a-zA-Z0-9]([a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?$/;
|
|
1986
|
-
if (allowedTlds !== void 0)
|
|
1987
|
-
if (
|
|
1988
|
-
|
|
1989
|
-
|
|
2018
|
+
if (allowedTlds !== void 0) {
|
|
2019
|
+
if (allowedTlds.length === 0) throw new TypeError("allowedTlds must not be empty.");
|
|
2020
|
+
for (const [i, tld] of allowedTlds.entries()) {
|
|
2021
|
+
if (typeof tld !== "string") {
|
|
2022
|
+
const actualType = Array.isArray(tld) ? "array" : typeof tld;
|
|
2023
|
+
throw new TypeError(`allowedTlds[${i}] must be a string, but got ${actualType}.`);
|
|
2024
|
+
}
|
|
2025
|
+
if (tld.length === 0) throw new TypeError(`allowedTlds[${i}] must not be an empty string.`);
|
|
2026
|
+
if (tld.includes(".")) throw new TypeError(`allowedTlds[${i}] must not contain dots: ${JSON.stringify(tld)}.`);
|
|
2027
|
+
if (tld !== tld.trim()) throw new TypeError(`allowedTlds[${i}] must not have leading or trailing whitespace: ${JSON.stringify(tld)}.`);
|
|
2028
|
+
if (!labelRegex.test(tld)) throw new TypeError(`allowedTlds[${i}] is not a valid DNS label: ${JSON.stringify(tld)}.`);
|
|
1990
2029
|
}
|
|
1991
|
-
if (tld.length === 0) throw new TypeError(`allowedTlds[${i}] must not be an empty string.`);
|
|
1992
|
-
if (tld.includes(".")) throw new TypeError(`allowedTlds[${i}] must not contain dots: ${JSON.stringify(tld)}.`);
|
|
1993
|
-
if (tld !== tld.trim()) throw new TypeError(`allowedTlds[${i}] must not have leading or trailing whitespace: ${JSON.stringify(tld)}.`);
|
|
1994
|
-
if (!labelRegex.test(tld)) throw new TypeError(`allowedTlds[${i}] is not a valid DNS label: ${JSON.stringify(tld)}.`);
|
|
1995
2030
|
}
|
|
1996
2031
|
const allowedTldsLower = allowedTlds != null ? Object.freeze(allowedTlds.map((t) => t.toLowerCase())) : void 0;
|
|
1997
2032
|
const minLabels = options?.minLabels ?? 2;
|
|
@@ -2188,7 +2223,12 @@ function domain(options) {
|
|
|
2188
2223
|
},
|
|
2189
2224
|
{
|
|
2190
2225
|
type: "text",
|
|
2191
|
-
text:
|
|
2226
|
+
text: " is not allowed. Allowed TLDs: "
|
|
2227
|
+
},
|
|
2228
|
+
...valueSet(allowedTlds, { locale: "en-US" }),
|
|
2229
|
+
{
|
|
2230
|
+
type: "text",
|
|
2231
|
+
text: "."
|
|
2192
2232
|
}
|
|
2193
2233
|
];
|
|
2194
2234
|
return {
|