Skip to content

php.js is a resource that offers community-built JavaScript alternatives to PHP functions

License

Notifications You must be signed in to change notification settings

CunDeveloper/phpjs

 
 

Repository files navigation

Locutus

Join the chat at https://gitter.im/kvz/locutus Build Status

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

More info at: http://locutusjs.io/about

Install

npm install --save --save-exact locutus

For ease of development, we recommend these global installs:

npm install --global mocha babel-cli

Use

${EDITOR} try.js
var php = require('locutus/php/strings/sprintf')
var effectiveness = 'futile'
php.echo(php.sprintf('Resistance is %s', effectiveness))
var strings = require('locutus/golang/strings')
console.log(strings.Contains('Locutus', 'cut'))
$ node try.js
Resistance is futile
true

Test

npm run test

Single out one function: natsort

TEST_GREP=natsort npm run test:languages

This startes by rewriting the test-cases, which is useful if you're changing the tests themselves as well. If that's not needed as you're iterating purely on the implementation, here's a speedier way of singling out natsort:

env DEBUG=locutus:* mocha \
  --compilers js:babel-register \
  --reporter spec \
test/languages/php/array/test-natsort.js

Website

We keep the website in ./website for so it's easy to keep docs & code in sync. For those reading this screaming murder, HashiCorp does this for all their projects, and it's working pretty well for them on a scale more impressive than ours.

Our website is built with Jekyll.

Here's the flow that takes written functions to the website:

  • npm run website:inject runs src/_util/util.js's injectweb method
  • injectweb iterates over ./functions and uses src/_util/util.js to parse them, most significantly: the header comments that declare authors, tests, and dependencies
  • injectweb then writes each function to website/_functions. This is a Jekyll Collection. The code is written as the content, and all the other properties are added as YAML front matter
  • Jekyll uses website/_layouts/function.html as the layout template for the function collection, this determines how all the properties are rendered.

Blog posts can be found in website/_posts.

At the time of writing, the Jekyll Asset pipeline is in a bad place, and so SASS / ES6 asset transpiling is handled separately via npm scripts. Unfortunately we don't have the theme of the website in SASS, so it's included in app.scss as plain CSS for now. You can find all the transpiling options in website/package.json.

Typing npm run website:deploy in the root of the project takes care of all the building steps above, and then force pushes the generated HTML to the gh-pages branch of this repo.

Todo

  • One way of checking pure Arrays vs PHP arrays (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') { )
  • Track all cases of window, see if they make sense
  • Track all cases of setTimeout, use them without window prefix. Remove codez hack
  • Read up on i18n_loc_set_default and setlocale in php manual, see if new behavior is warrented
  • json_* functions can leverage Node's
  • See if we need to merge sort functions into one helper function and require that. Use arsort as an example
  • Test is_array in-browser to see if the require for ini_get works correctly with browserify
  • Track down all iniRaws and replace them with iniVal
  • Add a default mode to ini_get
  • Use \u for octals in _examples for ES2015 compatibility
  • Rename strictForIn to sortByReference
  • Move functions that overly rely on ini & locales & global & ajax file operations to _legacy
  • Remove XUL from functions
  • ES6
  • Port a few more tricky/interdepending Ruby functions
  • Port a few more tricky/interdepending Python functions
  • Port a few more tricky/interdepending Go functions
  • Add eslint warnings to website function
  • Parse requires with ast like browserify. Then we can add dependencies back to website
  • Compare test cases against php -r
  • Auto-deploys via Travis CI
  • Adopt better global detection, use $locutus.golang.
  • [-] Maybe move module.exports = acos to bottom line, then function signature can stay BC
  • Add more 'social' buttons to website (twitter, github)
  • [-] Instead of index.js (and its Index.js conflicts) add e.g. Math.js indexes
  • [-] Port a few more tricky/interdepending Rust functions
  • [-] Make eslint standard compliant
  • Rework injectweb after structural changes in util.js
  • Remove ; from examples
  • Generate mocha language tests
  • Use require for dependencies
  • In util.opener: First * should point to the requesting/current language
  • Split out the npm module so you could do var sprintf = require('locutus/sprintf')
  • Launch BC breaking blogpost
  • [-] Add live eslinting in browser

Sponsor development

Gittip donate button Flattr donate button PayPal donate button BitCoin donate button

About

php.js is a resource that offers community-built JavaScript alternatives to PHP functions

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 88.5%
  • HTML 7.1%
  • PHP 3.8%
  • CSS 0.5%
  • Ruby 0.1%
  • Shell 0.0%