Skip to content

Instantly share code, notes, and snippets.

@DinoChiesa
Created July 26, 2013 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DinoChiesa/6089059 to your computer and use it in GitHub Desktop.
Save DinoChiesa/6089059 to your computer and use it in GitHub Desktop.
string extensions for use with the sql-1.asp example I posted previously.
// stringExtensions.js
//
// a few extensions on the string object.
//
// Fri, 10 Feb 2012 16:48
//
(function(globalScope) {
if (typeof String.prototype.trim != 'function') {
String.prototype.trim = function() {
return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
};
}
if (typeof String.prototype.startsWith != 'function') {
String.prototype.startsWith = function (str){
return this.slice(0, str.length) == str;
};
}
if (typeof String.prototype.capitalize != 'function') {
String.prototype.capitalize = function (str){
return this.charAt(0).toUpperCase() + this.slice(1);
};
}
if (typeof String.prototype.trimPunctuation != 'function') {
String.prototype.trimPunctuation = function (str){
var s = this.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g,"");
return s;
};
}
if (typeof String.prototype.endsWith != 'function') {
String.prototype.endsWith = function (str){
return this.slice(-str.length) == str;
};
}
}(this));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment