Twitter never lets me down 🙂

Today, I stumbled upon Sugar,  a really nice–and small–JavaScript library. Unlike monster libraries such as jQuery and ExtJS (which are awesome in their own ways…), Sugar is narrowly focused. It’s niche is simply extending native JS objects with intuitive methods.

So want to capitalize the first word in a string? Easy: string.capitalize(). Want to replace dashes/underscores with spaces? Nothing to it: string.spacify().

I’ve worked up a quick couple of demos of a few of the string methods, just to show how dead simple Sugar is to use. Of course, you should check out Sugar’s API for the full enchilada. Mmmm, enchildas

Impressions

While I am a die-hard ExtJS user, there is something about the simplicity of Sugar that I really like. While it certainly won’t give you the tools to build a full-fledged web app with components, data grids, and what-not, it’s perfect for the small or one-off websites/pages where JS’ native objects could use some extra lovin’.

The one drawback (and it’s a slight one) is that there does not appear to be a way to do a custom build of Sugar to include *only* those methods which you need. According to their blog, this is because of some internals of Sugar that are needed throughout the library for IE support. What, IE ruining yet another otherwise great project? Surely not!

Although the custom-build-ness is lacking, the full library is only 17k gzipped, so there’s really not a huge hit including the whole thing anyway. That’s what caching is for anyway, right?

Wrapping Up

Honestly, I haven’t looked closely at Sugar’s internals to make a judgement about how “well done” their extension of native JS objects is. However, my initial impression is that I really like the approach they’ve taken. The ridiculously simple implementation of their API makes Sugar a library worth keeping in mind when you’ve got some light to moderate JS-in’ to do.