2015-04-11 23:09:05 +00:00
|
|
|
/*
|
|
|
|
|
*
|
|
|
|
|
* Utils (utils.js)
|
|
|
|
|
* Author: rtfpessoa
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
(function() {
|
2019-05-08 22:42:42 +00:00
|
|
|
var merge = require('merge');
|
2017-10-16 21:00:03 +00:00
|
|
|
|
2015-04-12 01:59:54 +00:00
|
|
|
function Utils() {
|
|
|
|
|
}
|
2015-04-11 23:09:05 +00:00
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
Utils.prototype.escape = function(str) {
|
2015-04-12 01:59:54 +00:00
|
|
|
return str.slice(0)
|
2015-08-08 00:11:35 +00:00
|
|
|
.replace(/&/g, '&')
|
|
|
|
|
.replace(/</g, '<')
|
|
|
|
|
.replace(/>/g, '>')
|
2017-03-17 23:57:09 +00:00
|
|
|
.replace(/"/g, '"')
|
|
|
|
|
.replace(/'/g, ''')
|
2019-04-15 16:17:55 +00:00
|
|
|
.replace(/\//g, '/');
|
2015-04-12 01:59:54 +00:00
|
|
|
};
|
2015-04-11 23:09:05 +00:00
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
Utils.prototype.startsWith = function(str, start) {
|
2015-08-08 00:56:50 +00:00
|
|
|
if (typeof start === 'object') {
|
|
|
|
|
var result = false;
|
|
|
|
|
start.forEach(function(s) {
|
|
|
|
|
if (str.indexOf(s) === 0) {
|
|
|
|
|
result = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-28 20:58:51 +00:00
|
|
|
return str && str.indexOf(start) === 0;
|
2015-04-12 01:59:54 +00:00
|
|
|
};
|
|
|
|
|
|
2015-08-08 00:11:35 +00:00
|
|
|
Utils.prototype.valueOrEmpty = function(value) {
|
2016-07-12 12:47:29 +00:00
|
|
|
return value || '';
|
2015-04-12 01:59:54 +00:00
|
|
|
};
|
|
|
|
|
|
2017-10-16 21:00:03 +00:00
|
|
|
Utils.prototype.safeConfig = function(cfg, defaultConfig) {
|
2019-05-08 22:42:42 +00:00
|
|
|
return merge.recursive(true, defaultConfig, cfg);
|
2017-10-16 21:00:03 +00:00
|
|
|
};
|
|
|
|
|
|
2015-12-20 22:22:58 +00:00
|
|
|
module.exports.Utils = new Utils();
|
|
|
|
|
})();
|