Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

oro-php-locutus

oropesa1.4kMIT2.1.6TypeScript support: included

Fork of few Locutus functions that have been rewritten in TypeScript.

php-locutus, typescript, serialize, unserialize, htmlspecialchars, md5, utf8Encode, utf8Decode

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' );
// '&amp;lt;a href=&amp;quot;test&amp;quot;&amp;gt;Test&amp;lt;/a&amp;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'

changelog

2.1.6 / 2025-03-08

  • Reset package-lock.json.
  • Enhance tsconfig.json.
  • Enhance package clean and build scripts.
  • Update dev libs:
    • @babel/core from v7.26.0 to v7.26.9.
    • @babel/preset-env from v7.26.0 to v7.26.9.
    • @eslint/js from v9.16.0 to v9.22.0.
    • @trivago/prettier-plugin-sort-imports from v5.2.0 to v5.2.2.
    • eslint from v9.16.0 to v9.22.0.
    • eslint-config-prettier from v9.1.0 to v10.1.1.
    • eslint-plugin-jest from v28.9.0 to v28.11.0.
    • eslint-plugin-prettier from v5.2.1 to v5.2.3.
    • eslint-plugin-unicorn from v56.0.1 to v57.0.0.
    • globals from v15.13.0 to v16.0.0.
    • prettier from v3.4.2 to v3.5.3.
    • tsup from v8.3.5 to v8.4.0.
    • typescript from v5.7.2 to v5.8.2.
    • typescript-eslint from v8.18.0 to v8.26.0.

2.1.5 / 2024-12-13

  • Improve eslint.config.js.
  • Added dev libs:
    • eslint-plugin-jest-dom added v5.5.0.
    • eslint-plugin-prettier added v5.2.1.
  • Update dev libs:
    • @babel/core from v7.25.8 to v7.26.0.
    • @babel/preset-env from v7.25.8 to v7.26.0.
    • @babel/preset-typescript from v7.25.7 to v7.26.0.
    • @eslint/js from v9.12.0 to v9.16.0.
    • @trivago/prettier-plugin-sort-imports from v4.3.0 to v5.2.0.
    • @types/jest from v29.5.13 to v29.5.14.
    • eslint from v9.12.0 to v9.16.0.
    • eslint-plugin-jest from v28.8.3 to v28.9.0.
    • eslint-plugin-unicorn from v56.0.0 to v56.0.1.
    • globals from v15.11.0 to v15.13.0.
    • husky from v9.1.6 to v9.1.7.
    • nodemon from v3.1.7 to v3.1.9.
    • prettier from v3.3.3 to v3.4.2.
    • tsup from v8.3.0 to v8.3.5.
    • typescript from v5.5.4 to v5.7.2.
    • typescript-eslint from v8.8.1 to v8.18.0.

2.1.4 / 2024-10-13

  • Update dev libs:
    • @babel/core from v7.25.2 to v7.25.8.
    • @babel/preset-env from v7.25.4 to v7.25.8.
    • @babel/preset-typescript from v7.24.7 to v7.25.7.
    • @eslint/js from v9.11.0 to v9.12.0.
    • eslint from v9.11.0 to v9.12.0.
    • eslint-plugin-unicorn from v55.0.0 to v56.0.0.
    • globals from v15.9.0 to v15.11.0.
    • typescript-eslint from v8.6.0 to v8.8.1.

2.1.3 / 2024-09-23

  • Update typescript target to ES2020.
  • Update dev libs:
    • @eslint/js from v9.10.0 to v9.11.0.
    • @types/jest from v29.5.12 to v29.5.13.
    • eslint from v9.10.0 to v9.11.0.
    • husky from v9.1.5 to v9.1.6.
    • nodemon from v3.1.4 to v3.1.7.
    • tsup from v8.2.4 to v8.3.0.
    • typescript-eslint from v8.4.0 to v8.6.0.

