Coder Social home page Coder Social logo

is-ip's Introduction

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 instead. Note that it returns an integer instead of a boolean.

Install

npm install is-ip

Usage

import {isIP, isIPv4} from 'is-ip';

isIP('1:2:3:4:5:6:7:8');
//=> true

isIP('192.168.0.1');
//=> true

isIPv4('1:2:3:4:5:6:7:8');
//=> false

API

isIP(string)

Check if string is IPv6 or IPv4.

isIPv6(string)

Check if string is IPv6.

isIPv4(string)

Check if string is IPv4.

ipVersion(string)

Returns 6 if string is IPv6, 4 if string is IPv4, or undefined if string is neither.

import {ipVersion} from 'is-ip';

ipVersion('1:2:3:4:5:6:7:8');
//=> 6

ipVersion('192.168.0.1');
//=> 4

ipVersion('abc');
//=> undefined

Related

  • ip-regex - Regular expression for matching IP addresses
  • is-cidr - Check if a string is an IP address in CIDR notation
  • cidr-regex - Regular expression for matching IP addresses in CIDR notation

is-ip's People

Contributors

bendingbender avatar richienb avatar silverwind avatar sindresorhus avatar stroncium avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

is-ip's Issues

Getting warning: "Package is-ip has been ignored"

I'm getting this warning when building my React Native app:

warn Package is-ip has been ignored because it contains invalid configuration. Reason: Package subpath './package.json' is not defined by "exports" in /Users/jay/app/node_modules/is-ip/package.json

I'm using is-ip@^4.0.0

Causes PhantomJS tests to fail

While the code works as expected, it caused our PhantomJS tests to fail with the following error:

PhantomJS 2.1.1 (Mac OS X 0.0.0) ERROR
  SyntaxError: Unexpected token 'const'

node v10.21.0 (npm v6.14.8) on Mac 10.15.6

IPv4 check not works correctly

Hi everyone,
I'm facing the following issue while using your library.

isIPv4('123.123.123.');  // --> false | OK because I expect false
isIPv4('123.123.123.1');  // --> true | OK because I expect true
isIPv4('123.123.123.12');  // --> true | OK because I expect true
isIPv4('123.123.123.123');  // --> true | OK because I expect true
isIPv4('123.123.123.1234');  // --> true | NOT OK because I expect false and I get true
isIPv4('123.123.123.12345');  // --> true | NOT OK because I expect false and I get true

I'm using the 5.0.0 version and I'm using Typescript.

Return numbers on versionless check

Issuehunt badges

net.isIP and is-cidr both return numbers 4, 6 or 0 on the versionless check and it makes the API a bit more elegant to use if the user needs the IP version because instead of two function calls, they can do one.

I think it would be good if is-ip would do this too, in a semver-major release of course, even thought it will be compatible with simple boolean checks like if (isIP(ip)).

stroncium earned $40.00 by resolving this issue!

Jest encountered an unexpected token.

I am trying to use this with React. Code works fine but Jest doesn't like it. Any help would be appreciated.

`Test suite failed to run

Jest encountered an unexpected token

Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax.

Out of the box Jest supports Babel, which will be used to transform your files into valid JS based on your Babel configuration.

By default "node_modules" folder is ignored by transformers.

Here's what you can do:
 • If you are trying to use ECMAScript Modules, see https://jestjs.io/docs/ecmascript-modules for how to enable it.
 • If you are trying to use TypeScript, see https://jestjs.io/docs/getting-started#using-typescript
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/configuration
For information about custom transformations, see:
https://jestjs.io/docs/code-transformation

`

is ipV6 false for Localhost

Hi,
I noticed that isIp.v6() returns false for ::1 (ipV6 localhost), should I open the issue here or on the ip-regex package ?
Thanks :)

Cannot utilize require, only import.

It would be nice if the package supported the older require() standard as well as the newer import().

Caught exception:  Error [ERR_REQUIRE_ESM]: require() of ES Module {...}/node_modules/is-ip/index.js from {...}/src/apiv1.js not supported.
Instead change the require of index.js in {...}/src/apiv1.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/{...}/src/apiv1.js:15:14)
    at Object.<anonymous> (/{...}/index.js:48:19) {
  code: 'ERR_REQUIRE_ESM'

Current workaround for anyone with issues is to force release to 3.1.0.

is IPv6 not work as expected

Hi.
Function return true for:
isIp.v6('2a00:1450:4010:c0b::5f:8080')

Even for:
isIp.v6('2a00:1450:4010:c0b::5f:8080:5555')

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.