Unsizzle: A Simple Selector Builder

A while ago, I started toying around with a Chrome extension that would let me save a set of DOM actions and play them back. I did a bit of digging and found that there were already a few implementations out there, like Selector Gadget and whatever Optimizely is using. Selector Gadget was last updated in 2009 and built for much older browsers. Optimizely's code seemed decent, but it was dependent on jQuery. That's not terrible, but it seemed unnecessary and lazy. So I embarked on writing my own. With this very tiny library, I set out to do three things: 1. Accurately find the right node, every time. 2. Expose an API that was simple, memorable and flexible. 3. Create no dependencies. As a side note, I've recently added a fourth mandate of making this library testable via Grunt. With that in mind, I release to the world, unsizzle. The core API is as simple as can be. Simply give unsizzle an Event or Node object, and it'll return a selector. E.g.
// Returns something like "#some-parent > .some-class > ul > li:eq(3) > div"
There are certainly optimizations to be made, but I'm hoping the wider community finds this little library useful. It's great for browser plugins, bookmarklets and any situation in which you'd like to record a DOM action for later evaluation. Enjoy!
View the unsizzle repo on github.com