So in searching for a good polyfill for Element.classList, I found 2 promising versions:

1., which is on MDN as a “suggested” polyfill: This definitely works, but IMO is a little inelegantly written and might be hard to follow.

2., which is nice and clean, but the contains method is broken (I went to file an issue, but there are already several issues about this), and all other methods rely on that, so it’s really not usable. It also didn’t provide support for partial implementations.

So I wrote my own. I borrowed from both, heavily as regards to patching partial support from the former, but the base drop-in API is my own. Available on github: