Skip to content

Commit aec575a

Browse files
committed
More jslint-inspired fixes/changes
1 parent c0ce879 commit aec575a

File tree

13 files changed

+43
-30
lines changed

13 files changed

+43
-30
lines changed

functions/array/asort.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,12 @@ function asort(inputArr, sort_flags) {
3434
case 'SORT_REGULAR': // compare items normally (don't change types)
3535
default:
3636
sorter = function (a, b) {
37-
if (a > b)
37+
if (a > b) {
3838
return 1;
39-
if (a < b)
39+
}
40+
if (a < b) {
4041
return -1;
42+
}
4143
return 0;
4244
};
4345
break;
@@ -64,7 +66,7 @@ function asort(inputArr, sort_flags) {
6466
for (k in inputArr) {
6567
valArr.push(inputArr[k]);
6668
keyArr.push(k);
67-
delete inputArr[k] ;
69+
delete inputArr[k];
6870
}
6971
try {
7072
// Sort our new temporary arrays

functions/array/compact.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,23 @@ function compact ( ) {
88
// * example 1: compact('var1', 'var2', 'var3');
99
// * returns 1: {'var1': 'Kevin', 'var2': 'van', 'var3': 'Zonneveld'}
1010

11-
var Matrix = {};
12-
var key_value;
11+
var matrix = {};
1312

1413
var process = function ( value ) {
1514
var i = 0, l = value.length, key_value = '';
1615
for (i = 0; i < l; i++) {
1716
key_value = value [ i ];
1817
if (key_value instanceof Array) {
19-
process ( key_value );
18+
process( key_value );
2019
} else {
2120
if (typeof window[key_value] !== 'undefined') {
22-
Matrix[key_value] = window[key_value];
21+
matrix[key_value] = window[key_value];
2322
}
2423
}
2524
}
2625
return true;
2726
};
2827

2928
process(arguments);
30-
return Matrix;
29+
return matrix;
3130
}

functions/array/current.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ function current(arr) {
66
// * example 1: current(transport);
77
// * returns 1: 'foot'
88

9-
if (!this.php_js) this.php_js = {};
10-
if (!this.php_js.pointers) this.php_js.pointers = [];
9+
if (!this.php_js) {
10+
this.php_js = {};
11+
}
12+
if (!this.php_js.pointers) {
13+
this.php_js.pointers = [];
14+
}
1115
var pointers = this.php_js.pointers;
1216
if (pointers.indexOf(arr) === -1) {
1317
pointers.push(arr, 0);

functions/datetime/date.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ function date ( format, timestamp ) {
2525
// * example 4: (x+'').length == 10
2626
// * returns 4: true
2727

28-
var a, tal=[], jsdate=(
28+
var jsdate=(
2929
(typeof(timestamp) == 'undefined') ? new Date() : // Not provided
3030
(typeof(timestamp) == 'number') ? new Date(timestamp*1000) : // UNIX timestamp
3131
new Date(timestamp) // Javascript Date()
32-
);
32+
); // , tal=[]
3333
var pad = function(n, c){
3434
if( (n = n + "").length < c ) {
3535
return new Array(++c - n.length).join("0") + n;
@@ -173,10 +173,18 @@ function date ( format, timestamp ) {
173173
(jsdate.getMinutes() * 60) +
174174
jsdate.getSeconds() + off;
175175
var beat = Math.floor(theSeconds/86.4);
176-
if (beat > 1000) beat -= 1000;
177-
if (beat < 0) beat += 1000;
178-
if ((String(beat)).length == 1) beat = "00"+beat;
179-
if ((String(beat)).length == 2) beat = "0"+beat;
176+
if (beat > 1000) {
177+
beat -= 1000;
178+
}
179+
if (beat < 0) {
180+
beat += 1000;
181+
}
182+
if ((String(beat)).length == 1) {
183+
beat = "00"+beat;
184+
}
185+
if ((String(beat)).length == 2) {
186+
beat = "0"+beat;
187+
}
180188
return beat;
181189
},
182190
g: function(){
@@ -225,7 +233,7 @@ function date ( format, timestamp ) {
225233
},
226234
O: function(){
227235
var t = pad(Math.abs(jsdate.getTimezoneOffset()/60*100), 4);
228-
if (jsdate.getTimezoneOffset() > 0) t = "-" + t; else t = "+" + t;
236+
t = (jsdate.getTimezoneOffset() > 0) ? "-"+t : "+"+t;
229237
return t;
230238
},
231239
P: function(){

functions/datetime/date_default_timezone_get.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ function date_default_timezone_get () {
1212
if (this.php_js.default_timezone) { // set by date_default_timezone_set
1313
return this.php_js.default_timezone;
1414
}
15-
if (this.php_js.ENV && this.php_js.ENV['TZ']) { // getenv
16-
return this.php_js.ENV['TZ'];
15+
if (this.php_js.ENV && this.php_js.ENV.TZ) { // getenv
16+
return this.php_js.ENV.TZ;
1717
}
1818
if (this.php_js.ini && this.php_js.ini['date.timezone']) { // e.g., if set by ini_set()
19-
return this.php_js.ini['date.timezone']['local_value'] ? this.php_js.ini['date.timezone']['local_value'] : this.php_js.ini['date.timezone']['global_value'];
19+
return this.php_js.ini['date.timezone'].local_value ? this.php_js.ini['date.timezone'].local_value : this.php_js.ini['date.timezone'].global_value;
2020
}
2121
}
2222
// Get from system
23-
tal = timezone_abbreviations_list();
23+
tal = this.timezone_abbreviations_list();
2424
for (abbr in tal) {
2525
for (i=0; i < tal[abbr].length; i++) {
2626
if (tal[abbr][i].offset === -today.getTimezoneOffset()*60) {

functions/datetime/date_default_timezone_set.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function date_default_timezone_set (tz) {
1212
this.php_js={};
1313
}
1414
// PHP verifies that the timezone is valid
15-
tal = timezone_abbreviations_list();
15+
tal = this.timezone_abbreviations_list();
1616
for (abbr in tal) {
1717
for (i=0; i < tal[abbr].length; i++) {
1818
if (tal[abbr][i].timezone_id === tz) {

functions/math/decbin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ function decbin(number) {
99
// * example 3: decbin('26');
1010
// * returns 3: '11010'
1111

12-
return parseInt(number).toString(2);
12+
return parseInt(number, 10).toString(2);
1313
}

functions/math/dechex.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ function dechex(number) {
77
// * example 2: dechex(47);
88
// * returns 2: '2f'
99

10-
return parseInt(number).toString(16);
10+
return parseInt(number, 10).toString(16);
1111
}

functions/math/decoct.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@ function decoct(number) {
77
// * example 2: decoct(264);
88
// * returns 2: '410'
99

10-
return parseInt(number).toString(8);
10+
return parseInt(number, 10).toString(8);
1111
}

functions/objaggregation/aggregate_methods_by_regexp.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function aggregate_methods_by_regexp (obj, class_name, regexp, exclude) {
99
// * example 1: aggregate_methods_by_regexp(b, 'A', /^meth/, false);
1010
// * returns 1: undefined
1111

12-
var p = '', i=0, test=false, record={}, pos=-1;
12+
var p = '', test=false, record={}, pos=-1;
1313

1414
if (typeof regexp === 'string') { // If passing the regular expression as a string, note that this behavior may change in the future as we seek to implement PHP-style regexp (e.g., delimiteres and modifier flags within the string)
1515
regexp = eval(regexp);

0 commit comments

Comments
 (0)