Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

is-ip

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

is-ip - npm Package Compare versions

Comparing version 3.1.0 to 4.0.0

96

index.d.ts

@@ -1,64 +0,60 @@

declare const isIp: {
/**
Check if `string` is IPv4 or IPv6.
/**
Check if `string` is IPv6 or IPv4.
@example
```
import isIp = require('is-ip');
@example
```
import {isIP} from 'is-ip';
isIp('192.168.0.1');
//=> true
isIP('1:2:3:4:5:6:7:8');
//=> true
isIp('1:2:3:4:5:6:7:8');
//=> true
```
*/
(string: string): boolean;
isIP('192.168.0.1');
//=> true
```
*/
export function isIP(string: string): boolean; // eslint-disable-line @typescript-eslint/naming-convention
/**
Check if `string` is IPv4.
/**
Check if `string` is IPv6.
@example
```
import isIp = require('is-ip');
@example
```
import {isIPv6} from 'is-ip';
isIp.v4('192.168.0.1');
//=> true
```
*/
v4(string: string): boolean;
isIPv6('1:2:3:4:5:6:7:8');
//=> true
```
*/
export function isIPv6(string: string): boolean; // eslint-disable-line @typescript-eslint/naming-convention
/**
Check if `string` is IPv6.
/**
Check if `string` is IPv4.
@example
```
import isIp = require('is-ip');
@example
```
import {isIPv4} from 'is-ip';
isIp.v6('1:2:3:4:5:6:7:8');
//=> true
```
*/
v6(string: string): boolean;
isIPv4('192.168.0.1');
//=> true
```
*/
export function isIPv4(string: string): boolean; // eslint-disable-line @typescript-eslint/naming-convention
/**
@returns `6` if `string` is IPv6, `4` if `string` is IPv4, or `undefined` if `string` is neither.
/**
@returns `6` if `string` is IPv6, `4` if `string` is IPv4, or `undefined` if `string` is neither.
@example
```
import isIp = require('is-ip');
@example
```
import {ipVersion} from 'is-ip';
isIp.version('192.168.0.1');
//=> 4
ipVersion('1:2:3:4:5:6:7:8');
//=> 6
isIp.version('1:2:3:4:5:6:7:8');
//=> 6
ipVersion('192.168.0.1');
//=> 4
isIp.version('abc');
//=> undefined
```
*/
version(string: string): 4 | 6 | undefined;
};
export = isIp;
ipVersion('abc');
//=> undefined
```
*/
export function ipVersion(string: string): 6 | 4 | undefined;

@@ -1,9 +0,17 @@

'use strict';
const ipRegex = require('ip-regex');
import ipRegex from 'ip-regex';
const isIp = string => ipRegex({exact: true}).test(string);
isIp.v4 = string => ipRegex.v4({exact: true}).test(string);
isIp.v6 = string => ipRegex.v6({exact: true}).test(string);
isIp.version = string => isIp(string) ? (isIp.v4(string) ? 4 : 6) : undefined;
export function isIP(string) {
return ipRegex({exact: true}).test(string);
}
module.exports = isIp;
export function isIPv6(string) {
return ipRegex.v6({exact: true}).test(string);
}
export function isIPv4(string) {
return ipRegex.v4({exact: true}).test(string);
}
export function ipVersion(string) {
return isIP(string) ? (isIPv6(string) ? 6 : 4) : undefined;
}
{
"name": "is-ip",
"version": "3.1.0",
"version": "4.0.0",
"description": "Check if a string is an IP address",
"license": "MIT",
"repository": "sindresorhus/is-ip",
"funding": "https://github.com/sponsors/sindresorhus",
"author": {

@@ -12,4 +13,6 @@ "name": "Sindre Sorhus",

},
"type": "module",
"exports": "./index.js",
"engines": {
"node": ">=8"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},

@@ -44,9 +47,9 @@ "scripts": {

"dependencies": {
"ip-regex": "^4.0.0"
"ip-regex": "^5.0.0"
},
"devDependencies": {
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
"ava": "^3.15.0",
"tsd": "^0.19.1",
"xo": "^0.47.0"
}
}

@@ -1,44 +0,43 @@

# is-ip [![Build Status](https://travis-ci.org/sindresorhus/is-ip.svg?branch=master)](https://travis-ci.org/sindresorhus/is-ip)
# is-ip
> Check if a string is an IP address
If you only need this for Node.js and don't care about browser support, you may want to use [`net.isIP`](https://nodejs.org/api/net.html#net_net_isip_input) instead. Note that it returns an integer instead of a boolean.
## Install
```sh
npm install is-ip
```
$ npm install is-ip
```
## Usage
```js
const isIp = require('is-ip');
import {isIP, isIPv4} from 'is-ip';
isIp('192.168.0.1');
isIP('1:2:3:4:5:6:7:8');
//=> true
isIp('1:2:3:4:5:6:7:8');
isIP('192.168.0.1');
//=> true
isIp.v4('1:2:3:4:5:6:7:8');
isIPv4('1:2:3:4:5:6:7:8');
//=> false
```
## API
### isIp(string)
### isIP(string)
Check if `string` is IPv4 or IPv6.
Check if `string` is IPv6 or IPv4.
### isIp.v4(string)
### isIPv6(string)
Check if `string` is IPv4.
Check if `string` is IPv6.
### isIp.v6(string)
### isIPv4(string)
Check if `string` is IPv6.
Check if `string` is IPv4.
### isIp.version(string)
### ipVersion(string)

@@ -48,13 +47,14 @@ Returns `6` if `string` is IPv6, `4` if `string` is IPv4, or `undefined` if `string` is neither.

```js
isIp.version('192.168.0.1');
//=> 4
import {ipVersion} from 'is-ip';
isIp.version('1:2:3:4:5:6:7:8');
ipVersion('1:2:3:4:5:6:7:8');
//=> 6
isIp.version('abc');
ipVersion('192.168.0.1');
//=> 4
ipVersion('abc');
//=> undefined
```
## Related

@@ -65,6 +65,1 @@

- [cidr-regex](https://github.com/silverwind/cidr-regex) - Regular expression for matching IP addresses in CIDR notation
## License
MIT © [Sindre Sorhus](https://sindresorhus.com)

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc