Skip to content
php.js is a resource that offers community-built JavaScript alternatives to PHP functions
JavaScript HTML PHP CSS Ruby Shell
Latest commit c57a814 Apr 20, 2016 @kvz BC

README.md

php.js

Join the chat at https://gitter.im/kvz/phpjs Build Status NPM version Dependency Status Development Dependency Status

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

More info at: http://phpjs.org/about

module

$ mkdir test && cd $_
$ npm install phpjs
$ $EDITOR try.js
var php = require('phpjs');

php.echo(php.sprintf('Hey, %s : )', 'you'));
php.echo(php.parse_url('mysql://kevin:abcd1234@example.com/databasename')['pass']);
php.echo(php.strtotime('2 januari 2012, 11:12:13 GMT'));
$ node try.js
Hey, you : )
abcd1234
1325502733

Testing

cli

make test
node bin/phpjs.js --action test --name sort
node bin/phpjs.js --action test --category array

Web

PORT=8080 node test/browser/server.js

Point your webbrowser to http://localhost:8080

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 lib/cli.js's injectweb method
  • injectweb iterates over ./functions and uses lib/phpjsutil.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

  • Split out the npm module so you could do var sprintf = require('phpjs/sprintf')
  • Auto-deploys via Travis CI

Sponsor development

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

Something went wrong with that request. Please try again.