Sugar
A Javascript library for working with native objects.
Date Module
Note that this build includes only the "date" module. This repo is a modularized build of the main Sugar repo. Please post all issues there.
Date module for the Sugar Javascript utility library.
A Javascript library for working with native objects.
Note that this build includes only the "date" module. This repo is a modularized build of the main Sugar repo. Please post all issues there.
npm install sugar-date
bower install sugar-date
Date#utc
is now Date#setUTC
.Date.SugarNewDate
is now an option accessor Sugar.Date.setOption('newDateInternal', fn)
String#startsWith
and String#endsWith
to be more in compliance with ES6. See CAUTION.md for details.String#has
in favor of String#includes
to be more in compliance with ES6. See CAUTION.md for details.Number.isNaN
shim. Removed Object.isNaN
in favor of this.Object.map
, Object.each
, and Object.size
to the object module.Object.isArguments
.String#each
(renamed to String#forEach
) to allow breaking the loop with false
.String#stripTags
and Strip#removeTags
to pass a callback.String#stripTags
and String#removeTags
much more robust.String#normalize
and will put into its own plugin module as String#toAscii
later.Array#sortBy
to handle sorting on multiple properties (Issue #386, thanks to @eric-weiser).String#unescapeHTML
to handle HTML (and hex) codes. Also now handling Number#bytes
to allow normal SI units.Object.merge
updated to take an options object. Non-enumerable property support is now an option, as well as property descriptors. Resolver function now will not traverse further into a deep merge if it has been resolved with a function. Sugar global object continues the merge.String#hankaku
now makes a hyphen from hyphen-like fullwidth chars in number mode.ten
in date creation (Issue #431).Date#[unit]Since
improperly applying error margins.since
and fromNow
methods to traverse using internal date methods instead of applying an error margin. This makes them much more accurate in dicey situations like DST traversal, leap years, etc.Function#every
not being able to cancel itself (Issue #488).Date#get
allowing date creation with a context date that can be used as a starting point for relative dates.Function#memoize
(Issue #486)Object.equal
and Object#equals
to isEqual
for parity.Date.utc
object as well as Date.past
and Date.future
in favor of an options object on Date#create
.Function#fill
to Function#partial
. Tests from Underscore and Lodash brought in to confirm conformitive behavior.null
now no longer acts as a placeholder in Function#partial
. Other bugs fixed around this including using partial
on constructors.Date#create
options object now uses fromUTC
instead of just utc
. A new option setUTC
is also added which will set the internal utc flag on creation.String#assign
refactored and renamed to String#format
. Tokens are zero based and a few other changes.Object.get
and Object.set
, allowed them to use dot, bracket, range, and push syntax, and allowed deep object transforms on Array#map
, and other methods.Array#randomize
to Array#shuffle
Array#sample
ability to remove sampled elements and performance optimization.String#replaceAll
and String#removeAll
.Array.from
and modified Array.create
to return a reference by default.Function#after
to more closely match that of Underscore/Lodash.Number#times
to return an array of return values.Object.fromQueryString
to return a plain object.Object.watch
and Object.unwatch
.Date.create
to accept enumerated arguments.Object.toQueryString
to accept an options object.Object.fromQueryString
to accept an options object.isEqual
.Array#median
.Number#metric
to use a more flexible system of defining units.Date#format
as well as a number of new standard tokens. Aligned tokens more with moment/ldml and renamed to ldml in the code.Array#at
and String#at
to use arrays instead of enumerated arguments.String#hankaku
and String#zenkaku
.String#replaceTags
and String#stripTags
to simplify argument signature and small performance boost.Array#isEqual
.RegExp#addFlag
and RegExp#removeFlag
to RegExp#addFlags
and RegExp#removeFlags
, and ensured they work on multiple flags.enumerable
, and split out array methods.Array#findAll
in favor of Array#filter
and Array#filterFromIndex
.Object.findAll
with Object.filter
.Array#isEmpty
now only checks for zero length.Object.select
and Object.reject
to enumerable module and updated to match objects on key existence.Object.remove
and Object.exclude
.Array#append
to take the place of Array#add
. Array#add
now is non-destructive. Array#insert
now aliases append
instead of add
.Array#include
(now is identical to Array#add
).Object.invert
.String#titleize
to String module from Inflections.Object.has
to allow deep keys. Also added a flag to allow properties in the prototype.Object.extended
and all trace of Hashes in favor of Sugar chainables.String#capitalize
to have an extra parameter for downcasing.Array#sortBy
to not clone the array by default.Date#reset
to use higher units to make more semantic sense.Date#relative
.Array#each
in favor of Array#forEachFromIndex
in cases where the index is needed.fromIndex
methods. Moved findFrom
and findIndexFrom
to be inline with these.Object.each
to Object.forEach
to bring it in line with other methods.Array#subtract
, Array#intersect
, and Array#union
to only accept a single argument to follow other methods more closely.String#add
, which on its own is largely useless in favor of String#insert
which was previously an alias.all
and any
aliases.step
argument in Number#upto
and Number#downto
to be an optional 2nd argument.Object.keys
and Object.values
. Object.forEach
should be preferred method of iteration.String#each
to String#forEach
.min/max/least/most
args to put the callback at the end.String#paragraphs
.Object.addAll
.Date.range
Date#past/future
(#383)Number#abs
(#400)clamp
for ranges and an alias for Number.cap
for ranges and an alias for Number.String#truncateOnWords
. Part of the String#truncate
functionality is now here.Array.create
will understand ranges and can build an array from one.DateRange#duration
is deprecated in favor of Range#span
.Number#upto
and Number#downto
will now work on inverse ranges.pad
, padLeft
, and padRight
now pad to the specified length, instead of simply adding to string.findAll
now directly match regexes against elements, regardless of whether or not they are strings.===
.Object.clone
now only works on known object types and does not work on instances of user-created classes.String#assign
now can be passed an array as well as enumerated arguments.Array#removeAt
#324isThisWeek
being false when not en locale.Date#beginningOfISOWeek
and Date#endOfISOWeek
Array#create
not working on argument objects of zero-length (Issue #299).String#capitalize
capitalizing after apostrophes (Issue #325).select
and reject
returning plain objects.Object.merge
not merging certain deep objects.multiMatch
in favor of a cached matcher system.Function#cancel
not properly clearing all timers (Issue #346).immediate
to Function#lazy
, which is now false by default.Function#every
.Array.AlphanumericSort
to allow its use in native Array#sort
.Array.AlphanumericSortNatural
that is on by default and triggers a natural sort.Array.find
now aligns with ES6 spec.String#truncate
not returning primitives.String#repeat
is now aligned more with spec. String#pad
follows suit.Array#findFrom
and Array#findIndexFrom
.Range#step
alias.deep
argument from Object.fromQueryString
and replaced with optional boolean casting.Object.toQueryString
.isToday
not working when using a non-English locale (Issue #264).Sugar#namespace
to fix conflict with jQuery (Issue #265).Date#getWeek
and Date#setWeek
to Date#getISOWeek
and Date#setISOWeek
.Date#setWeek
(now Date#setISOWeek
) to follow ISO-8601 standard.Object.extend()
.addMonths
(Issue #221).isOdd
(Issue #220).Object.fromQueryString
(Issue #225).Object.each
.7 July
date format (Issue #227).Number#format
(Issue #229).Array.create
on objects (#195).Date.future
(#210), zh-CN locale time parsing, (#204).Number.random
to have better random distribution (#196).Date#create
on ISO dates no longer sets the utc flag.hasOwnProperty
. This will notably now exclude functions and host objects such as DOM elements. This means that such excluded objects will be matched by reference only.String#split patching for regexes is now removed from the String module and is on its own in /lib/extra. It can be dropped in anywhere after Sugar is loaded.
Array#has is deprecated
Enumerable methods now allow fuzzy matching of instances of classes (Issue 157)
All Math methods are now mapped onto Number and are accessible as instance methods
String#capitalize all will capitalize any letter after a letter that could not be capitalized.
Fixed issue with decodeBase64 shim (Issue 145)
String#toDate is now deprecated.
false
as the wait
parameter.