Install via yarn add locutus and import:
import { intval } from 'locutus/php/var/intval'.
Or with CommonJS: const { intval } = require('locutus/php/var/intval')
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
intval('Kevin van Zonneveld')
0
2
intval(4.2)
4
3
intval(42, 8)
42
4
intval('09')
9
5
intval('1e', 16)
30
6
intval(0x200000001)
8589934593
7
intval('0xff', 0)
255
8
intval('010', 0)
8
Here's what our current TypeScript equivalent to PHP's intval looks like.
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.