Created
July 26, 2013 13:57
-
-
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.
This file contains hidden or 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
// 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