2.1.2 / 2024-09-08

  • Apply prettier --write in the whole project (with endOfLine: 'lf').
  • Update eslint breakpoint version (v8 to v9).
  • Update dev libs:
    • @babel/core from v7.24.7 to v7.25.2.
    • @babel/preset-env from v7.24.7 to v7.25.4.
    • @eslint/js from v9.6.0 to v9.10.0.
    • eslint from v8.57.0 to v9.10.0.
    • eslint-plugin-jest from v28.6.0 to v28.8.3.
    • eslint-plugin-unicorn from v54.0.0 to v55.0.0.
    • globals from v15.8.0 to v15.9.0.
    • husky from v9.0.11 to v9.1.5.
    • prettier from v3.3.2 to v3.3.3.
    • tsup from v8.1.0 to v8.2.4.
    • typescript from v5.5.3 to v5.5.4.
    • typescript-eslint from v7.16.0 to v8.4.0.

2.1.1 / 2024-07-10

  • Simplified eslint config.
  • Updated dev libs:
    • @babel/core from v7.24.5 to v7.24.7.
    • @babel/preset-env from v7.24.5 to v7.24.7.
    • @babel/preset-typescript from v7.24.1 to v7.24.7.
    • @eslint/js from v9.2.0 to v9.6.0.
    • eslint-plugin-jest from v28.5.0 to v28.6.0.
    • eslint-plugin-unicorn from v53.0.0 to v54.0.0.
    • globals from v15.2.0 to v15.8.0.
    • nodemon from v3.1.0 to v3.1.4.
    • prettier from v3.2.5 to v3.3.2.
    • tsup from v8.0.2 to v8.1.0.
    • typescript from v5.4.5 to v5.5.3.
    • typescript-eslint from v7.9.0 to v7.16.0.

2.1.0 / 2024-05-17

  • Improved github cicd replacing actions/--@v3 by actions/--@v4.
  • Moved tests inside src and simplified *.test.js to have only the special-js cases.
  • Updated eslint to flat eslint.config.js.
  • Simplified tsup.config.ts.
  • Re-init package-lock.json.
  • Updated dev libs:
    • @babel/core from v7.23.7 to v7.24.5.
    • @babel/preset-env from v7.23.8 to v7.24.5.
    • @babel/preset-typescript from v7.23.3 to v7.24.1.
    • @types/jest from v29.5.11 to v29.5.12.
    • eslint from v8.56.0 to v8.57.0.
    • eslint-plugin-jest from v27.6.3 to v28.5.0.
    • eslint-plugin-unicorn from v50.0.1 to v53.0.0.
    • husky from v8.0.3 to v9.0.11.
    • nodemon from v3.0.2 to v3.1.0.
    • prettier from v3.2.1 to v3.2.5.
    • tsup from v8.0.1 to v8.0.2.
    • typescript from v5.3.3 to v5.4.5.
  • Added dev libs:
    • @eslint/js added v9.2.0.
    • globals added v15.2.0.
    • typescript-eslint added v7.9.0.
  • Removed dev libs:
    • @typescript-eslint/eslint-plugin removed.
    • @typescript-eslint/parser removed.
    • eslint-config-alloy removed.

2.0.3 / 2024-01-14

  • Added coverage for testing.
  • Added watcher for coding.
  • Improved github cicd replacing npm install to npm ci.
  • Improved export declarations if index files
  • Enhanced linter adding some extensions.
  • Enhanced prettier adding import-sorter.
  • Enhanced testing to achieve the 95% of coverage (yay!).
  • Added const's:
    • HTMLSPECIALCHARS_ENT_NOQUOTES
    • HTMLSPECIALCHARS_ENT_HTML_QUOTE_SINGLE
    • HTMLSPECIALCHARS_ENT_HTML_QUOTE_DOUBLE
    • HTMLSPECIALCHARS_ENT_COMPAT
    • HTMLSPECIALCHARS_ENT_QUOTES
    • HTMLSPECIALCHARS_ENT_IGNORE
  • Updated dev libs:
    • @babel/core from v7.23.3 to v7.23.7.
    • @babel/preset-env from v7.23.3 to v7.23.7.
    • @types/jest from v29.5.10 to v29.5.11.
    • @typescript-eslint/eslint-plugin from v6.12.0 to v6.18.1.
    • @typescript-eslint/parser from v6.12.0 to v6.18.1.
    • eslint from v8.54.0 to v^8.56.0.
    • eslint-plugin-unicorn from v49.0.0 to v50.0.1.
    • prettier from v3.1.0 to v3.2.1.
    • typescript from v5.2.2 to v5.3.3.
  • Added dev libs:
    • @trivago/prettier-plugin-sort-imports
    • eslint-config-prettier
    • eslint-plugin-jest
    • nodemon

