Sugar. Javascript, sweetened.

Customize Github Download

What is Sugar?

Sugar is a Javascript library that extends native objects with helpful methods. It is designed to be intuitive, unobtrusive, and let you do more with less code.

What is Sugar not?

Sugar is a not a framework for AJAX, animation, or DOM manipulation. In fact, Sugar is not tied to the browser in any way. It's also not evil, promise :)

getLatestTweets(function(tweets) { var users = tweets.map('user').unique(), total = users.sum('statuses_count').format(), top = users.max('followers_count'), followers = top.followers_count.format(), started = Date.create(top.created_at), str = '{users} users with a total of {total} ' + 'tweets {name} is the most popular with ' + '{followers} followers and start tweeting {time}'; return str.assign({ users: users.length, total: total, name: top.screen_name, followers: followers, time: started.relative() }); });

Sugar...

So it's Prototype then...?
Sugar adds methods to native Javascript objects, much like Prototype, but has none of the weight of ajax, DOM, or inheritance oriented frameworks. Sugar also prefers native Javascript conventions and syntax.
Okay, so then it's Underscore...?
Sugar is intended as a support library for functional programming like Underscore. However, it differs quite a bit with what and how it chooses to implement.
Then surely it must have something to do with jQuery...?!
Sugar fits right in with jQuery, especially in data-heavy applications. However, it is in no way dependent on jQuery, or even on the browsing environment.
But Sugar modifies native objects! Isn't that Evil™?
Probably not as much as you think. Sugar sidesteps the biggest pitfalls of extending natives, and approaches the rest with caution and a huge suite of unit tests. Read more.
Will Sugar break my existing code?
Unless you are using another library that modifies natives, the risks are minimal. Sugar does not modify Object.prototype and adds methods in a way that does its best to avoid problems with enumerability.
Any help for someone coming from another language/framework?
The library comparison page shows a method-by-method comparison of Sugar to other libs and even languages like Ruby and Python. Also, if you're coming from Prototype or Underscore check out the analyzer script which gives dynamic, inline tips on using Sugar and also steps through your code and fires warnings at exactly the point something needs to be changed.
Is Sugar available for Node.js?
Yes!