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

Package detail

locutus

locutusjs1.4mMIT2.0.32TypeScript support: definitely-typed

Locutus other languages' standard libraries to JavaScript for fun and educational purposes

php, golang, c, ruby, python, js, locutus

readme

Locutus

All your standard libraries will be assimilated into our JavaScript collective. Resistance is futile.

Welcome to Locutus, where the boundaries of coding languages blur. We're a dedicated collective developers on a mission to explore the possibilities of porting standard libraries from various programming language (Go, Ruby, PHP, C) to JavaScript. Our journey is one of discovery, innovation, and sometimes, delightful chaos.

From the complex to the quirky, we assimilate libraries with a spirit of curiosity and a penchant for experimentation. Our creations typically start as rainy Sunday afternoon puzzles, and end up ranging from groundbreaking functions that enhance the JavaScript ecosystem, to unique oddities that challenge the norms of coding.

As we navigate through this uncharted territory, we invite you to join us. Whether to contribute, learn, or simply marvel at the wonders of cross-language integration and portability, your presence on GitHub is valued.

Embark on this journey with us at locutus.io.

Use our creations at your own risk, and may they inspire you to push the boundaries of what's possible with JavaScript.

Table of contents

Install

yarn add locutus

Use

$ vim php.js
const sprintf = require('locutus/php/strings/sprintf')
const echo = require('locutus/php/strings/echo')
const effectiveness = 'futile'
echo(sprintf('Resistance is %s', effectiveness))
$ node php.js
Resistance is futile
$ vim go.js
const strings = require('locutus/golang/strings')
console.log(strings.Contains('Locutus', 'cut'))
$ node go.js
true

Development

Some guidelines and instructions can be found in CONTRIBUTING.md

changelog

Changelog

Our combined changelog and roadmap. It contains todos as well as dones.

Only project-wide changes are mentioned here. For individual function changelogs, please refer to their respective Git histories.

Locutus does not follow SemVer as we're a work in progress - and even though we try, we cannot guarantee BC-safety for the hundreds of contributions across the many languages that Locutus is assimilating.

Backlog

Ideas that will be planned and find their way into a release at one point

  • <input disabled="" type="checkbox"> Address the 25 remaining test failures that are currently skipped (find out which ones via
    `yarn test:languages:noskip`)
  • <input disabled="" type="checkbox"> Compare example test cases for PHP against php -r to make sure they are correctly mimicking the most recent
    stable behavior
  • <input disabled="" type="checkbox"> Have one way of checking pure JS arrays vs PHP arrays (vs:
    `Object.prototype.toString.call(arr1) === '[object Array]'`, `typeof retObj[p] === 'object'`,
    `var asString = Object.prototype.toString.call(mixedVar) var asFunc = _getFuncName(mixedVar.constructor) if (asString === '[object Object]' && asFunc === 'Object') {`
    )
  • <input disabled="" type="checkbox"> Investigate if we can have one helper function for intersecting, and use that in all array_*diff* and
    `array_*sort*` functions. Refrain from using `labels`, which those functions currently still rely on
  • <input disabled="" type="checkbox"> Investigate if we can have one helper function for sorting, and use that in all *sort* functions
  • <input disabled="" type="checkbox"> Investigate if we can have one helper function to resolve
    `Function/'function'/'Class::function'/[$object, 'function']`, and use that in `is_callable`, `array_walk`,
    `call_user_func_array` etc.
  • <input disabled="" type="checkbox"> Parse requires with AST just like Browserify does. Then we can add dependencies back to website
  • <input disabled="" type="checkbox"> Port a few more tricky/inter-depending Go functions
  • <input disabled="" type="checkbox"> Port a few more tricky/inter-depending Python functions
  • <input disabled="" type="checkbox"> Port a few more tricky/inter-depending Ruby functions
  • <input disabled="" type="checkbox"> website: Render authors server-side
  • <input disabled="" type="checkbox"> website: Fix the search functionality

main

Released: TBA. Diff.

  • [ ]

v2.0.32

Released: 2024-04-05. Diff.

  • <input checked="" disabled="" type="checkbox"> Update intro and add to the NPM module as a README.md

v2.0.31

