Format and manipulate dates in plain JavaScript without adding a large library like moment.js.
Chain array and string operations expressively without writing repetitive utility functions for every project.
Add modern JavaScript ES5/ES6 features to code that must support older browsers using Sugar's polyfill modules.
Build i18n-aware date parsing and formatting across a dozen locales without external dependencies.
No external dependencies, can be loaded via a single CDN script tag or installed modularly through npm.
Sugar is a JavaScript library that adds extra methods to the built-in types that JavaScript already provides, such as arrays, strings, numbers, dates, and objects. Rather than introducing entirely new abstractions, it extends the language's existing foundations with helpers that developers tend to need repeatedly. The idea is that working with dates, formatting strings, manipulating arrays, and rounding numbers should feel less repetitive and more expressive than the default JavaScript experience allows. The library is organized into modules, each corresponding to a built-in type. There are modules for arrays, dates, numbers, strings, objects, functions, regular expressions, and ranges. There are also optional polyfill modules for ES5 and ES6 features, which add modern JavaScript capabilities to older browsers. An extra Language module handles character script detection and conversion, and an Inflections module handles things like pluralizing words and normalizing strings. The date module supports over a dozen locales, covering European languages, Japanese, Korean, Chinese, and others. Sugar can be loaded in a browser directly from the dist folder, or pulled in via npm. The npm package is modular, so you can require only the specific module or even the individual method you need rather than loading the entire library. This makes it practical to use with build tools that strip out unused code. Developers can also create custom browser builds through the project's website download page. One notable design choice is that Sugar does not extend native prototypes by default. When used through npm, methods are called on Sugar's own wrapper objects. Calling Sugar.extend() explicitly opts into adding methods directly onto native prototypes, which is the older style the library originally used. This gives developers the choice between a safer modular style and the more concise chaining style. The library also supports defining and publishing your own methods in the same style as the built-in ones, which is intended for developers who want to build plugins on top of Sugar. Documentation and a quickstart guide are available at sugarjs.com.
← andrewplummer on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.