(ipAddress, options = {})
| 45 | ')(%[0-9a-zA-Z.]{1,})?$'); |
| 46 | |
| 47 | export 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 | } |
no test coverage detected