@optique/core 1.0.0-dev.1431 → 1.0.0-dev.1438
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 +35 -16
- package/dist/valueparser.js +35 -16
- package/package.json +1 -1
package/dist/valueparser.cjs
CHANGED
|
@@ -1164,6 +1164,14 @@ function ipv4(options) {
|
|
|
1164
1164
|
error: msg
|
|
1165
1165
|
};
|
|
1166
1166
|
}
|
|
1167
|
+
if (!/^[0-9]+$/.test(part)) {
|
|
1168
|
+
const errorMsg = options?.errors?.invalidIpv4;
|
|
1169
|
+
const msg = typeof errorMsg === "function" ? errorMsg(input) : errorMsg ?? require_message.message`Expected a valid IPv4 address, but got ${input}.`;
|
|
1170
|
+
return {
|
|
1171
|
+
success: false,
|
|
1172
|
+
error: msg
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1167
1175
|
const octet = Number(part);
|
|
1168
1176
|
if (!Number.isInteger(octet) || octet < 0 || octet > 255) {
|
|
1169
1177
|
const errorMsg = options?.errors?.invalidIpv4;
|
|
@@ -1664,20 +1672,20 @@ function socketAddress(options) {
|
|
|
1664
1672
|
metavar: "PORT",
|
|
1665
1673
|
type: "number"
|
|
1666
1674
|
});
|
|
1675
|
+
function looksLikeIpv4(input) {
|
|
1676
|
+
return /^\d+\.\d+\.\d+\.\d+$/.test(input);
|
|
1677
|
+
}
|
|
1667
1678
|
function parseHost(hostInput) {
|
|
1668
1679
|
if (hostType === "hostname") {
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
if (ipResult.success) return ipResult.value;
|
|
1679
|
-
const hostnameResult = hostnameParser.parse(hostInput);
|
|
1680
|
-
return hostnameResult.success ? hostnameResult.value : null;
|
|
1680
|
+
if (looksLikeIpv4(hostInput)) return {
|
|
1681
|
+
success: false,
|
|
1682
|
+
error: require_message.message`Expected a valid hostname, but got ${hostInput}.`
|
|
1683
|
+
};
|
|
1684
|
+
return hostnameParser.parse(hostInput);
|
|
1685
|
+
} else if (hostType === "ip") return ipParser.parse(hostInput);
|
|
1686
|
+
else {
|
|
1687
|
+
if (looksLikeIpv4(hostInput)) return ipParser.parse(hostInput);
|
|
1688
|
+
return hostnameParser.parse(hostInput);
|
|
1681
1689
|
}
|
|
1682
1690
|
}
|
|
1683
1691
|
return {
|
|
@@ -1695,15 +1703,26 @@ function socketAddress(options) {
|
|
|
1695
1703
|
hostPart = trimmed.substring(0, separatorIndex);
|
|
1696
1704
|
portPart = trimmed.substring(separatorIndex + separator.length);
|
|
1697
1705
|
}
|
|
1698
|
-
const
|
|
1699
|
-
if (
|
|
1706
|
+
const hostResult = parseHost(hostPart);
|
|
1707
|
+
if (!hostResult.success) {
|
|
1700
1708
|
const errorMsg = options?.errors?.invalidFormat;
|
|
1701
|
-
|
|
1709
|
+
if (errorMsg) {
|
|
1710
|
+
const msg = typeof errorMsg === "function" ? errorMsg(input) : errorMsg;
|
|
1711
|
+
return {
|
|
1712
|
+
success: false,
|
|
1713
|
+
error: msg
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1716
|
+
if (looksLikeIpv4(hostPart)) return {
|
|
1717
|
+
success: false,
|
|
1718
|
+
error: hostResult.error
|
|
1719
|
+
};
|
|
1702
1720
|
return {
|
|
1703
1721
|
success: false,
|
|
1704
|
-
error:
|
|
1722
|
+
error: require_message.message`Expected a socket address in format host${separator}port, but got ${input}.`
|
|
1705
1723
|
};
|
|
1706
1724
|
}
|
|
1725
|
+
const validatedHost = hostResult.value;
|
|
1707
1726
|
let validatedPort;
|
|
1708
1727
|
if (portPart === void 0 || portPart === "") {
|
|
1709
1728
|
if (requirePort) {
|
package/dist/valueparser.js
CHANGED
|
@@ -1164,6 +1164,14 @@ function ipv4(options) {
|
|
|
1164
1164
|
error: msg
|
|
1165
1165
|
};
|
|
1166
1166
|
}
|
|
1167
|
+
if (!/^[0-9]+$/.test(part)) {
|
|
1168
|
+
const errorMsg = options?.errors?.invalidIpv4;
|
|
1169
|
+
const msg = typeof errorMsg === "function" ? errorMsg(input) : errorMsg ?? message`Expected a valid IPv4 address, but got ${input}.`;
|
|
1170
|
+
return {
|
|
1171
|
+
success: false,
|
|
1172
|
+
error: msg
|
|
1173
|
+
};
|
|
1174
|
+
}
|
|
1167
1175
|
const octet = Number(part);
|
|
1168
1176
|
if (!Number.isInteger(octet) || octet < 0 || octet > 255) {
|
|
1169
1177
|
const errorMsg = options?.errors?.invalidIpv4;
|
|
@@ -1664,20 +1672,20 @@ function socketAddress(options) {
|
|
|
1664
1672
|
metavar: "PORT",
|
|
1665
1673
|
type: "number"
|
|
1666
1674
|
});
|
|
1675
|
+
function looksLikeIpv4(input) {
|
|
1676
|
+
return /^\d+\.\d+\.\d+\.\d+$/.test(input);
|
|
1677
|
+
}
|
|
1667
1678
|
function parseHost(hostInput) {
|
|
1668
1679
|
if (hostType === "hostname") {
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
if (ipResult.success) return ipResult.value;
|
|
1679
|
-
const hostnameResult = hostnameParser.parse(hostInput);
|
|
1680
|
-
return hostnameResult.success ? hostnameResult.value : null;
|
|
1680
|
+
if (looksLikeIpv4(hostInput)) return {
|
|
1681
|
+
success: false,
|
|
1682
|
+
error: message`Expected a valid hostname, but got ${hostInput}.`
|
|
1683
|
+
};
|
|
1684
|
+
return hostnameParser.parse(hostInput);
|
|
1685
|
+
} else if (hostType === "ip") return ipParser.parse(hostInput);
|
|
1686
|
+
else {
|
|
1687
|
+
if (looksLikeIpv4(hostInput)) return ipParser.parse(hostInput);
|
|
1688
|
+
return hostnameParser.parse(hostInput);
|
|
1681
1689
|
}
|
|
1682
1690
|
}
|
|
1683
1691
|
return {
|
|
@@ -1695,15 +1703,26 @@ function socketAddress(options) {
|
|
|
1695
1703
|
hostPart = trimmed.substring(0, separatorIndex);
|
|
1696
1704
|
portPart = trimmed.substring(separatorIndex + separator.length);
|
|
1697
1705
|
}
|
|
1698
|
-
const
|
|
1699
|
-
if (
|
|
1706
|
+
const hostResult = parseHost(hostPart);
|
|
1707
|
+
if (!hostResult.success) {
|
|
1700
1708
|
const errorMsg = options?.errors?.invalidFormat;
|
|
1701
|
-
|
|
1709
|
+
if (errorMsg) {
|
|
1710
|
+
const msg = typeof errorMsg === "function" ? errorMsg(input) : errorMsg;
|
|
1711
|
+
return {
|
|
1712
|
+
success: false,
|
|
1713
|
+
error: msg
|
|
1714
|
+
};
|
|
1715
|
+
}
|
|
1716
|
+
if (looksLikeIpv4(hostPart)) return {
|
|
1717
|
+
success: false,
|
|
1718
|
+
error: hostResult.error
|
|
1719
|
+
};
|
|
1702
1720
|
return {
|
|
1703
1721
|
success: false,
|
|
1704
|
-
error:
|
|
1722
|
+
error: message`Expected a socket address in format host${separator}port, but got ${input}.`
|
|
1705
1723
|
};
|
|
1706
1724
|
}
|
|
1725
|
+
const validatedHost = hostResult.value;
|
|
1707
1726
|
let validatedPort;
|
|
1708
1727
|
if (portPart === void 0 || portPart === "") {
|
|
1709
1728
|
if (requirePort) {
|