Last active
November 1, 2019 10:36
-
-
Save ruslankonev/0a2b0add98092bacd3ac to your computer and use it in GitHub Desktop.
JS
toCamel, trim, toDash, toUnderscore, capitalize, decapitalize, blankLink, parseURL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.toCamel = function(){ | |
return this.replace(/([-_][a-z])/g, function($1){return $1.toUpperCase().replace(/[-_]/,'');}); | |
}; | |
String.prototype.trim = function(){ | |
return this.replace(/^\s+|\s+$/g, ""); | |
}; | |
String.prototype.toDash = function(){ | |
return this.replace(/([A-Z])/g, function($1){return "-"+$1.toLowerCase();}); | |
}; | |
String.prototype.toUnderscore = function(){ | |
return this.replace(/([A-Z])/g, function($1){return "_"+$1.toLowerCase();}); | |
}; | |
String.prototype.capitalize = function() { | |
return this.charAt(0).toUpperCase() + this.slice(1); | |
}; | |
String.prototype.decapitalize = function() { | |
return this.charAt(0).toLowerCase() + this.slice(1); | |
}; | |
String.prototype.blankLink = function(url) { | |
return "<a target='_blank' href='" + url + "'>" + url + "</a>"; | |
} | |
String.prototype.parseURL = function() { | |
return this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&~\?\/.=]+/g, function(url) { | |
return url.blankLink(url); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment