Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
String startsWith & endsWith polyfills
;(function (sp) {
if (!sp.startsWith)
sp.startsWith = function (str) {
return !!(str && this) && !this.lastIndexOf(str, 0)
}
if (!sp.endsWith)
sp.endsWith = function (str) {
var offset = str && this ? this.length - str.length : -1
return offset >= 0 && this.lastIndexOf(str, offset) === offset
}
})(String.prototype);
@tipiirai

This comment has been minimized.

Copy link

@tipiirai tipiirai commented Aug 30, 2015

Found this one by coincidence. Nice, minimalistic code from a Riot.js contributor. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment