Created
January 17, 2012 13:40
-
-
Save tfluehr/1626664 to your computer and use it in GitHub Desktop.
Prototype String Methods in jQuery
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
$.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