Here you will find points of caution when updating Sugar to a new version. Think of it as a pruned Changelog with the most front-facing changes surfaced. If your code breaks on update check here first!
Read all the ones that are greater than the version you are migrating from.
-
Level: Major
- Array methods that allow fuzzy matching on an object (
findAll
,filter
,some
, etc.) as well asunique
,intersect
,union
, andsubtract
, will now match by reference unless certain conditions are met. Most notably this means that arrays of functions as well as arrays of host objects (DOM elements, etc.) will now only match elements that are strictly true by reference (===
). If you are using arrays of host objects or functions (event handlers and the like), use caution upgrading. Other kinds of arrays such as primitives (strings, numbers, etc) as well as object literals and instances of user-defined objects should not be affected.
- Array methods that allow fuzzy matching on an object (
-
Level: Minor
- Array methods matching an empty object
{}
will now return true instead of false against another empty object.
- Array methods matching an empty object
-
Level: Major
- Date locales are now moved into a separate package. This means that now with the default download package, setting the date locale to anything other than English will throw an error. If you require locales other than English, please include them from the customize page.
-
Level: Major
Array#min
,Array#max
,Array#least
, andArray#most
now return a single value instead of an array. If you need to get "all min" or "all max" values, then passtrue
as the second argument to these methods.
-
Level: Major
Array#has
is deprecated. UseArray#some
orArray#any
instead.
-
Level: Major
String#toDate
is deprecated. UseDate.create
instead.
-
Level: Major
String#add
,String#insert
,Array#add
, andArray#insert
now consider negative indexes to be the same as built-inArray#slice
. This means that adding 'd' to 'abc' at index -1 now results in 'abdc' instead of 'abcd'.
-
Level: Major
- Date parsing is now scoped by locale. Previously setting a locale would add all its formats into a common pool that would match from that point on. Now the locale must be either be set beforehand
Date.setLocale('fr')
or explicitly passedDate.create('...', 'fr')
. The exception to this are numeric formats which are core formats and will parse in any locale.
- Date parsing is now scoped by locale. Previously setting a locale would add all its formats into a common pool that would match from that point on. Now the locale must be either be set beforehand
-
Level: Minor
- Extended objects that are otherwise identical to non-extended counterparts are now considered equal by
Object.equal
.
- Extended objects that are otherwise identical to non-extended counterparts are now considered equal by
-
Level: Minor
Object.isEmpty
will now error when passed a non-object. This includes object versions of primitives like strings, numbers, and booleans.
-
Level: Minor
- Default date output format
date.format()
now includes the time. Previously this was just the date.
- Default date output format
-
Level: Minor
Array#groupBy
no longer returns extended objects. UseObject.extended
on the result if you need this.
-
Level: Minor
- Unrecognized locale codes will now simply produce an invalid date instead of throwing an error. Likewise, fully qualified locale codes ('it_IT') will fall back to 2 character codes ('it') before giving up.
-
Level: Very Minor
- Array methods using fuzzy matching (findAll, remove, etc.) now match instances of classes as well as plain objects.
-
Level: Very Minor
String#capitalize
with the first argument astrue
(capitalize all words) will now capitalize any letter whose previous letter could not be capitalized. Previously only words after spaces were counted.
-
Level: Major
String#truncate
arguments changed.ellipsis
("..."
by default) is now the last argument of four. Second argument is nowsplit
which is true by default, so the method will behave like standard truncate methods by default.from
added as the third parameter and determines where to truncate. Can be"right"
(default),"left"
, or"middle"
.
-
Level: Major
Function#debounce
no longer has an argumentwait
. Equivalent function is nowFunction#throttle
(no arguments).fn.debounce(100, false)
is nowfn.throttle(100)
.
-
Level: Minor
Object.isObject
now returnstrue
for extended objects.
-
Level: Minor
- Object.equal and its instance method form "equals" is now considered "egal". This means that, for example, new String('w') will NOT be equal to 'w', etc. Previously equal was nearly egal, but not quite, so this should only affect very small edge cases. This now means that Sugar will match Underscore's _.isEqual method 100% of the time with the only exception being custom "isEqual" methods that Underscore checks explicitly.
-
Level: Very Minor
- Object.merge will now merge properties of non-objects like functions.
-
Level: Major
- String#compare, Number#compare, and Date#compare are deprecated
-
Level: Major
- Object.merge params are swapped.
resolve
is now the 4th parameter anddeep
is now 3rd. - When using extended objects, this are now 2nd and 3rd parameters.
deep
is now false by default.
- Object.merge params are swapped.
-
Level: Minor
- Array#sortBy now exhibits more sensible behavior when sorting on strings.
- Level: Very Minor
- Extended objects now keep their "Hash" constructor (which is internal) so they no longer have
Object
as their constructor. If you are doing instanceof checks here this may break (which you shouldn't be doing anyway)
- Extended objects now keep their "Hash" constructor (which is internal) so they no longer have
-
Level: Major
- Array methods now use "fuzzy object matching" when passing an object. As an example,
arr.find({ foo: 'bar' })
would previously only match an identical object, now it will match any object whosefoo
property isbar
. Additionally, note that passing regexes and functions will be used to match (regexes match against strings, functions are callbacks that returntrue
/false
), not compared directly. This applies to the following array methods:every
,some
,filter
,find
,findAll
,findIndex
,remove
,none
,count
, andexclude
.
- Array methods now use "fuzzy object matching" when passing an object. As an example,
-
Level: Major
- Object.sugar renamed to Object.restore. However Object.sugar() equivalent is now Object.extend().
-
Level: Minor
- Object.merge now also merges undefined properties.
-
Level: Minor
- Function#after will now call a method immediately if the passed value is
0
.
- Function#after will now call a method immediately if the passed value is
-
Level: Very minor
- Object.isEmpty will now properly report
false
for primitive types likenull
and empty strings.
- Object.isEmpty will now properly report
-
Level: Major
- Object.merge no longer merges an arbitrary number of arguments. Use extended objects and chaining instead.
-
Level: Minor
- Array#remove and Array#exclude now no longer accept an arbitrary number of arguments. Pass only 1 argument to these methods (may be a nested array).
-
Level: Major
- Object.equals renamed to Object.equal.
-
Level: Major
- Number#format "thousands" and "decimal" parameters are now pushed to the 2nd and 3rd parameters, adding a "place" for the decimal as the 1st.
-
Level: Minor
- A few tokens were removed from Date#format. See sugarjs.com/dates for a list of currently accepted tokens.
-
Level: Minor
- Function#lazy now executes, then waits as opposed to waiting, then executing.
-
Level: Minor
- Array#sortBy is now no longer destructive, so you will need to set the variable explicitly.
-
Level: Major
- String#normalize is removed, but now available in the Inflections module, available at sugarjs.com/customize.
-
Level: Major
- String#is/hasArmenian, is/hasBopomofo, is/hasEthiopic, and is/hasGeorgian deprecated.
-
Level: Minor
- Passing a second parameter to Date#set now no longer resets only the time, but also any unit less specific than the most specific one set. So if the object
{ hours: 5 }
is passed with the second parametertrue
, minutes, seconds, and milliseconds will be reset.
- Passing a second parameter to Date#set now no longer resets only the time, but also any unit less specific than the most specific one set. So if the object
-
Level: Minor
- Passing "relative" as the format to Date#format is now deprecated, and instead Date#relative.
-
Level: Minor
- Date.allowVariant deprecated in favor of the locale system. Any locale that is not 'en' or 'en-US' will use variants when ambiguities exist.
-
Level: Very minor
- Date#format token suffixes " short", and " pad" deprecated.
-
Level: Very minor
- When passing a function to Date#format or Date#relative, the "dir" parameter is now deprecated. Instead the milliseconds argument has a sign directly on it.
-
Level: Major
- Array#split deprecated.
-
Level: Major
- String#toObject is now Object.fromQueryString.
-
Level: Major
- Function.lazy is now Function#lazy and is called directly on function instances.
-
Level: Major
- Function#defer is now simply Function#delay with no arguments.
-
Level: Moderate
- Object.clone is now shallow by default.
-
Level: Major
- Array#each is no longer an alias of Array#forEach and now has its own behavior including a 2nd parameter for the start index, 3rd parameter for looping from the beginning, returning the array, allowing returning false to break the loop, passing the array as scope to the callback, and support for sparse arrays.
-
Level: Major
- Array#eachFromIndex deprecated.
-
Level: Major
- Array#removeAtIndex renamed to Array#removeAt.
-
Level: Major
- Array#collect deprecated.
-
Level: Major
- Array#shuffle deprecated.
-
Level: Major
- String#titleize deprecated. It is now available again as of v1.2 in the Inflections module, available at sugarjs.com/customize.
-
Level: Major
- String#pad/padLeft/padRight changed argument order to padding first and number second.
-
Level: Moderate
- Array#indexOf/lastIndexOf now performs a simple
===
equality check instead of a deep recursive property check.
- Array#indexOf/lastIndexOf now performs a simple
-
Level: Minor
- String#repeat will now return a blank string on numbers less than 1.
-
Level: Minor
- String#dasherize and String#underscore now strip whitespace.
- Level: Major
- Object.create changed to Object.extended.