Skip to content

Commit f01b724

Browse files
committed
Improved code.
1 parent ff6ca6a commit f01b724

3 files changed

Lines changed: 29 additions & 38 deletions

File tree

builders.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ SchemaBuilderEntity.prototype.getDependencies = function() {
463463

464464
var m = self.parent.get(type);
465465

466-
if (typeof(m) === undefined)
466+
if (m === undefined)
467467
continue;
468468

469469
dependencies.push({ name: name, isArray: isArray, schema: m });
@@ -1207,7 +1207,7 @@ SchemaBuilderEntity.prototype.prepare = function(model, dependencies) {
12071207
if (obj === null)
12081208
return null;
12091209

1210-
if (model === null || model === undefined)
1210+
if (model == null)
12111211
return self.default();
12121212

12131213
var tmp;
@@ -1251,7 +1251,7 @@ SchemaBuilderEntity.prototype.prepare = function(model, dependencies) {
12511251

12521252
// string
12531253
case 3:
1254-
tmp = val === undefined || val === null ? '' : autotrim(self, val.toString());
1254+
tmp = val == null ? '' : autotrim(self, val.toString());
12551255
if (type.length && type.length < tmp.length)
12561256
tmp = tmp.substring(0, type.length);
12571257

@@ -1385,7 +1385,7 @@ SchemaBuilderEntity.prototype.prepare = function(model, dependencies) {
13851385
break;
13861386

13871387
case 3:
1388-
tmp = tmp === undefined || tmp === null ? '' : autotrim(self, tmp.toString());
1388+
tmp = tmp == null ? '' : autotrim(self, tmp.toString());
13891389
if (type.length && tmp.length < tmp.length)
13901390
tmp = tmp.substring(0, type.length);
13911391

@@ -3062,7 +3062,7 @@ Pagination.prototype.prepare = function(max, format, type) {
30623062

30633063
var isHTML = type === 'html';
30643064

3065-
if (max === undefined || max === null) {
3065+
if (max == null) {
30663066
for (var i = 1; i < self.count + 1; i++) {
30673067
if (isHTML)
30683068
builder.push(self.prepare_html(format, i, self.count, self.items, i === self.page));
@@ -3188,7 +3188,7 @@ UrlBuilder.prototype.toString = function(url, skipEmpty) {
31883188
Object.keys(self.builder).forEach(function(o) {
31893189

31903190
var value = self.builder[o];
3191-
if (value === undefined || value === null)
3191+
if (value == null)
31923192
value = '';
31933193
else
31943194
value = value.toString();
@@ -3225,7 +3225,7 @@ UrlBuilder.prototype.hasValue = function(keys) {
32253225

32263226
for (var i = 0; i < keys.length; i++) {
32273227
var val = self.builder[keys[i]];
3228-
if (val === undefined || val === null)
3228+
if (val == null)
32293229
return false;
32303230
}
32313231

image.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,13 @@ exports.measureSVG = function(buffer) {
132132
@useImageMagick {Boolean} :: default false
133133
*/
134134
function Image(filename, useImageMagick, width, height) {
135-
136135
var type = typeof(filename);
137-
138136
this.width = width;
139137
this.height = height;
140138
this.builder = [];
141139
this.filename = type === 'string' ? filename : null;
142140
this.currentStream = type === 'object' ? filename : null;
143-
this.isIM = useImageMagick === undefined || useImageMagick === null ? F.config['default-image-converter'] === 'im' : useImageMagick;
141+
this.isIM = useImageMagick == null ? F.config['default-image-converter'] === 'im' : useImageMagick;
144142
this.outputType = type === 'string' ? framework_utils.getExtension(filename) : 'jpg';
145143
}
146144

utils.js

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const regexpUID = /^\d{14,}[a-z]{3}[01]{1}$/;
5454
const regexpZIP = /^\d{5}(?:[-\s]\d{4})?$/;
5555
const regexpXML = /\w+\=\".*?\"/g;
5656
const regexpDECODE = /&gt;|\&lt;|\&quot;|&apos;|&amp;/g;
57+
const regexpPARAM = /\{{2}[^}\n]*\}{2}/g;
5758
const SOUNDEX = { a: '', e: '', i: '', o: '', u: '', b: 1, f: 1, p: 1, v: 1, c: 2, g: 2, j: 2, k: 2, q: 2, s: 2, x: 2, z: 2, d: 3, t: 3, l: 4, m: 5, n: 5, r: 6 };
5859
const ENCODING = 'utf8';
5960
const NEWLINE = '\r\n';
@@ -1168,7 +1169,7 @@ exports.httpStatus = function(code, addCode) {
11681169
*/
11691170
exports.extend = function(target, source, rewrite) {
11701171

1171-
if (target === null || source === null)
1172+
if (!target || !source)
11721173
return target;
11731174

11741175
if (typeof(target) !== 'object' || typeof(source) !== 'object')
@@ -1318,7 +1319,7 @@ exports.reduce = function(source, prop, reverse) {
13181319
*/
13191320
exports.assign = function(obj, path, fn) {
13201321

1321-
if (obj === null || obj === undefined)
1322+
if (obj == null)
13221323
return obj;
13231324

13241325
var arr = path.split('.');
@@ -1431,7 +1432,7 @@ exports.streamer = function(beg, end, callback) {
14311432
*/
14321433
exports.encode = function(str) {
14331434

1434-
if (str === undefined)
1435+
if (str == null)
14351436
return '';
14361437

14371438
var type = typeof(str);
@@ -1449,7 +1450,7 @@ exports.encode = function(str) {
14491450
*/
14501451
exports.decode = function(str) {
14511452

1452-
if (str === undefined)
1453+
if (str == null)
14531454
return '';
14541455

14551456
var type = typeof(str);
@@ -1476,7 +1477,7 @@ exports.isStaticFile = function(url) {
14761477
* @return {Number}
14771478
*/
14781479
exports.parseInt = function(obj, def) {
1479-
if (obj === undefined || obj === null)
1480+
if (obj == null)
14801481
return def || 0;
14811482
var type = typeof(obj);
14821483
if (type === 'number')
@@ -1486,11 +1487,10 @@ exports.parseInt = function(obj, def) {
14861487

14871488
exports.parseBool = exports.parseBoolean = function(obj, def) {
14881489

1489-
if (obj === undefined || obj === null)
1490+
if (obj == null)
14901491
return def === undefined ? false : def;
14911492

14921493
var type = typeof(obj);
1493-
14941494
if (type === 'boolean')
14951495
return obj;
14961496

@@ -1509,11 +1509,10 @@ exports.parseBool = exports.parseBoolean = function(obj, def) {
15091509
*/
15101510
exports.parseFloat = function(obj, def) {
15111511

1512-
if (obj === undefined || obj === null)
1512+
if (obj == null)
15131513
return def || 0;
15141514

15151515
var type = typeof(obj);
1516-
15171516
if (type === 'number')
15181517
return obj;
15191518

@@ -1755,7 +1754,7 @@ function validate_builder_default(name, value, entity) {
17551754
if (type === 'boolean')
17561755
return value === true;
17571756

1758-
if (value === null || value === undefined)
1757+
if (value == null)
17591758
return false;
17601759

17611760
if (value instanceof Array)
@@ -2497,7 +2496,7 @@ Date.prototype.format = function(format, resource) {
24972496
format = format.substring(1);
24982497
}
24992498

2500-
if (format === undefined || format === null || format === '')
2499+
if (!format)
25012500
return self.getFullYear() + '-' + (self.getMonth() + 1).toString().padLeft(2, '0') + '-' + self.getDate().toString().padLeft(2, '0') + 'T' + self.getHours().toString().padLeft(2, '0') + ':' + self.getMinutes().toString().padLeft(2, '0') + ':' + self.getSeconds().toString().padLeft(2, '0') + '.' + self.getMilliseconds().toString().padLeft(3, '0') + 'Z';
25022501

25032502
var h = self.getHours();
@@ -2963,9 +2962,7 @@ String.prototype.format = function() {
29632962
var arg = arguments;
29642963
return this.replace(regexpSTRINGFORMAT, function(text) {
29652964
var value = arg[+text.substring(1, text.length - 1)];
2966-
if (value === null || value === undefined)
2967-
value = '';
2968-
return value;
2965+
return value == null ? '' : value;
29692966
});
29702967
};
29712968

@@ -3027,11 +3024,10 @@ String.prototype.urlDecode = function() {
30273024
String.prototype.params = function(obj) {
30283025
var formatted = this;
30293026

3030-
if (obj === undefined || obj === null)
3027+
if (obj == null)
30313028
return formatted;
30323029

3033-
var reg = /\{{2}[^}\n]*\}{2}/g;
3034-
return formatted.replace(reg, function(prop) {
3030+
return formatted.replace(regexpPARAM, function(prop) {
30353031

30363032
var isEncode = false;
30373033
var name = prop.substring(2, prop.length - 2).trim();
@@ -3069,7 +3065,7 @@ String.prototype.params = function(obj) {
30693065
val = obj[arr[0]][arr[1]][arr[2]][arr[3]][arr[4]];
30703066
}
30713067
} else
3072-
val = name.length === 0 ? obj : obj[name];
3068+
val = name.length ? obj[name] : obj;
30733069

30743070
if (typeof(val) === 'function')
30753071
val = val(index);
@@ -3078,7 +3074,6 @@ String.prototype.params = function(obj) {
30783074
return prop;
30793075

30803076
if (format.length) {
3081-
30823077
var type = typeof(val);
30833078
if (type === 'string') {
30843079
var max = +format;
@@ -3683,7 +3678,7 @@ Number.prototype.format = function(decimals, separator, separatorDecimal) {
36833678

36843679
Number.prototype.add = function(value, decimals) {
36853680

3686-
if (value === undefined || value === null)
3681+
if (value == null)
36873682
return this;
36883683

36893684
if (typeof(value) === 'number')
@@ -3962,7 +3957,7 @@ Number.prototype.parseDate = function(plus) {
39623957
return new Date(this + (plus || 0));
39633958
};
39643959

3965-
if (typeof (Number.prototype.toRad) === 'undefined') {
3960+
if (!Number.prototype.toRad) {
39663961
Number.prototype.toRad = function () {
39673962
return this * Math.PI / 180;
39683963
};
@@ -4808,7 +4803,7 @@ Async.prototype.await = function(name, fn, cb) {
48084803
name = exports.GUID(6);
48094804
}
48104805

4811-
if (self.tasksPending[name] !== undefined)
4806+
if (self.tasksPending[name])
48124807
return false;
48134808

48144809
self.tasksPending[name] = new AsyncTask(self, name, fn, cb, null);
@@ -4831,7 +4826,7 @@ Async.prototype.wait = function(name, waitingFor, fn, cb) {
48314826
waitingFor = null;
48324827
}
48334828

4834-
if (self.tasksPending[name] !== undefined)
4829+
if (self.tasksPending[name])
48354830
return false;
48364831

48374832
self.tasksPending[name] = new AsyncTask(self, name, fn, cb, waitingFor);
@@ -4917,7 +4912,7 @@ Async.prototype.refresh = function(name) {
49174912
break;
49184913

49194914
var task = self.tasksPending[name];
4920-
if (task === undefined)
4915+
if (!task)
49214916
break;
49224917

49234918
if (self.isCanceled || task.isCanceled) {
@@ -5253,9 +5248,7 @@ function queue_next(name) {
52535248
item.running++;
52545249
(function(name){
52555250
setImmediate(function() {
5256-
fn(function() {
5257-
queue_next(name);
5258-
});
5251+
fn(() => queue_next(name));
52595252
});
52605253
})(name);
52615254
}
@@ -5276,7 +5269,7 @@ exports.queue = function(name, max, fn) {
52765269
return true;
52775270
}
52785271

5279-
if (exports.queuecache[name] === undefined)
5272+
if (!exports.queuecache[name])
52805273
exports.queuecache[name] = { limit: max, running: 0, pending: [] };
52815274

52825275
var item = exports.queuecache[name];

0 commit comments

Comments
 (0)