Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // sformat prototype as argument replacement.
- //
- // "{0} is dead, but {1} is alive! {0} {2}".sformat("ASP", "ASP.NET")
- // Output: "ASP is dead, but ASP.NET is alive! ASP {2}"
- //
- if (!String.prototype.sformat) {
- String.prototype.sformat = function() {
- const args = arguments;
- return this.replace(/{(\d+)}/g, (match, number) => {
- return typeof args[number] !== 'undefined' ? args[number] : match;
- });
- };
- }
- if (!String.prototype.present) {
- String.prototype.present = function() {
- return this && typeof this != 'undefined' && this.length > 0;
- };
- }
- if (!String.prototype.starts) {
- String.prototype.starts = function(text) {
- return this.toLowerCase().search(text.toLowerCase()) > -1;
- };
- }
Add Comment
Please, Sign In to add comment