oro-php-locutus
v2.1.4
Published
Fork of few Locutus functions that have been rewritten in TypeScript.
Downloads
4,362
Maintainers
Readme
Oro Php Locutus
Overview
Locutus is a project that seeks to assimilate other languages’ standard libraries to JavaScript.
Locutus is a huge library created by a community effort, so instead of downloading all their code, this is just a piece of it.
This package is a fork of few Locutus functions that have been rewritten in TypeScript.
These functions have no dependencies and are browser friendly.
Installation
npm install oro-php-locutus
Methods
serialize()
serialize( mixedValue: any ): string
Here's what Locutus JavaScript equivalent to PHP's serialize looks like.
// cjs
const { serialize } = require( 'oro-php-locutus' );
// mjs, ts
import { serialize } from 'oro-php-locutus';
serialize( { chacho: true, tio: 17 } );
// 'a:2:{s:6:"chacho";b:1;s:3:"tio";i:17;}'
serialize( [ 'chacho', '', true, false, 1, 2.3 ] );
// 'a:6:{i:0;s:6:"chacho";i:1;s:0:"";i:2;b:1;i:3;b:0;i:4;i:1;i:5;d:2.3;}'
unserialize()
unserialize( str: string ): string
Here's what Locutus JavaScript equivalent to PHP's unserialize looks like.
// cjs
const { unserialize } = require( 'oro-php-locutus' );
// mjs, ts
import { unserialize } from 'oro-php-locutus';
unserialize( 'a:2:{s:6:"chacho";b:1;s:3:"tio";i:17;}' );
// { chacho: true, tio: 17 }
unserialize( 'a:6:{i:0;s:6:"chacho";i:1;s:0:"";i:2;b:1;i:3;b:0;i:4;i:1;i:5;d:2.3;}' );
// [ 'chacho', '', true, false, 1, 2.3 ]
htmlspecialchars()
htmlspecialchars(
string: string,
quoteStyle?: ENT_OPTION | ENT_OPTION[],
charset?: null,
doubleEncode?: boolean
): string
type ENT_OPTION =
| 0 | 'ENT_NOQUOTES'
| 1 | 'ENT_HTML_QUOTE_SINGLE'
| 2 | 'ENT_HTML_QUOTE_DOUBLE'
| 'ENT_COMPAT'
| 3 | 'ENT_QUOTES'
| 4 | 'ENT_IGNORE'
Here's what Locutus JavaScript equivalent to PHP's unserialize looks like.
// js
const { htmlspecialchars } = require( 'oro-php-locutus' );
// ts
import { htmlspecialchars } from 'oro-php-locutus';
htmlspecialchars( '<a href="test">Test</a>', 'ENT_QUOTES' );
// '&lt;a href=&quot;test&quot;&gt;Test&lt;/a&gt;'
utf8Encode()
utf8Encode( str: string ): string
Here's what Locutus JavaScript equivalent to PHP's unserialize looks like.
// cjs
const { utf8Encode } = require( 'oro-php-locutus' );
// mjs, ts
import { utf8Encode } from 'oro-php-locutus';
utf8Encode( 'Chacho' );
// 'Chacho'
utf8Encode( 'cañón' );
// 'cañón'
utf8Decode()
utf8Decode( str: string ): string
Here's what Locutus JavaScript equivalent to PHP's unserialize looks like.
// cjs
const { utf8Decode } = require( 'oro-php-locutus' );
// mjs, ts
import { utf8Decode } from 'oro-php-locutus';
utf8Decode( 'Chacho' );
// 'Chacho'
utf8Decode( 'cañón' );
// 'cañón'
md5()
md5( str: string ): string
Here's what Locutus JavaScript equivalent to PHP's unserialize looks like.
// cjs
const { md5 } = require( 'oro-php-locutus' );
// mjs, ts
import { md5 } from 'oro-php-locutus';
md5( 'chacho' );
// '496c84fb22e82d68fad9e5fe8e89d03d'