A Javascript library for working with native objects.
Alternatives To Sugar
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Sugar4,4612,4864312 years ago33December 05, 201888mitJavaScript
A Javascript library for working with native objects.
Proposal Temporal3,03764 hours ago10July 09, 202172otherHTML
Provides standard objects and functions for working with dates and times.
Date Utils3731,8731957 months ago31April 19, 201612mitJavaScript
Date Pollyfills for Node.js and Browser
Better Dateinput Polyfill259543 years ago29April 17, 20218mitJavaScript
input[type=date] polyfill for better-dom
Nodep Date Input Polyfill76844 years ago61August 22, 201718mitJavaScript
Automatically adds datepickers to input[type=date] on IE, macOS Safari, and legacy browsers.
Datetime Picker67455 years ago32November 16, 20187mitJavaScript
A minimal picker for date and time for Polymer, that can use the native input
12 years ago2December 29, 2011mitCoffeeScript
Partial EC5.1 polyfill for ISO 8601 support in the JavaScript Date object.
Date Polyfill30
8 years agoFebruary 22, 20217CoffeeScript
A polyfill for implementing the HTML5 <input type="date"> element in browsers that do not currently support it.
Html5 Simple Date Input Polyfill26145 years ago3November 15, 20158mitJavaScript
just include this simple script and IE and Firefox will support <input type="date">, without any dependencies
Angular Date Picker Polyfill19
6 years agoFebruary 22, 202115otherCoffeeScript
HTML5 Date Input Polyfill for AngularJS
Alternatives To Sugar
Select To Compare

Alternative Project Comparisons


Build Status Coverage Status

A Javascript library for working with native objects.


sugar.js | sugar.min.js (24kb gz)


npm install sugar

bower install sugar


If you are upgrading from v1, there is now an upgrade helper script available that makes upgrading easier by warning you about breaking changes as your code is run. The CAUTIONLOG is also available, which is a vetted changelog showing breaking changes in order of severity.

Getting Started


Custom Builds

Custom browser builds can be created on the site download page. In addition, tools like Browserify can also be used to create custom builds, as npm packages are now fully modular. The main repo also has tasks to create custom builds as well. Simply clone, run npm install then gulp.


The dist directory holds builds that are ready to be loaded in the browser. These builds include the core module, and so have no dependencies. Bower packages at the moment include only this directory. Use the es5 builds if you require support for environments that do not support ES5 natively (IE8 and below).


The sugar npm package allows methods as well as entire modules to be required individually. If you are using a build tool like Browserify, this will make it simple to create smaller custom builds without going through the download page. All packages also include pre-built distributions in the dist/ directory.

In addition to the main sugar package, there are also packages separated by Sugar module, i.e. sugar-date, sugar-array, etc.

When an entry point is required (the package name or an entire module), it will return a reference to Sugar, which is equivalent to the global object in the browser. All methods will be defined on this object and can be called as normal. Requiring an individual method will define it on Sugar and additionally return a reference to its static form that can be called immediately:

// Require all modules
var Sugar = require('sugar');

// Require the Number module
var Sugar = require('sugar/number');

// Require only the "round" method
var round = require('sugar/number/round');

As the npm package is designed with node in mind, polyfills must be explicitly required (the sugar entry point will not include them), and will immediately apply themselves if the methods they polyfill are missing.

// Require and apply ES6 polyfills

Similarly, date locales must be explicitly required as well:

// Require the Japanese date locale
// Require all date locales

All Sugar npm packages are dependent on the sugar-core package.


Although Sugar builds can now be customized at method level, modules are still used as an intuitive way of grouping similar methods. Sugar npm packages make use of modules, both in the main sugar package as well as individual module packages beginning with sugar-. The following modules are available:



  • ES5 (Polyfills, adds IE6-8 Support)
  • Language (Character conversion and script detection)
  • Inflections (Pluralization and string normalization)

Non-default modules are excluded from the main Sugar build, but can be added by creating a custom build. The main npm package includes the ES5 module, polyfills are disabled by default and must be explicitly required. Other non-default modules can be found individually (i.e. sugar-language, etc).

Date Locales

Locale definition files are in the locales directory. They can be simply included as-is after Sugar is loaded, or built together using custom builds. English is included by default and required by the Date module. Currently available locales are:

Adding/Customizing Locales

If a locale or format is missing, it can easily be added by modifying or adding the definition. See here for more on this. Please consider contributing any changes made back to the community!


Sugar does not deal with timezone abbreviations (i.e. "PST", etc). Timezone offsets will be correctly parsed if they are in ISO-8601 format (+09:00, +0900, or Z for UTC), however if an abbreviation exists it will be ignored. Sugar however plays nicely with other libraries that offer full timezone support such as timezone.js.

Date.create allows two options for dealing with UTC dates. fromUTC will parse the string as UTC, but return a normal date. In contrast, setUTC tells Sugar to use methods like getUTCHours when handling the date, and is usually used when the date needs to be formatted as UTC. Native methods like getHours still return local values.

Defining Methods

Sugar now makes it easy to define your own methods. This is aimed at developers hoping to release their own plugins with Sugar. After defining methods, they can be extended or used as chainables just like other methods:

Sugar.Number.defineStatic('randomish', function () {
  if (Math.random() > .5) {
    return Math.random();
  } else {
    return 1;

  'square': function (n) {
    return n * n;
  'cube': function (n) {
    return n * n * n;

Sugar.Number.square(3);         // 9
new Sugar.Number(5).cube().raw; // 125
Sugar.Number.randomish()        // ???

(2).square();       // 4
(4).cube();         // 64
Number.randomish(); // ???

See the docs for options and other helpers.


If you are defining methods that are useful to the general public, please consider releasing them as a Sugar plugin! Refer to the plugin boilerplate repo for an example to get started.


If you would like to issue a pull request, please first consider adding well formed unit tests. These tests can be run directly in the browser from the test/browser/ directory or in node with npm test.

Road Map

Proposals for core features or major method changes will be added to the road map. New methods may or may not be accepted, depending on their utility. Generally, they will first be delegated to plugins that may eventually be added to the main library when they reach a certain stage of popularity.

Popular Date Projects
Popular Polyfill Projects
Popular Libraries Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.