@optique/core 1.0.0-dev.1484 → 1.0.0-dev.1495
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/doc.cjs +9 -9
- package/dist/doc.js +9 -9
- package/dist/valueparser.cjs +148 -39
- package/dist/valueparser.js +148 -39
- package/package.json +1 -1
package/dist/doc.cjs
CHANGED
|
@@ -250,9 +250,9 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
250
250
|
const entryMin = needsDescColumn ? Math.min(splitEntryMin, fixedEntryMin) : hasEntries ? termIndent + 1 : 1;
|
|
251
251
|
const usageMin = page.usage != null ? 7 + Math.max(programName.length, Math.min(maxVisibleAtomicWidth(page.usage), programName.length + 7)) : 1;
|
|
252
252
|
let sectionMin = 1;
|
|
253
|
-
if (page.examples
|
|
254
|
-
if (page.author
|
|
255
|
-
if (page.bugs
|
|
253
|
+
if (hasContent(page.examples)) sectionMin = Math.max(sectionMin, 9);
|
|
254
|
+
if (hasContent(page.author)) sectionMin = Math.max(sectionMin, 7);
|
|
255
|
+
if (hasContent(page.bugs)) sectionMin = Math.max(sectionMin, 5);
|
|
256
256
|
const minWidth = Math.max(entryMin, usageMin, sectionMin);
|
|
257
257
|
if (options.maxWidth < minWidth) throw new RangeError(`maxWidth must be at least ${minWidth}, got ${options.maxWidth}.`);
|
|
258
258
|
if (needsDescColumn && minDescWidth > 1) {
|
|
@@ -272,7 +272,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
272
272
|
effectiveTermWidth = availableForColumns >= termWidth + 1 ? termWidth : Math.max(1, Math.floor(availableForColumns / 2));
|
|
273
273
|
}
|
|
274
274
|
let output = "";
|
|
275
|
-
if (page.brief
|
|
275
|
+
if (hasContent(page.brief)) {
|
|
276
276
|
output += require_message.formatMessage(page.brief, {
|
|
277
277
|
colors: options.colors,
|
|
278
278
|
maxWidth: options.maxWidth,
|
|
@@ -290,7 +290,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
290
290
|
}), 7);
|
|
291
291
|
output += "\n";
|
|
292
292
|
}
|
|
293
|
-
if (page.description
|
|
293
|
+
if (hasContent(page.description)) {
|
|
294
294
|
output += "\n";
|
|
295
295
|
output += require_message.formatMessage(page.description, {
|
|
296
296
|
colors: options.colors,
|
|
@@ -402,7 +402,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
402
402
|
output += `${" ".repeat(termIndent)}${ansiAwareRightPad(term, effectiveTermWidth)}${description === "" ? "" : ` ${indentLines(description, termIndent + effectiveTermWidth + 2)}`}\n`;
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
|
-
if (page.examples
|
|
405
|
+
if (hasContent(page.examples)) {
|
|
406
406
|
output += "\n";
|
|
407
407
|
const examplesLabel = options.colors ? "\x1B[1;2mExamples:\x1B[0m\n" : "Examples:\n";
|
|
408
408
|
output += examplesLabel;
|
|
@@ -414,7 +414,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
414
414
|
output += " " + indentLines(examplesContent, 2);
|
|
415
415
|
output += "\n";
|
|
416
416
|
}
|
|
417
|
-
if (page.author
|
|
417
|
+
if (hasContent(page.author)) {
|
|
418
418
|
output += "\n";
|
|
419
419
|
const authorLabel = options.colors ? "\x1B[1;2mAuthor:\x1B[0m\n" : "Author:\n";
|
|
420
420
|
output += authorLabel;
|
|
@@ -426,7 +426,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
426
426
|
output += " " + indentLines(authorContent, 2);
|
|
427
427
|
output += "\n";
|
|
428
428
|
}
|
|
429
|
-
if (page.bugs
|
|
429
|
+
if (hasContent(page.bugs)) {
|
|
430
430
|
output += "\n";
|
|
431
431
|
const bugsLabel = options.colors ? "\x1B[1;2mBugs:\x1B[0m\n" : "Bugs:\n";
|
|
432
432
|
output += bugsLabel;
|
|
@@ -438,7 +438,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
438
438
|
output += " " + indentLines(bugsContent, 2);
|
|
439
439
|
output += "\n";
|
|
440
440
|
}
|
|
441
|
-
if (page.footer
|
|
441
|
+
if (hasContent(page.footer)) {
|
|
442
442
|
output += "\n";
|
|
443
443
|
output += require_message.formatMessage(page.footer, {
|
|
444
444
|
colors: options.colors,
|
package/dist/doc.js
CHANGED
|
@@ -250,9 +250,9 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
250
250
|
const entryMin = needsDescColumn ? Math.min(splitEntryMin, fixedEntryMin) : hasEntries ? termIndent + 1 : 1;
|
|
251
251
|
const usageMin = page.usage != null ? 7 + Math.max(programName.length, Math.min(maxVisibleAtomicWidth(page.usage), programName.length + 7)) : 1;
|
|
252
252
|
let sectionMin = 1;
|
|
253
|
-
if (page.examples
|
|
254
|
-
if (page.author
|
|
255
|
-
if (page.bugs
|
|
253
|
+
if (hasContent(page.examples)) sectionMin = Math.max(sectionMin, 9);
|
|
254
|
+
if (hasContent(page.author)) sectionMin = Math.max(sectionMin, 7);
|
|
255
|
+
if (hasContent(page.bugs)) sectionMin = Math.max(sectionMin, 5);
|
|
256
256
|
const minWidth = Math.max(entryMin, usageMin, sectionMin);
|
|
257
257
|
if (options.maxWidth < minWidth) throw new RangeError(`maxWidth must be at least ${minWidth}, got ${options.maxWidth}.`);
|
|
258
258
|
if (needsDescColumn && minDescWidth > 1) {
|
|
@@ -272,7 +272,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
272
272
|
effectiveTermWidth = availableForColumns >= termWidth + 1 ? termWidth : Math.max(1, Math.floor(availableForColumns / 2));
|
|
273
273
|
}
|
|
274
274
|
let output = "";
|
|
275
|
-
if (page.brief
|
|
275
|
+
if (hasContent(page.brief)) {
|
|
276
276
|
output += formatMessage(page.brief, {
|
|
277
277
|
colors: options.colors,
|
|
278
278
|
maxWidth: options.maxWidth,
|
|
@@ -290,7 +290,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
290
290
|
}), 7);
|
|
291
291
|
output += "\n";
|
|
292
292
|
}
|
|
293
|
-
if (page.description
|
|
293
|
+
if (hasContent(page.description)) {
|
|
294
294
|
output += "\n";
|
|
295
295
|
output += formatMessage(page.description, {
|
|
296
296
|
colors: options.colors,
|
|
@@ -402,7 +402,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
402
402
|
output += `${" ".repeat(termIndent)}${ansiAwareRightPad(term, effectiveTermWidth)}${description === "" ? "" : ` ${indentLines(description, termIndent + effectiveTermWidth + 2)}`}\n`;
|
|
403
403
|
}
|
|
404
404
|
}
|
|
405
|
-
if (page.examples
|
|
405
|
+
if (hasContent(page.examples)) {
|
|
406
406
|
output += "\n";
|
|
407
407
|
const examplesLabel = options.colors ? "\x1B[1;2mExamples:\x1B[0m\n" : "Examples:\n";
|
|
408
408
|
output += examplesLabel;
|
|
@@ -414,7 +414,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
414
414
|
output += " " + indentLines(examplesContent, 2);
|
|
415
415
|
output += "\n";
|
|
416
416
|
}
|
|
417
|
-
if (page.author
|
|
417
|
+
if (hasContent(page.author)) {
|
|
418
418
|
output += "\n";
|
|
419
419
|
const authorLabel = options.colors ? "\x1B[1;2mAuthor:\x1B[0m\n" : "Author:\n";
|
|
420
420
|
output += authorLabel;
|
|
@@ -426,7 +426,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
426
426
|
output += " " + indentLines(authorContent, 2);
|
|
427
427
|
output += "\n";
|
|
428
428
|
}
|
|
429
|
-
if (page.bugs
|
|
429
|
+
if (hasContent(page.bugs)) {
|
|
430
430
|
output += "\n";
|
|
431
431
|
const bugsLabel = options.colors ? "\x1B[1;2mBugs:\x1B[0m\n" : "Bugs:\n";
|
|
432
432
|
output += bugsLabel;
|
|
@@ -438,7 +438,7 @@ function formatDocPage(programName, page, options = {}) {
|
|
|
438
438
|
output += " " + indentLines(bugsContent, 2);
|
|
439
439
|
output += "\n";
|
|
440
440
|
}
|
|
441
|
-
if (page.footer
|
|
441
|
+
if (hasContent(page.footer)) {
|
|
442
442
|
output += "\n";
|
|
443
443
|
output += formatMessage(page.footer, {
|
|
444
444
|
colors: options.colors,
|
package/dist/valueparser.cjs
CHANGED
|
@@ -1726,73 +1726,182 @@ function socketAddress(options) {
|
|
|
1726
1726
|
metavar,
|
|
1727
1727
|
parse(input) {
|
|
1728
1728
|
const trimmed = input.trim();
|
|
1729
|
-
const
|
|
1730
|
-
let
|
|
1731
|
-
let
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
const
|
|
1742
|
-
if (
|
|
1743
|
-
|
|
1729
|
+
const canOmitPort = defaultPort !== void 0 && !requirePort;
|
|
1730
|
+
let firstHostError;
|
|
1731
|
+
let validHostNumericPortInvalid = false;
|
|
1732
|
+
let trailingSepHost;
|
|
1733
|
+
let trailingSepHostError;
|
|
1734
|
+
let anySeparatorFound = false;
|
|
1735
|
+
let searchFrom = trimmed.length;
|
|
1736
|
+
while (searchFrom > 0) {
|
|
1737
|
+
const separatorIndex = trimmed.lastIndexOf(separator, searchFrom - 1);
|
|
1738
|
+
if (separatorIndex === -1) break;
|
|
1739
|
+
anySeparatorFound = true;
|
|
1740
|
+
const hostPart = trimmed.substring(0, separatorIndex);
|
|
1741
|
+
const portPart = trimmed.substring(separatorIndex + separator.length);
|
|
1742
|
+
if (portPart === "") {
|
|
1743
|
+
if (trailingSepHost === void 0 && trailingSepHostError === void 0) {
|
|
1744
|
+
const hostResult = parseHost(hostPart);
|
|
1745
|
+
if (hostResult.success) trailingSepHost = hostResult.value;
|
|
1746
|
+
else trailingSepHostError = {
|
|
1747
|
+
hostPart,
|
|
1748
|
+
error: hostResult.error
|
|
1749
|
+
};
|
|
1750
|
+
}
|
|
1751
|
+
} else {
|
|
1752
|
+
const portResult = portParser.parse(portPart);
|
|
1753
|
+
if (portResult.success) {
|
|
1754
|
+
const hostResult = parseHost(hostPart);
|
|
1755
|
+
if (hostResult.success) return {
|
|
1756
|
+
success: true,
|
|
1757
|
+
value: {
|
|
1758
|
+
host: hostResult.value,
|
|
1759
|
+
port: portResult.value
|
|
1760
|
+
}
|
|
1761
|
+
};
|
|
1762
|
+
if (firstHostError === void 0 || (looksLikeIpv4(hostPart) || looksLikeAltIpv4Literal(hostPart)) && !looksLikeIpv4(firstHostError.hostPart) && !looksLikeAltIpv4Literal(firstHostError.hostPart)) firstHostError = {
|
|
1763
|
+
hostPart,
|
|
1764
|
+
error: hostResult.error
|
|
1765
|
+
};
|
|
1766
|
+
} else if (!validHostNumericPortInvalid && hostPart !== "" && /^[0-9]+$/.test(portPart)) if (looksLikeIpv4(hostPart) || looksLikeAltIpv4Literal(hostPart)) {
|
|
1767
|
+
const hostResult = parseHost(hostPart);
|
|
1768
|
+
if (!hostResult.success) {
|
|
1769
|
+
if (firstHostError === void 0 || !looksLikeIpv4(firstHostError.hostPart) && !looksLikeAltIpv4Literal(firstHostError.hostPart)) firstHostError = {
|
|
1770
|
+
hostPart,
|
|
1771
|
+
error: hostResult.error
|
|
1772
|
+
};
|
|
1773
|
+
} else validHostNumericPortInvalid = true;
|
|
1774
|
+
} else validHostNumericPortInvalid = true;
|
|
1775
|
+
else if ((firstHostError === void 0 || !looksLikeIpv4(firstHostError.hostPart) && !looksLikeAltIpv4Literal(firstHostError.hostPart)) && (looksLikeIpv4(hostPart) || looksLikeAltIpv4Literal(hostPart))) {
|
|
1776
|
+
const hostResult = parseHost(hostPart);
|
|
1777
|
+
if (!hostResult.success) firstHostError = {
|
|
1778
|
+
hostPart,
|
|
1779
|
+
error: hostResult.error
|
|
1780
|
+
};
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
searchFrom = separatorIndex;
|
|
1784
|
+
}
|
|
1785
|
+
if (validHostNumericPortInvalid) {
|
|
1786
|
+
const errorMsg$1 = options?.errors?.invalidFormat;
|
|
1787
|
+
if (errorMsg$1) {
|
|
1788
|
+
const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1;
|
|
1744
1789
|
return {
|
|
1745
1790
|
success: false,
|
|
1746
1791
|
error: msg
|
|
1747
1792
|
};
|
|
1748
1793
|
}
|
|
1749
|
-
|
|
1794
|
+
return {
|
|
1750
1795
|
success: false,
|
|
1751
|
-
error:
|
|
1796
|
+
error: require_message.message`Expected a socket address in format host${separator}port, but got ${input}.`
|
|
1797
|
+
};
|
|
1798
|
+
}
|
|
1799
|
+
if (firstHostError !== void 0) {
|
|
1800
|
+
if (looksLikeIpv4(firstHostError.hostPart) || looksLikeAltIpv4Literal(firstHostError.hostPart)) {
|
|
1801
|
+
const errorMsg$1 = options?.errors?.invalidFormat;
|
|
1802
|
+
if (errorMsg$1) {
|
|
1803
|
+
const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1;
|
|
1804
|
+
return {
|
|
1805
|
+
success: false,
|
|
1806
|
+
error: msg
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
return {
|
|
1810
|
+
success: false,
|
|
1811
|
+
error: firstHostError.error
|
|
1812
|
+
};
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
let hostOnlyResult;
|
|
1816
|
+
if (!requirePort || trailingSepHost !== void 0 || trailingSepHostError !== void 0) {
|
|
1817
|
+
hostOnlyResult = parseHost(trimmed);
|
|
1818
|
+
if (canOmitPort && hostOnlyResult.success) return {
|
|
1819
|
+
success: true,
|
|
1820
|
+
value: {
|
|
1821
|
+
host: hostOnlyResult.value,
|
|
1822
|
+
port: defaultPort
|
|
1823
|
+
}
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
if (trailingSepHost !== void 0 && hostOnlyResult !== void 0 && !hostOnlyResult.success) {
|
|
1827
|
+
if (canOmitPort) return {
|
|
1828
|
+
success: true,
|
|
1829
|
+
value: {
|
|
1830
|
+
host: trailingSepHost,
|
|
1831
|
+
port: defaultPort
|
|
1832
|
+
}
|
|
1752
1833
|
};
|
|
1834
|
+
const errorMsg$1 = options?.errors?.missingPort;
|
|
1835
|
+
const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1 ?? require_message.message`Port number is required but was not specified.`;
|
|
1753
1836
|
return {
|
|
1754
1837
|
success: false,
|
|
1755
|
-
error:
|
|
1838
|
+
error: msg
|
|
1756
1839
|
};
|
|
1757
1840
|
}
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
const errorMsg = options?.errors?.missingPort;
|
|
1763
|
-
const msg = typeof errorMsg === "function" ? errorMsg(input) : errorMsg ?? require_message.message`Port number is required but was not specified.`;
|
|
1841
|
+
if (trailingSepHostError !== void 0 && hostOnlyResult !== void 0 && !hostOnlyResult.success) {
|
|
1842
|
+
const errorMsg$1 = options?.errors?.invalidFormat;
|
|
1843
|
+
if (errorMsg$1) {
|
|
1844
|
+
const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1;
|
|
1764
1845
|
return {
|
|
1765
1846
|
success: false,
|
|
1766
1847
|
error: msg
|
|
1767
1848
|
};
|
|
1768
1849
|
}
|
|
1769
|
-
if (
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1850
|
+
if (looksLikeIpv4(trailingSepHostError.hostPart) || looksLikeAltIpv4Literal(trailingSepHostError.hostPart)) return {
|
|
1851
|
+
success: false,
|
|
1852
|
+
error: trailingSepHostError.error
|
|
1853
|
+
};
|
|
1854
|
+
return {
|
|
1855
|
+
success: false,
|
|
1856
|
+
error: require_message.message`Expected a socket address in format host${separator}port, but got ${input}.`
|
|
1857
|
+
};
|
|
1858
|
+
}
|
|
1859
|
+
if (!canOmitPort && !requirePort && hostOnlyResult !== void 0 && hostOnlyResult.success) {
|
|
1860
|
+
const errorMsg$1 = options?.errors?.missingPort;
|
|
1861
|
+
const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1 ?? require_message.message`Port number is required but was not specified.`;
|
|
1862
|
+
return {
|
|
1863
|
+
success: false,
|
|
1864
|
+
error: msg
|
|
1865
|
+
};
|
|
1866
|
+
}
|
|
1867
|
+
if (!canOmitPort && !anySeparatorFound) {
|
|
1868
|
+
hostOnlyResult = hostOnlyResult ?? parseHost(trimmed);
|
|
1869
|
+
if (hostOnlyResult.success) {
|
|
1870
|
+
const errorMsg$1 = options?.errors?.missingPort;
|
|
1871
|
+
const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1 ?? require_message.message`Port number is required but was not specified.`;
|
|
1773
1872
|
return {
|
|
1774
1873
|
success: false,
|
|
1775
1874
|
error: msg
|
|
1776
1875
|
};
|
|
1777
1876
|
}
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
const msg = typeof errorMsg === "function" ? errorMsg(input) : errorMsg
|
|
1877
|
+
}
|
|
1878
|
+
if (firstHostError !== void 0) {
|
|
1879
|
+
const errorMsg$1 = options?.errors?.invalidFormat;
|
|
1880
|
+
if (errorMsg$1) {
|
|
1881
|
+
const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1;
|
|
1783
1882
|
return {
|
|
1784
1883
|
success: false,
|
|
1785
1884
|
error: msg
|
|
1786
1885
|
};
|
|
1787
1886
|
}
|
|
1788
|
-
|
|
1887
|
+
}
|
|
1888
|
+
const errorMsg = options?.errors?.invalidFormat;
|
|
1889
|
+
if (errorMsg) {
|
|
1890
|
+
const msg = typeof errorMsg === "function" ? errorMsg(input) : errorMsg;
|
|
1891
|
+
return {
|
|
1892
|
+
success: false,
|
|
1893
|
+
error: msg
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1896
|
+
if (hostOnlyResult !== void 0 && !hostOnlyResult.success) {
|
|
1897
|
+
if (looksLikeIpv4(trimmed) || looksLikeAltIpv4Literal(trimmed)) return {
|
|
1898
|
+
success: false,
|
|
1899
|
+
error: hostOnlyResult.error
|
|
1900
|
+
};
|
|
1789
1901
|
}
|
|
1790
1902
|
return {
|
|
1791
|
-
success:
|
|
1792
|
-
|
|
1793
|
-
host: validatedHost,
|
|
1794
|
-
port: validatedPort
|
|
1795
|
-
}
|
|
1903
|
+
success: false,
|
|
1904
|
+
error: require_message.message`Expected a socket address in format host${separator}port, but got ${input}.`
|
|
1796
1905
|
};
|
|
1797
1906
|
},
|
|
1798
1907
|
format(value) {
|
package/dist/valueparser.js
CHANGED
|
@@ -1726,73 +1726,182 @@ function socketAddress(options) {
|
|
|
1726
1726
|
metavar,
|
|
1727
1727
|
parse(input) {
|
|
1728
1728
|
const trimmed = input.trim();
|
|
1729
|
-
const
|
|
1730
|
-
let
|
|
1731
|
-
let
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
const
|
|
1742
|
-
if (
|
|
1743
|
-
|
|
1729
|
+
const canOmitPort = defaultPort !== void 0 && !requirePort;
|
|
1730
|
+
let firstHostError;
|
|
1731
|
+
let validHostNumericPortInvalid = false;
|
|
1732
|
+
let trailingSepHost;
|
|
1733
|
+
let trailingSepHostError;
|
|
1734
|
+
let anySeparatorFound = false;
|
|
1735
|
+
let searchFrom = trimmed.length;
|
|
1736
|
+
while (searchFrom > 0) {
|
|
1737
|
+
const separatorIndex = trimmed.lastIndexOf(separator, searchFrom - 1);
|
|
1738
|
+
if (separatorIndex === -1) break;
|
|
1739
|
+
anySeparatorFound = true;
|
|
1740
|
+
const hostPart = trimmed.substring(0, separatorIndex);
|
|
1741
|
+
const portPart = trimmed.substring(separatorIndex + separator.length);
|
|
1742
|
+
if (portPart === "") {
|
|
1743
|
+
if (trailingSepHost === void 0 && trailingSepHostError === void 0) {
|
|
1744
|
+
const hostResult = parseHost(hostPart);
|
|
1745
|
+
if (hostResult.success) trailingSepHost = hostResult.value;
|
|
1746
|
+
else trailingSepHostError = {
|
|
1747
|
+
hostPart,
|
|
1748
|
+
error: hostResult.error
|
|
1749
|
+
};
|
|
1750
|
+
}
|
|
1751
|
+
} else {
|
|
1752
|
+
const portResult = portParser.parse(portPart);
|
|
1753
|
+
if (portResult.success) {
|
|
1754
|
+
const hostResult = parseHost(hostPart);
|
|
1755
|
+
if (hostResult.success) return {
|
|
1756
|
+
success: true,
|
|
1757
|
+
value: {
|
|
1758
|
+
host: hostResult.value,
|
|
1759
|
+
port: portResult.value
|
|
1760
|
+
}
|
|
1761
|
+
};
|
|
1762
|
+
if (firstHostError === void 0 || (looksLikeIpv4(hostPart) || looksLikeAltIpv4Literal(hostPart)) && !looksLikeIpv4(firstHostError.hostPart) && !looksLikeAltIpv4Literal(firstHostError.hostPart)) firstHostError = {
|
|
1763
|
+
hostPart,
|
|
1764
|
+
error: hostResult.error
|
|
1765
|
+
};
|
|
1766
|
+
} else if (!validHostNumericPortInvalid && hostPart !== "" && /^[0-9]+$/.test(portPart)) if (looksLikeIpv4(hostPart) || looksLikeAltIpv4Literal(hostPart)) {
|
|
1767
|
+
const hostResult = parseHost(hostPart);
|
|
1768
|
+
if (!hostResult.success) {
|
|
1769
|
+
if (firstHostError === void 0 || !looksLikeIpv4(firstHostError.hostPart) && !looksLikeAltIpv4Literal(firstHostError.hostPart)) firstHostError = {
|
|
1770
|
+
hostPart,
|
|
1771
|
+
error: hostResult.error
|
|
1772
|
+
};
|
|
1773
|
+
} else validHostNumericPortInvalid = true;
|
|
1774
|
+
} else validHostNumericPortInvalid = true;
|
|
1775
|
+
else if ((firstHostError === void 0 || !looksLikeIpv4(firstHostError.hostPart) && !looksLikeAltIpv4Literal(firstHostError.hostPart)) && (looksLikeIpv4(hostPart) || looksLikeAltIpv4Literal(hostPart))) {
|
|
1776
|
+
const hostResult = parseHost(hostPart);
|
|
1777
|
+
if (!hostResult.success) firstHostError = {
|
|
1778
|
+
hostPart,
|
|
1779
|
+
error: hostResult.error
|
|
1780
|
+
};
|
|
1781
|
+
}
|
|
1782
|
+
}
|
|
1783
|
+
searchFrom = separatorIndex;
|
|
1784
|
+
}
|
|
1785
|
+
if (validHostNumericPortInvalid) {
|
|
1786
|
+
const errorMsg$1 = options?.errors?.invalidFormat;
|
|
1787
|
+
if (errorMsg$1) {
|
|
1788
|
+
const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1;
|
|
1744
1789
|
return {
|
|
1745
1790
|
success: false,
|
|
1746
1791
|
error: msg
|
|
1747
1792
|
};
|
|
1748
1793
|
}
|
|
1749
|
-
|
|
1794
|
+
return {
|
|
1750
1795
|
success: false,
|
|
1751
|
-
error:
|
|
1796
|
+
error: message`Expected a socket address in format host${separator}port, but got ${input}.`
|
|
1797
|
+
};
|
|
1798
|
+
}
|
|
1799
|
+
if (firstHostError !== void 0) {
|
|
1800
|
+
if (looksLikeIpv4(firstHostError.hostPart) || looksLikeAltIpv4Literal(firstHostError.hostPart)) {
|
|
1801
|
+
const errorMsg$1 = options?.errors?.invalidFormat;
|
|
1802
|
+
if (errorMsg$1) {
|
|
1803
|
+
const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1;
|
|
1804
|
+
return {
|
|
1805
|
+
success: false,
|
|
1806
|
+
error: msg
|
|
1807
|
+
};
|
|
1808
|
+
}
|
|
1809
|
+
return {
|
|
1810
|
+
success: false,
|
|
1811
|
+
error: firstHostError.error
|
|
1812
|
+
};
|
|
1813
|
+
}
|
|
1814
|
+
}
|
|
1815
|
+
let hostOnlyResult;
|
|
1816
|
+
if (!requirePort || trailingSepHost !== void 0 || trailingSepHostError !== void 0) {
|
|
1817
|
+
hostOnlyResult = parseHost(trimmed);
|
|
1818
|
+
if (canOmitPort && hostOnlyResult.success) return {
|
|
1819
|
+
success: true,
|
|
1820
|
+
value: {
|
|
1821
|
+
host: hostOnlyResult.value,
|
|
1822
|
+
port: defaultPort
|
|
1823
|
+
}
|
|
1824
|
+
};
|
|
1825
|
+
}
|
|
1826
|
+
if (trailingSepHost !== void 0 && hostOnlyResult !== void 0 && !hostOnlyResult.success) {
|
|
1827
|
+
if (canOmitPort) return {
|
|
1828
|
+
success: true,
|
|
1829
|
+
value: {
|
|
1830
|
+
host: trailingSepHost,
|
|
1831
|
+
port: defaultPort
|
|
1832
|
+
}
|
|
1752
1833
|
};
|
|
1834
|
+
const errorMsg$1 = options?.errors?.missingPort;
|
|
1835
|
+
const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1 ?? message`Port number is required but was not specified.`;
|
|
1753
1836
|
return {
|
|
1754
1837
|
success: false,
|
|
1755
|
-
error:
|
|
1838
|
+
error: msg
|
|
1756
1839
|
};
|
|
1757
1840
|
}
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
const errorMsg = options?.errors?.missingPort;
|
|
1763
|
-
const msg = typeof errorMsg === "function" ? errorMsg(input) : errorMsg ?? message`Port number is required but was not specified.`;
|
|
1841
|
+
if (trailingSepHostError !== void 0 && hostOnlyResult !== void 0 && !hostOnlyResult.success) {
|
|
1842
|
+
const errorMsg$1 = options?.errors?.invalidFormat;
|
|
1843
|
+
if (errorMsg$1) {
|
|
1844
|
+
const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1;
|
|
1764
1845
|
return {
|
|
1765
1846
|
success: false,
|
|
1766
1847
|
error: msg
|
|
1767
1848
|
};
|
|
1768
1849
|
}
|
|
1769
|
-
if (
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1850
|
+
if (looksLikeIpv4(trailingSepHostError.hostPart) || looksLikeAltIpv4Literal(trailingSepHostError.hostPart)) return {
|
|
1851
|
+
success: false,
|
|
1852
|
+
error: trailingSepHostError.error
|
|
1853
|
+
};
|
|
1854
|
+
return {
|
|
1855
|
+
success: false,
|
|
1856
|
+
error: message`Expected a socket address in format host${separator}port, but got ${input}.`
|
|
1857
|
+
};
|
|
1858
|
+
}
|
|
1859
|
+
if (!canOmitPort && !requirePort && hostOnlyResult !== void 0 && hostOnlyResult.success) {
|
|
1860
|
+
const errorMsg$1 = options?.errors?.missingPort;
|
|
1861
|
+
const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1 ?? message`Port number is required but was not specified.`;
|
|
1862
|
+
return {
|
|
1863
|
+
success: false,
|
|
1864
|
+
error: msg
|
|
1865
|
+
};
|
|
1866
|
+
}
|
|
1867
|
+
if (!canOmitPort && !anySeparatorFound) {
|
|
1868
|
+
hostOnlyResult = hostOnlyResult ?? parseHost(trimmed);
|
|
1869
|
+
if (hostOnlyResult.success) {
|
|
1870
|
+
const errorMsg$1 = options?.errors?.missingPort;
|
|
1871
|
+
const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1 ?? message`Port number is required but was not specified.`;
|
|
1773
1872
|
return {
|
|
1774
1873
|
success: false,
|
|
1775
1874
|
error: msg
|
|
1776
1875
|
};
|
|
1777
1876
|
}
|
|
1778
|
-
}
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
const msg = typeof errorMsg === "function" ? errorMsg(input) : errorMsg
|
|
1877
|
+
}
|
|
1878
|
+
if (firstHostError !== void 0) {
|
|
1879
|
+
const errorMsg$1 = options?.errors?.invalidFormat;
|
|
1880
|
+
if (errorMsg$1) {
|
|
1881
|
+
const msg = typeof errorMsg$1 === "function" ? errorMsg$1(input) : errorMsg$1;
|
|
1783
1882
|
return {
|
|
1784
1883
|
success: false,
|
|
1785
1884
|
error: msg
|
|
1786
1885
|
};
|
|
1787
1886
|
}
|
|
1788
|
-
|
|
1887
|
+
}
|
|
1888
|
+
const errorMsg = options?.errors?.invalidFormat;
|
|
1889
|
+
if (errorMsg) {
|
|
1890
|
+
const msg = typeof errorMsg === "function" ? errorMsg(input) : errorMsg;
|
|
1891
|
+
return {
|
|
1892
|
+
success: false,
|
|
1893
|
+
error: msg
|
|
1894
|
+
};
|
|
1895
|
+
}
|
|
1896
|
+
if (hostOnlyResult !== void 0 && !hostOnlyResult.success) {
|
|
1897
|
+
if (looksLikeIpv4(trimmed) || looksLikeAltIpv4Literal(trimmed)) return {
|
|
1898
|
+
success: false,
|
|
1899
|
+
error: hostOnlyResult.error
|
|
1900
|
+
};
|
|
1789
1901
|
}
|
|
1790
1902
|
return {
|
|
1791
|
-
success:
|
|
1792
|
-
|
|
1793
|
-
host: validatedHost,
|
|
1794
|
-
port: validatedPort
|
|
1795
|
-
}
|
|
1903
|
+
success: false,
|
|
1904
|
+
error: message`Expected a socket address in format host${separator}port, but got ${input}.`
|
|
1796
1905
|
};
|
|
1797
1906
|
},
|
|
1798
1907
|
format(value) {
|