Released: 2024-04-05. Diff.

  • <input checked="" disabled="" type="checkbox"> dx: Add use strict to generated tests
  • <input checked="" disabled="" type="checkbox"> dx: Add Stale Action
  • <input checked="" disabled="" type="checkbox"> file_exists: Introduced (in #461, thx @erikn69)
  • <input checked="" disabled="" type="checkbox"> strtotime: Add support oracle dates (fixes #340)
  • <input checked="" disabled="" type="checkbox"> bin2hex: Add support for multi-byte characters (fixes #427)
  • <input checked="" disabled="" type="checkbox"> var_dump: Detect circular references (fixes #305)
  • <input checked="" disabled="" type="checkbox"> escapeshellarg: Add Windows support (fixes #395)
  • <input checked="" disabled="" type="checkbox"> fmod: Fix Uncaught RangeError: toFixed() digits argument must be between 0 and 100 (thx @dekairi, fixes #417)

v2.0.30

Released: 2024-04-05. Diff.

  • <input checked="" disabled="" type="checkbox"> Relax yarn engine requirement (fixes #467)
  • <input checked="" disabled="" type="checkbox"> Allow for custom mocha tests for functions (that arent generated based on header comments)

v2.0.29

Released: 2024-04-04. Diff.

  • <input checked="" disabled="" type="checkbox"> Fix issue #458: unserialize fails when serialized array contains (@kukawski)
  • <input checked="" disabled="" type="checkbox"> dx: Switch from master -> main branch
  • <input checked="" disabled="" type="checkbox"> dx: Upgrade to Yarn 4 managed by Corepack
  • <input checked="" disabled="" type="checkbox"> dx: Add testing for Node 20
  • <input checked="" disabled="" type="checkbox"> dx: Add prettier & upgrade ESLint & StandardJS
  • <input checked="" disabled="" type="checkbox"> dx: Upgrade Hexo to latest
  • <input checked="" disabled="" type="checkbox"> dx: Clarify contributing docs
  • <input checked="" disabled="" type="checkbox"> dx: Allow all core contributors to cut NPM releases by pushing Git tags (GHA CI handles the rest)
  • <input checked="" disabled="" type="checkbox"> dx: Upgrade all remaining dependencies

v2.0.16

Released: 2019-06-12. Diff.

  • <input checked="" disabled="" type="checkbox"> Switch from Travis CI to GitHub Actions
  • <input checked="" disabled="" type="checkbox"> Fix ReDOS on IPv6
  • <input checked="" disabled="" type="checkbox"> Basic timezone support in strtotime

v2.0.11

Released: 2019-06-12. Diff.

  • <input checked="" disabled="" type="checkbox"> functions: Community-contributed function improvements, see respective functions' changelogs in the Diff:
  • <input checked="" disabled="" type="checkbox"> ci: test Node.js 6, 8, 10 and 11 (#384)
  • <input checked="" disabled="" type="checkbox"> website: Fix code listing on locutus website (#379)

v2.0.10

Released: 2018-09-07. Diff.

  • <input checked="" disabled="" type="checkbox"> functions: Community-contributed function improvements, see respective functions' changelogs in the Diff.

v2.0.9

Released: 2017-06-22. Diff.

  • <input checked="" disabled="" type="checkbox"> functions: Community-contributed function improvements, see respective functions' changelogs in the Diff.

v2.0.8

Released: 2017-02-23. Diff.

  • <input checked="" disabled="" type="checkbox"> Upgrade eslint and fix newly found issues accordingly
  • <input checked="" disabled="" type="checkbox"> functions: Community-contributed function improvements, see respective functions' changelogs in the Diff.

v2.0.7

Released: 2017-02-09. Diff.

  • <input checked="" disabled="" type="checkbox"> functions: Community-contributed function improvements, see respective functions' changelogs in the Diff.

v2.0.6

Released: 2016-06-16. Diff.

  • <input checked="" disabled="" type="checkbox"> Language fixes

v2.0.5

Released: 2016-06-16. Diff.

  • <input checked="" disabled="" type="checkbox"> Cache node modules on Travis so we'll be less dependent on npm connectivity

v2.0.4

Released: 2016-05-25. Diff.

  • <input checked="" disabled="" type="checkbox"> Upgrade depurar to 0.2.2, fixing an issue with the testwriter (@kukawski)
  • <input checked="" disabled="" type="checkbox"> Add the 'reimplemented by' and 'parts by' contributionKeys to the /authors website page
  • <input checked="" disabled="" type="checkbox"> Fix linting warnings when hacking on website by adding eslint dependencies locally
  • <input checked="" disabled="" type="checkbox"> Improve array_rand: Fix coding style, hangs when selected huge number of keys from huge array, function signature
    (@kukawski)

v2.0.3

Released: 2016-05-22. Diff.

  • <input checked="" disabled="" type="checkbox"> Minor util.js refactoring
  • <input checked="" disabled="" type="checkbox"> Use hexo deploy instead of custom bash script to aid Windows compatibility
  • <input checked="" disabled="" type="checkbox"> Use cross-env and rimraf in build scripts to aid Windows compatibility
  • <input checked="" disabled="" type="checkbox"> Improve Travis auto-deployments (now using official deploy methods)
  • <input checked="" disabled="" type="checkbox"> Switch from locutusjs.io to locutus.io
  • <input checked="" disabled="" type="checkbox"> Triage all open issues and PRs
  • <input checked="" disabled="" type="checkbox"> Triage all open issues and PRs
  • <input checked="" disabled="" type="checkbox"> docs: Miscellaneous cosmetic updates
  • <input checked="" disabled="" type="checkbox"> website: Miscellaneous cosmetic updates
  • <input checked="" disabled="" type="checkbox"> website: Show languages & functions in profile sidebar
  • <input checked="" disabled="" type="checkbox"> website: Add social buttons
  • <input checked="" disabled="" type="checkbox"> website: Let Travis auto-deploy to gh-pages on main changes
  • <input checked="" disabled="" type="checkbox"> website: Use Hexo deploy vs bash script

v2.0.2

Released: 2016-05-02. Diff.

  • <input checked="" disabled="" type="checkbox"> Don't use files in package.json as we don't ship all of dist now

v2.0.1

Released: 2016-05-02. Diff.

  • <input checked="" disabled="" type="checkbox"> Don't use bin in package.json as we don't ship cli.js

v2.0.0

Released: 2016-05-02. Diff.

  • <input checked="" disabled="" type="checkbox"> website: Add profile to sidebar
  • <input checked="" disabled="" type="checkbox"> Rename _locutus_shared to _helpers. Rename _locutus_shared_bc to _bc
  • <input checked="" disabled="" type="checkbox"> website: Fix jumpy scrolling due to on the githubs
  • <input checked="" disabled="" type="checkbox"> website: DRY up add_more code
  • <input checked="" disabled="" type="checkbox"> website: About as homepage
  • <input checked="" disabled="" type="checkbox"> Transpile to ES5 before publishing to npm
  • <input checked="" disabled="" type="checkbox"> Add estarget option to all functions, set ip2long to es2015
  • <input checked="" disabled="" type="checkbox"> Change fix(me)? and Todo to @todo
  • <input checked="" disabled="" type="checkbox"> Replace single line /**/ comments with //
  • <input checked="" disabled="" type="checkbox"> Enforce a 100 character line-length via eslint, and change all functions accordingly
  • <input checked="" disabled="" type="checkbox"> Do not pass values by reference via the window global, use e.g. countObj.value and errorObj.value instead
  • <input checked="" disabled="" type="checkbox"> Have one way of getting an ini value and its default
  • <input checked="" disabled="" type="checkbox"> Track all cases of setTimeout, use them without window prefix. Remove codez replace hack
  • <input checked="" disabled="" type="checkbox"> Track all cases of XMLHttpRequest
  • <input checked="" disabled="" type="checkbox"> Test is_array in-browser to see if the require for ini_get works correctly with Browserify
  • <input checked="" disabled="" type="checkbox"> Deprecate blocking ajax requests in e.g. file_get_contents
  • <input checked="" disabled="" type="checkbox"> Use native sha1 and md5 encoding when available
  • <input checked="" disabled="" type="checkbox"> Remove XUL from functions
  • <input checked="" disabled="" type="checkbox"> Rename strictForIn to sortByReference
  • <input checked="" disabled="" type="checkbox"> Remove // (BEGIN|END) (STATIC|REDUNDANT)
  • <input checked="" disabled="" type="checkbox"> Index all notes
  • <input checked="" disabled="" type="checkbox"> Either deprecate or document all functions using eval or new Function
  • <input checked="" disabled="" type="checkbox"> Port Util to ES6 class
  • <input checked="" disabled="" type="checkbox"> Write one function (ip2long) in ES6 and make it pass tests & linting
  • <input checked="" disabled="" type="checkbox"> Deprecate support for node_js: 0.8
  • <input checked="" disabled="" type="checkbox"> Make Travis fail on eslint issues
  • <input checked="" disabled="" type="checkbox"> Move CHANGELOG to own file
  • <input checked="" disabled="" type="checkbox"> Make all functions pass eslint with JavaScript Standard Style
  • <input checked="" disabled="" type="checkbox"> Remove _workbench and _experimental. They are available for reference in 1.3.2 but making them harder to
    find for newcomers should help avoid a lot of complaints
  • <input checked="" disabled="" type="checkbox"> Move functions that overly rely on ini & locales & global & ajax file operations to _legacy
  • <input checked="" disabled="" type="checkbox"> Address ~50 test failures that were previously skipped and now enabled
  • <input checked="" disabled="" type="checkbox"> json_* functions can leverage Node's
  • <input checked="" disabled="" type="checkbox"> Add ES6 capabilities
  • <input checked="" disabled="" type="checkbox"> Adopt better global detection, use $locutus.golang.<specifics>
  • <input checked="" disabled="" type="checkbox"> Add more 'social' buttons to website (twitter, github)
  • <input checked="" disabled="" type="checkbox"> Rework injectweb after structural changes in util.js
  • <input checked="" disabled="" type="checkbox"> Use require for dependencies
  • <input checked="" disabled="" type="checkbox"> Remove ; from examples in accordance with JavaScript Standard Style
  • <input checked="" disabled="" type="checkbox"> Use mocha for generating language tests
  • <input checked="" disabled="" type="checkbox"> Use require for dependencies
  • <input checked="" disabled="" type="checkbox"> In util.opener: First * should point to the requesting/current language
  • <input checked="" disabled="" type="checkbox"> Split out the npm module so you could do var sprintf = require('locutus/sprintf')
  • <input checked="" disabled="" type="checkbox"> Launch BC breaking blogpost
  • <input checked="" disabled="" type="checkbox"> Roll out support for Ruby, C, Go, Python

v1.3.2

Released: April 4, 2016