2017-04-19 23:11:37 +02:00
|
|
|
class Helper {
|
|
|
|
constructor () {
|
|
|
|
this.addHelpfulPrototypes();
|
|
|
|
}
|
|
|
|
|
|
|
|
addHelpfulPrototypes () {
|
2017-04-26 07:13:59 +02:00
|
|
|
String.prototype.capitalize = function () {
|
|
|
|
return this.charAt(0).toUpperCase() + this.slice(1);
|
|
|
|
}
|
|
|
|
String.prototype.replaceAt = function (index, replacement) {
|
|
|
|
return this.substr(0, index) + replacement + this.substr(index + replacement.length);
|
2017-04-19 23:11:37 +02:00
|
|
|
}
|
|
|
|
}
|
2017-04-23 01:05:36 +02:00
|
|
|
|
2017-04-26 07:13:59 +02:00
|
|
|
characterIsUppercase (character) {
|
|
|
|
return character === character.toUpperCase();
|
2017-04-23 01:05:36 +02:00
|
|
|
}
|
2017-08-17 00:53:55 +02:00
|
|
|
|
|
|
|
arraysAreEqual (array1, array2) {
|
|
|
|
// if the other array2 is a falsy value, return
|
|
|
|
if (!array1 || !array2)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// compare lengths - can save a lot of time
|
|
|
|
if (array1.length != array2.length)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for (var i = 0, l=array1.length; i < l; i++) {
|
|
|
|
// Check if we have nested arrays
|
|
|
|
if (array1[i] instanceof Array && array2[i] instanceof Array) {
|
|
|
|
// recurse into the nested arrays
|
|
|
|
if (!array1[i].equals(array2[i]))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if (array1[i] != array2[i]) {
|
|
|
|
// Warning - two different object instances will never be equal: {x:20} != {x:20}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
objectIsEmpty (obj) {
|
|
|
|
for(var key in obj) {
|
|
|
|
if(obj.hasOwnProperty(key))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2017-04-19 23:11:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export default new Helper;
|