Skip to content

Instantly share code, notes, and snippets.

@aMarCruz
Last active December 26, 2018 02:01
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aMarCruz/7892c05992d9ba559c99 to your computer and use it in GitHub Desktop.
Save aMarCruz/7892c05992d9ba559c99 to your computer and use it in GitHub Desktop.
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
Copy link

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