@qbyco/tjs-cli
Version:
TrafaletJS CLI Tool
58 lines (48 loc) • 1.32 kB
JavaScript
(function () {
/**
* @method toUniqueId
* Gets the provided string and uses it as a salt for
* creating a unique ID
*/
Object.defineProperty(String.prototype, "toUniqueId", {
value: function (keyLength) {
let text = "",
size = 10,
possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
possible += this.toString();
if(undefined !== keyLength) {
size = keyLength;
}
for( var i=0; i < size; i++ ) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}
});
/**
* @method sprintf
* The good ol` sprintf
*/
Object.defineProperty(String.prototype, "sprintf", {
value: function () {
let text,
i_argument;
text = this.toString();
for (i_argument = 0; i_argument < arguments.length; i_argument += 1) {
text = text.replace("%s", arguments[i_argument]);
}
return text;
}
});
/**
* @method capitalizeFirstLetter
* @memberof String
* @description Will make first letter in string upper case
* @return {string}
*/
Object.defineProperty(String.prototype, "capitalizeFirstLetter", {
value: function () {
return this.charAt(0).toUpperCase() + this.slice(1);
}
});
}());