2.0.2 / 2023-10-24

  • Fixed github action npm_publish_on_pr_merge_to_master.
  • Updated dev libs:
    • @babel/core from v7.23.2 to v7.23.3.
    • @babel/preset-env from v7.23.2 to v7.23.3.
    • @babel/preset-typescript from v7.23.2 to v7.23.3.
    • @types/jest from v29.5.6 to v29.5.10.
    • @typescript-eslint/eslint-plugin from v6.9.0 to v6.12.0.
    • @typescript-eslint/parser from v6.9.0 to v6.12.0.
    • eslint from v8.52.0 to v8.54.0.
    • eslint-plugin-unicorn from v48.0.1 to v49.0.0.
    • prettier from v3.0.3 to v3.1.0.
    • tsup from v7.2.0 to v8.0.1.

2.0.1 / 2023-10-24

  • Updated dev libs:
    • @babel/core from v7.23.0 to v7.23.2.
    • @babel/preset-env from v7.22.20 to v7.23.2.
    • @babel/preset-typescript from v7.23.0 to v7.23.2.
    • @types/jest from v29.5.5 to v29.5.6.
    • @typescript-eslint/eslint-plugin from v6.7.4 to v6.9.0.
    • @typescript-eslint/parser from v6.7.4 to v6.9.0.
    • eslint from v8.50.0 to v8.52.0.

2.0.0 / 2023-10-06

  • Refactored *.js to src/*.ts.
  • Updated package as type: "module".
  • Added tsup and now package is compiled to cjs (common) and mjs (module).
  • Added github actions:
    • validate_pr_to_master
    • npm_publish_on_pr_merge_to_master.
  • Added husky (to ensure only valid commits).
  • Added eslint (and applied it).
  • Added prettier (and applied it).
  • Updated package description
  • Updated dev libs:
    • @babel/core to v7.23.0.
    • @babel/preset-env to v7.22.20.
    • @babel/preset-typescript to v7.23.0.
    • @types/jest to v29.5.5.
    • babel-jest to v29.7.0.
    • jest to v29.7.0.

1.3.0 / 2023-05-11

  • Added ts tests.
  • Improved tests.
  • Improved readme.
  • Updated lib-dev jest to v29.5.0.
  • Updated index.d.ts adding export type ENT_OPTION.

1.2.0 / 2023-03-03

  • Added Typescript.
  • Updated lib-dev jest to v29.4.3.

1.1.1 / 2022-08-16

  • Updated php function unserialize.

1.1.0 / 2022-08-02

  • Updated Readme and tests/.
  • Added package-lock.json.
  • Updated lib-dev jest to v28.1.3.

1.0.0 / 2021-08-17

  • Added MIT License.
  • Added package in github.com & npmjs.com.
  • Added unit testing Jest.
  • Removed package crypto, instead of that, it uses nodejs built-in.

0.2.0 / 2021-05-17

  • Added php functions md5, utf8Encode, utf8Decode.
  • Added nodemodule_ crypto (md5 requires it).

0.1.0 / 2021-05-14

  • Added changelog.
  • Added php function htmlspecialchars.

0.0.1 / 2021-03-22

  • Init package.