MCPcopy
hub / github.com/validatorjs/validator.js / isIP

Function isIP

src/lib/isIP.js:47–67  ·  view source on GitHub ↗
(ipAddress, options = {})

Source from the content-addressed store, hash-verified

45 ')(%[0-9a-zA-Z.]{1,})?$');
46
47export default function isIP(ipAddress, options = {}) {
48 assertString(ipAddress);
49
50 // accessing 'arguments' for backwards compatibility: isIP(ipAddress [, version])
51 // eslint-disable-next-line prefer-rest-params
52 const version = (typeof options === 'object' ? options.version : arguments[1]) || '';
53
54 if (!version) {
55 return isIP(ipAddress, { version: 4 }) || isIP(ipAddress, { version: 6 });
56 }
57
58 if (version.toString() === '4') {
59 return IPv4AddressRegExp.test(ipAddress);
60 }
61
62 if (version.toString() === '6') {
63 return IPv6AddressRegExp.test(ipAddress);
64 }
65
66 return false;
67}

Callers 3

isIPRangeFunction · 0.85
isEmailFunction · 0.85
isURLFunction · 0.85

Calls 1

assertStringFunction · 0.85

Tested by

no test coverage detected