Skip to content

Instantly share code, notes, and snippets.

@tfluehr
Created January 17, 2012 13:40
Show Gist options
  • Save tfluehr/1626664 to your computer and use it in GitHub Desktop.
Save tfluehr/1626664 to your computer and use it in GitHub Desktop.
Prototype String Methods in jQuery
$.extend({
string: {
// public interface: $.tmpl
include: function(text, pattern){
return text.indexOf(pattern) > -1;
},
startsWith: function(text, pattern){
return text.lastIndexOf(pattern, 0) === 0;
},
endsWith: function(text, pattern){
var d = text.length - pattern.length;
return d >= 0 && text.indexOf(pattern, d) === d;
},
repeat: function(str, count){
if (isNaN(count)) {
return "";
}
var result = [];
for (var i = 0; i < count; i++) {
result.push(str);
}
return result.join('');
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment