Install via yarn add locutus and import:
import { ip2long } from 'locutus/php/network/ip2long'.
Or with CommonJS: const { ip2long } = require('locutus/php/network/ip2long')
Use a bundler that supports tree-shaking so you only ship the functions you actually use.
Vite,
webpack,
Rollup, and
Parcel
all handle this. For server-side use this is less of a concern.
Examples
These examples are extracted from test cases that automatically verify our functions against their native counterparts.
#
code
expected result
1
ip2long('192.0.34.166')
3221234342
2
ip2long('0.0xABCDEF')
11259375
3
ip2long('255.255.255.256')
false
Here's what our current TypeScript equivalent to PHP's ip2long looks like.
exportfunctionip2long(argIP: string): number | false { // discuss at: https://locutus.io/php/ip2long/ // original by: Waldo Malqui Silva (https://waldo.malqui.info) // improved by: Victor // revised by: fearphage (https://my.opera.com/fearphage/) // revised by: Theriault (https://github.com/Theriault) // estarget: es2015 // example 1: ip2long('192.0.34.166') // returns 1: 3221234342 // example 2: ip2long('0.0xABCDEF') // returns 2: 11259375 // example 3: ip2long('255.255.255.256') // returns 3: false
// PHP allows decimal, octal, and hexadecimal IP components. // PHP allows between 1 (e.g. 127) to 4 (e.g 127.0.0.1) components.
Locutus is a community effort following
The McDonald's Theory:
we ship first iterations, hoping others will improve them.
If you see something that could be better, we'd love your contribution.