Check if a string is an IP address.
Like Node's net.isIP function, but in userland.
npm i -S @substrate-system/is-ip
This exposes ESM and common JS via package.json exports
field.
import { isIP } from '@substrate-system/is-ip'
const isIP = require('@substrate-system/is-ip')
This package exposes minified JS files too. Copy them to a location that is accessible to your web server, then link to them in HTML.
cp ./node_modules/@namespace/package/dist/module.min.js ./public
<script type="module" src="./module.min.js"></script>
Return either 0
, 4
, or 6
depending on the type of IP address.
import { isIP } from '@substrate-system/is-ip'
isIP('::1') // returns 6
isIP('127.0.0.1') // returns 4
isIP('127.000.000.001') // returns 0
isIP('127.0.0.1/24') // returns 0
isIP('fhqwhgads') // returns 0