diff2html/src/utils.js
Rodrigo Fernandes 8d86a15d69 Clean code and force code style
Since more people are contributing to the code Codacy will help
keep it consistent and easy to maintain, by suggesting improvements
2015-12-20 22:55:09 +00:00

46 lines
846 B
JavaScript

/*
*
* Utils (utils.js)
* Author: rtfpessoa
*
*/
(function() {
function Utils() {
}
Utils.prototype.escape = function(str) {
return str.slice(0)
.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\t/g, ' ');
};
Utils.prototype.getRandomId = function(prefix) {
return prefix + '-' + Math.random().toString(36).slice(-3);
};
Utils.prototype.startsWith = function(str, start) {
if (typeof start === 'object') {
var result = false;
start.forEach(function(s) {
if (str.indexOf(s) === 0) {
result = true;
}
});
return result;
}
return str.indexOf(start) === 0;
};
Utils.prototype.valueOrEmpty = function(value) {
return value ? value : '';
};
module.exports.Utils = new Utils();
})();