Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: node_js
node_js:
- "0.8"
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq php5-cli
script: make test
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ setup:
cd .. ; \

test:
cd _tests && npm install
find functions -type f |grep -v '/_' |xargs node _tests/cli.js -f
#node tests/cli.js --debug --abort # To abort at first failure
cd tests && npm install
node tests/cli.js --debug

site:
git pull && \
Expand Down
File renamed without changes.
12 changes: 0 additions & 12 deletions experimental/filesystem/dirname.js

This file was deleted.

134 changes: 0 additions & 134 deletions experimental/filesystem/pathinfo.js

This file was deleted.

14 changes: 8 additions & 6 deletions experimental/filesystem/realpath.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
function realpath (path) {
// http://kevin.vanzonneveld.net
// From: http://phpjs.org/functions
// + original by: mk.keck
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// % note 1: Returned path is an url like e.g. 'http://yourhost.tld/path/'
// * example 1: realpath('../.././_supporters/pj_test_supportfile_1.htm');
// * returns 1: 'file:/home/kevin/workspace/_supporters/pj_test_supportfile_1.htm'
var p = 0,
arr = []; /* Save the root, if not given */

var p = 0;
var arr = []; /* Save the root, if not given */
var r = this.window.location.href; /* Avoid input failures */
path = (path + '').replace('\\', '/'); /* Check if there's a port in path (like 'http://') */
if (path.indexOf('://') !== -1) {
Expand All @@ -22,20 +23,21 @@ function realpath (path) {
continue;
} /* This reduces the realpath */
if (arr[k] == '..') {
/* But only if there more than 3 parts in the path-array.
/* But only if there more than 3 parts in the path-array.
* The first three parts are for the uri */
if (path.length > 3) {
path.pop();
}
} /* This adds parts to the realpath */
else {
/* But only if the part is not empty or the uri
/* But only if the part is not empty or the uri
* (the first three parts ar needed) was not
* saved */
if ((path.length < 2) || (arr[k] !== '')) {
path.push(arr[k]);
}
}
} /* Returns the absloute path as a string */
} /* Returns the absolute path as a string */

