"use strict"; Date.prototype.addDays = function (days) { let date = new Date(this.valueOf()); date.setDate(date.getDate() + days); return date; }; Date.prototype.substractDays = function (days) { let date = new Date(this.valueOf()); date.setDate(date.getDate() - days); return date; }; Storage.prototype.removeRegex = function (r) { if (!r) return; let n = sessionStorage.length; while (n--) { let key = sessionStorage.key(n); let rx = new RegExp(r); if (rx.test(key)) { sessionStorage.removeItem(key); } } }; Storage.prototype.setStringified = function (key, value) { let stringified = JSON.stringify(value); sessionStorage.setItem(key, stringified); }; Storage.prototype.getParsedValue = function (key) { try { let value = sessionStorage.getItem(key); return JSON.parse(value); } catch (e) { return null; } }; //"Hello, {name}, are you feeling {adjective}?".formatUnicorn({name:"Gabriel", adjective: "OK"}); String.prototype.formatUnicorn = function () { let str = this.toString(); if (arguments.length) { let t = typeof arguments[0]; let key; let args = ("string" === t || "number" === t) ? Array.prototype.slice.call(arguments) : arguments[0]; for (key in args) { str = str.replace(new RegExp("\\{" + key + "\\}", "gi"), args[key]); } } return str; }; //"Hello, {0}, are you feeling {1}?".format("Gabriel", "OK"); String.prototype.format = function () { let args = arguments; return this.replace(/{(\d+)}/g, function (match, number) { return typeof args[number] != 'undefined' ? args[number] : match ; }); }; String.prototype.toHash = function () { let hash = 0, i, chr; if (this.length === 0) return hash; for (i = 0; i < this.length; i++) { chr = this.charCodeAt(i); hash = ((hash << 5) - hash) + chr; hash |= 0; // Convert to 32bit integer } return hash; };