Sugar v1.4.0 Release Notes
-
API Changes
- ➕ Adding generalized ranges for Numbers and Strings in addition to Dates.
- Date ranges are now part of the Range module and are no longer dependent on the Date module.
- ➕ Adding
clamp
for ranges and an alias for Number. - ➕ Adding
cap
for ranges and an alias for Number. - ➕ Added
String#truncateOnWords
. Part of theString#truncate
functionality is now here. - 🏗
Array.create
will understand ranges and can build an array from one. - 🗄
DateRange#duration
is deprecated in favor ofRange#span
. - 🛠 Fix for relative times with "4 weeks" that are actually past the single month threshold.
Number#upto
andNumber#downto
will now work on inverse ranges.pad
,padLeft
, andpadRight
now pad to the specified length, instead of simply adding to string.- Fuzzy matching methods like
findAll
now directly match regexes against elements, regardless of whether or not they are strings. - Instances of classes are now entirely matched by reference only, as originally intended. This means that any equality checking inside Sugar will consider them equal only if they are
===
. - 👯
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.- 🛠 Fixed global variable leak #328
- 🚚 Optimization for
Array#removeAt
#324 - 🛠 Fix for
isThisWeek
being false when not en locale. - 👍 Timezone formatting tokens changed to align with Moment.js better.
- 🐎 Major performance optimization for date formatting and more.
- ➕ Added
Date#beginningOfISOWeek
andDate#endOfISOWeek
- 🛠 Fix for
Array#create
not working on argument objects of zero-length (Issue #299). - 🛠 Fix for
String#capitalize
capitalizing after apostrophes (Issue #325). - 🛠 Fix for extended objects
select
andreject
returning plain objects. - 🛠 Fix for
Object.merge
not merging certain deep objects. - ➕ Added Date.SugarNewDate to allow customization of internally created dates.
- ✂ Removed
multiMatch
in favor of a cached matcher system. - 🛠 Fix for environments where regexes are functions.
- 🛠 Fix for
Function#cancel
not properly clearing all timers (Issue #346). - 🛠 Fix for lazy functions not being able to recursively call themselves.
- ➕ Added option
immediate
toFunction#lazy
, which is now false by default. - ➕ Added
Function#every
. - 🔦 Exposed
Array.AlphanumericSort
to allow its use in nativeArray#sort
. - ➕ Added
Array.AlphanumericSortNatural
that is on by default and triggers a natural sort. - 🛠 Fixed strings not being coerced into objects in < IE8.
Array.find
now aligns with ES6 spec.- 🛠 Fixed bug with array like objects iterated over with loop = true.
- 🛠 Fixed
String#truncate
not returning primitives. String#repeat
is now aligned more with spec.String#pad
follows suit.- ➕ Added
Array#findFrom
andArray#findIndexFrom
. - ✂ Removed
Range#step
alias. - ✂ Removed
deep
argument fromObject.fromQueryString
and replaced with optional boolean casting.
🐎 Performance Enhancements
- Object.map: up to 682% faster
- Date#format: up to 21,400% faster
- Array#min/max/less/more up to 83% faster
- Enumerable methods like findAll/findIndex/map/any/count/sum/etc.: up to 11,270% faster
- isString/isNumber/isBoolean: up to 77% faster
- isEqual returns up front when === (can be much faster). Many methods use this internally as well.
- Math related functions (and internals that use them): up to 16% faster.
- getRegExpFlags is up to 1000% faster.
- Range#every up to 52% faster for dates, 1500% faster for numbers/strings.
- Array#at and String#at up to 242% faster for single index lookups.
- String#assign up to 30% faster.