return path.join('/');
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ function register_shutdown_function (cb) {
// + original by: Brett Zamir (http://brett-zamir.me)
// * example 1: register_shutdown_function(function(first, middle, last) {alert('Goodbye '+first+' '+middle+' '+last+'!');}, 'Kevin', 'van', 'Zonneveld');
// * returns 1: 'Goodbye Kevin van Zonneveld!'

var args = [],
_addEvent = function (el, type, handler, capturing) {
if (el.addEventListener) { /* W3C */
Expand Down
4 changes: 2 additions & 2 deletions functions/info/assert.js → experimental/info/assert.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
function assert (assertion) {
// From: http://phpjs.org/functions
// + original by: Brett Zamir (http://brett-zamir.me)
// % note 1: Do not pass untrusted user input to assert() in string form (you can test it beforehand though)
// % note 2: Does not provide perfect arguments to the assertion callback, as far as file location or line number
// % note 1: Do not pass untrusted user input to assert() in string form (you can test it beforehand though)
// % note 2: Does not provide perfect arguments to the assertion callback, as far as file location or line number
// * example 1: assert('false === true');
// * returns 1: false

Expand Down
1 change: 1 addition & 0 deletions experimental/info/get_defined_constants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function get_defined_constants (categorize) {
// From: http://phpjs.org/functions
// + original by: Brett Zamir (http://brett-zamir.me)
// % note 1: Could possibly substitute some others like M_PI with JavaScript's Math.PI, etc., but here
// % note 1: sticking to PHP, except for changing: NULL to null, NAN to NaN, and INF to Number.POSITIVE_INFINITY
Expand Down
11 changes: 9 additions & 2 deletions experimental/array/array.js → functions/array/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ function array () {
// From: http://phpjs.org/functions
// + original by: d3x
// + improved by: Brett Zamir (http://brett-zamir.me)
// * test: skip
// * example 1: array('Kevin', 'van', 'Zonneveld');
// * returns 1: ['Kevin', 'van', 'Zonneveld']
// * example 2: ini_set('phpjs.return_phpjs_arrays', 'on');
// * example 2: var arr = array({0:2}, {a:41}, {2:3}).change_key_case('CASE_UPPER').keys();
// * example 2: array({0:2}, {a:41}, {2:3}).change_key_case('CASE_UPPER').keys();
// * returns 2: [0,'A',2]

try {
this.php_js = this.php_js || {};
} catch (e) {
this.php_js = {};
}

var arrInst, e, __, that = this, PHPJS_Array = function PHPJS_Array() {},
mainArgs = arguments, p = this.php_js = this.php_js || {},
mainArgs = arguments, p = this.php_js,
_indexOf = function (value, from, strict) {
var i = from || 0, nonstrict = !strict, length = this.length;
while (i < length) {
Expand Down
9 changes: 5 additions & 4 deletions functions/array/array_change_key_case.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function array_change_key_case (array, cs) {
// From: http://phpjs.org/functions
// + original by: Ates Goral (http://magnetiq.com)
// + improved by: marrtins
// + improved by: Brett Zamir (http://brett-zamir.me)
// + improved by: Brett Zamir (http://brett-zamir.me)
// * example 1: array_change_key_case(42);
// * returns 1: false
// * example 2: array_change_key_case([ 3, 5 ]);
Expand All @@ -16,10 +16,10 @@ function array_change_key_case (array, cs) {
// * example 6: array_change_key_case({ FuBaR: 42 }, 2);
// * returns 6: {"FUBAR": 42}
// * example 7: ini_set('phpjs.return_phpjs_arrays', 'on');
// * example 7: var arr = array({a: 0}, {B: 1}, {c: 2});
// * example 7: var arr = [{a: 0}, {B: 1}, {c: 2}];
// * example 7: var newArr = array_change_key_case(arr);
// * example 7: newArr.b
// * example 7: 1
// * example 7: newArr.splice(1);
// * returns 7: {b: 1}

var case_fn, key, tmp_ar = {};

Expand All @@ -36,5 +36,6 @@ function array_change_key_case (array, cs) {
}
return tmp_ar;
}

return false;
}
2 changes: 1 addition & 1 deletion functions/array/array_filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function array_filter (arr, func) {
// * example 2: var even = function (num) {return (!(num & 1));}
// * example 2: array_filter([6, 7, 8, 9, 10, 11, 12], even);
// * returns 2: {0: 6, 2: 8, 4: 10, 6: 12}
// * example 3: var arr = array_filter({"a": 1, "b": false, "c": -1, "d": 0, "e": null, "f":'', "g":undefined});
// * example 3: array_filter({"a": 1, "b": false, "c": -1, "d": 0, "e": null, "f":'', "g":undefined});
// * returns 3: {"a":1, "c":-1};

var retObj = {},
Expand Down
13 changes: 9 additions & 4 deletions functions/array/array_flip.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
function array_flip (trans) {
// From: http://phpjs.org/functions
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + improved by: Pier Paolo Ramon (http://www.mastersoup.com/)
// + improved by: Brett Zamir (http://brett-zamir.me)
// + improved by: Pier Paolo Ramon (http://www.mastersoup.com/)
// + improved by: Brett Zamir (http://brett-zamir.me)
// - depends on: array
// * test: skip
// * example 1: array_flip( {a: 1, b: 1, c: 2} );
// * returns 1: {1: 'b', 2: 'c'}
// * example 2: ini_set('phpjs.return_phpjs_arrays', 'on');
Expand All @@ -11,12 +13,15 @@ function array_flip (trans) {

var key, tmp_ar = {};

if (trans && typeof trans=== 'object' && trans.change_key_case) { // Duck-type check for our own array()-created PHPJS_Array
// Duck-type check for our own array()-created PHPJS_Array
if (trans && typeof trans === 'object' && trans.change_key_case) {
return trans.flip();
}

for (key in trans) {
if (!trans.hasOwnProperty(key)) {continue;}
if (!trans.hasOwnProperty(key)) {
continue;
}
tmp_ar[trans[key]] = key;
}

Expand Down
2 changes: 2 additions & 0 deletions functions/array/array_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ function array_search (needle, haystack, argStrict) {
// + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + input by: Brett Zamir (http://brett-zamir.me)
// + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// - depends on: array
// * test: skip
// * example 1: array_search('zonneveld', {firstname: 'kevin', middle: 'van', surname: 'zonneveld'});
// * returns 1: 'surname'
// * example 2: ini_set('phpjs.return_phpjs_arrays', 'on');
Expand Down
8 changes: 5 additions & 3 deletions functions/array/array_walk.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ function array_walk (array, funcname, userdata) {
// + original by: Johnny Mast (http://www.phpvrouwen.nl)
// + bugfixed by: David
// + improved by: Brett Zamir (http://brett-zamir.me)
// % note 1: Using ini_set('phpjs.no-eval', true) will only work with
// % note 1: user-defined string functions, not built-in functions like void()
// - depends on: array
// % note 1: Using ini_set('phpjs.no-eval', true) will only work with
// % note 1: user-defined string functions, not built-in functions like void()
// * test: skip
// * example 1: array_walk ({'a':'b'}, 'void', 'userdata');
// * returns 1: true
// * example 2: array_walk ('a', 'void', 'userdata');
Expand All @@ -16,7 +18,7 @@ function array_walk (array, funcname, userdata) {
// * example 5: ini_set('phpjs.return_phpjs_arrays', 'on');
// * example 5: var arr = array({40: 'My age'}, {50: 'My IQ'});
// * example 5: array_walk(arr, [window, 'prompt']);
// * returns 5: [object Object]
// * returns 5: '[object Object]'
var key, value, ini;

if (!array || typeof array !== 'object') {
Expand Down
3 changes: 2 additions & 1 deletion functions/array/end.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ function end (arr) {
var arrpos = pointers.indexOf(arr);
if (Object.prototype.toString.call(arr) !== '[object Array]') {
var ct = 0;
var val;
for (var k in arr) {
ct++;
var val = arr[k];
val = arr[k];
}
if (ct === 0) {
return false; // Empty
Expand Down
1 change: 1 addition & 0 deletions functions/array/natcasesort.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ function natcasesort (inputArr) {
// * example 1: $array1 = {a:'IMG0.png', b:'img12.png', c:'img10.png', d:'img2.png', e:'img1.png', f:'IMG3.png'};
// * example 1: $array1 = natcasesort($array1);
// * returns 1: {a: 'IMG0.png', e: 'img1.png', d: 'img2.png', f: 'IMG3.png', c: 'img10.png', b: 'img12.png'}

var valArr = [],
k, i, ret, that = this,
strictForIn = false,
Expand Down
8 changes: 5 additions & 3 deletions functions/array/shuffle.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ function shuffle (inputArr) {
// % note 1: behavior by default if IE ever does allow it; only gives shallow copy since
// % note 1: is by reference in PHP anyways
// * example 1: ini_set('phpjs.strictForIn', true);
// * example 1: shuffle({5:'a', 2:'3', 3:'c', 4:5, 'q':5});
// * example 2: var data = {5:'a', 2:'3', 3:'c', 4:5, 'q':5};
// * example 1: shuffle(data);
// * example 1: data;
// * returns 1: {5:'a', 4:5, 'q':5, 3:'c', 2:'3'}
// * example 2: ini_set('phpjs.strictForIn', true);
// * example 2: var data = {5:'a', 2:'3', 3:'c', 4:5, 'q':5};
// * example 2: shuffle(data);
// * results 2: {5:'a', 'q':5, 3:'c', 2:'3', 4:5}
// * returns 2: true
// * example 2: data;
// * returns 2: {5:'a', 'q':5, 3:'c', 2:'3', 4:5}
var valArr = [],
k = '',
i = 0,
Expand Down
Loading