summaryrefslogtreecommitdiff
path: root/bin/wiki/ImportarDesdeURL/node_modules/tldts-core/dist/es6/src/is-ip.js
diff options
context:
space:
mode:
Diffstat (limited to 'bin/wiki/ImportarDesdeURL/node_modules/tldts-core/dist/es6/src/is-ip.js')
-rw-r--r--bin/wiki/ImportarDesdeURL/node_modules/tldts-core/dist/es6/src/is-ip.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/bin/wiki/ImportarDesdeURL/node_modules/tldts-core/dist/es6/src/is-ip.js b/bin/wiki/ImportarDesdeURL/node_modules/tldts-core/dist/es6/src/is-ip.js
new file mode 100644
index 00000000..aa82fbb6
--- /dev/null
+++ b/bin/wiki/ImportarDesdeURL/node_modules/tldts-core/dist/es6/src/is-ip.js
@@ -0,0 +1,60 @@
+/**
+ * Check if a hostname is an IP. You should be aware that this only works
+ * because `hostname` is already garanteed to be a valid hostname!
+ */
+function isProbablyIpv4(hostname) {
+ // Cannot be shorted than 1.1.1.1
+ if (hostname.length < 7) {
+ return false;
+ }
+ // Cannot be longer than: 255.255.255.255
+ if (hostname.length > 15) {
+ return false;
+ }
+ var numberOfDots = 0;
+ for (var i = 0; i < hostname.length; i += 1) {
+ var code = hostname.charCodeAt(i);
+ if (code === 46 /* '.' */) {
+ numberOfDots += 1;
+ }
+ else if (code < 48 /* '0' */ || code > 57 /* '9' */) {
+ return false;
+ }
+ }
+ return (numberOfDots === 3 &&
+ hostname.charCodeAt(0) !== 46 /* '.' */ &&
+ hostname.charCodeAt(hostname.length - 1) !== 46 /* '.' */);
+}
+/**
+ * Similar to isProbablyIpv4.
+ */
+function isProbablyIpv6(hostname) {
+ // We only consider the maximum size of a normal IPV6. Note that this will
+ // fail on so-called "IPv4 mapped IPv6 addresses" but this is a corner-case
+ // and a proper validation library should be used for these.
+ if (hostname.length > 39) {
+ return false;
+ }
+ var hasColon = false;
+ for (var i = 0; i < hostname.length; i += 1) {
+ var code = hostname.charCodeAt(i);
+ if (code === 58 /* ':' */) {
+ hasColon = true;
+ }
+ else if (((code >= 48 && code <= 57) || // 0-9
+ (code >= 97 && code <= 102)) === false // a-f
+ ) {
+ return false;
+ }
+ }
+ return hasColon;
+}
+/**
+ * Check if `hostname` is *probably* a valid ip addr (either ipv6 or ipv4).
+ * This *will not* work on any string. We need `hostname` to be a valid
+ * hostname.
+ */
+export default function isIp(hostname) {
+ return isProbablyIpv6(hostname) || isProbablyIpv4(hostname);
+}
+//# sourceMappingURL=is-ip.js.map \ No newline at end of file