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.
When upgrading to a new major version, it's hard to know what changes you will be affected by. This document was meant to help, but now there is also the upgrade script! Just include it immediately after Sugar is loaded, and it will log any method calls that may potentially break!
Drop it in before upgrading to get a general idea of what needs to change, or upgrade and fix as you go!
-
Level: Major
- Callbacks for iterating over object properties are now value first, key second. This includes
Object.each(now renamed toObject.forEach),Object.map,Object.every,Object.find,Object.count,Object.none,Object.sum,Object.average,Object.min,Object.max,Object.least,Object.most, andArray#groupBy.
- Callbacks for iterating over object properties are now value first, key second. This includes
-
Level: Major
String#assignis nowString#format, and behaves very closely to Python's method of the same name. Tokens are now zero based, and start with{0}. Also, errors will be thrown when tokens cannot be matched. Braces can now be escaped by repeating them. Lastly, multiple objects passed will no longer be merged together. Instead either access with new dot syntax (0.prop) or merge together with Object.merge beforehand.
-
Level: Major
Function#fillwas renamed toFunction#partial. Additionally, it no longer acceptsnullas a placeholder. Useundefinedinstead.
-
Level: Major
Object.equalis renamed toObject.isEqualin both the static and instance method types.
-
Level: Major
Object.extendedwas removed in favor of chainables. The equivalent is nownew Sugar.Object(), however the result will be wrapped in a property called.raw. See the docs for more details.
-
Level: Major
Object.mergenow takes an options object instead of a list of arguments. The 3rd argument is now "deep" in the options object, and the 4th is "resolve". Resolver functions will now abort the merge (for a single property) ifundefinedis the return value. To tell the resolver function to continue as normal, return theSugarglobal object instead. Any non-undefined value returned by the function will now resolve the conflict completely and will not continue traversing into it when in "deep" mode. To tell the resolver function to continue with the merge, return the Sugar global object instead.
-
Level: Major
String#hasis now removed in favor ofString#includesto be in compliance with the ES6 spec. The ES6 method only accepts a string as input, however Sugar enhances this method to allow regexes (can be opted-out).
-
Level: Major
Array#includewas removed as it is now identical toArray#add.
-
Level: Major
Array#findAllwas replaced withArray#filterFromIndexin cases that require a start index. For cases without a start index, simply use nativeArray#filter. Additionally, the "index" and "loop" arguments now come before the callback.
-
Level: Major
Array#eachwas replaced withArray#forEachFromIndexin cases that require a start index. For cases without a start index, simply use nativeArray#forEach. Additionally, the "index" and "loop" arguments now come before the callback. For iterating until a return value is passed, useArray#some.
-
Level: Major
Array#findFromandArray#findIndexFromare nowArray#findFromIndexandArray#findIndexFromIndexand exist alongside other "from index" methods with similar naming. Additionally, the "index" and "loop" arguments now come before the callback.
-
Level: Major
Object.findAllwas replaced withObject.filter, which parallelsArray#filterby returning a filtered object.
-
Level: Major
Object.eachwas renamed asObject.forEachto bring it more in line with other object methods. Additionally it no longer allows a return value to break the loop. UseObject.someinstead for this functionality.
-
Level: Major
String#eachwas renamed toString#forEachto bring it more in line with other methods.
-
Level: Major
Date#utcis nowDate#setUTC, and now requires explicitly passingtrueas the first argument to set the flag to true.
-
Level: Major
Date#formatshortcuts ("short", "long", "full", etc) have significantly changed. See the docs for the new formats. Tokensf,fff,izotz, andord, have been replaced withS,SSS,Z, anddoto align better with Moment/LDML.DowandMonwere previously always 3 characters and uppercased. Both of these are now locale dependent, as certain locales may prefer different casing or abbreviation length. Lowercased formatsdowandmonare also locale-dependent in length, but always lowercased.
-
Level: Major
Array#randomizewas renamed toArray#shuffle.
-
Level: Major
Array.createnow only accepts one argument. See the docs for more details or use ES6 methodArray.frominstead. Sugar provides this as a polyfill in the default bundle.
-
Level: Major
Object.watchwas removed. This method was the only part of Sugar that was not 100% compatible in all environments, and was an overly simplistic solution to a difficult problem that others have done better (see discussions around Object.observe and polling). As a quick and dirty solution, this will be made available as a plugin. Also includesObject.unwatch.
-
Level: Major
Function#afterhas changed behavior. Previously it would fire everyntimes. Now it will fire afterncalls. Additionally it will not immediately fire when0is passed.
-
Level: Major
Array#addis now non-destructive. To append to the array in place, useArray#append.
-
Level: Major
Object.toQueryStringno longer uses square bracket syntax by default. To enable this passdeepin the options object which is now the second argument to the function.namespace, which was previously the second argument to this method, is nowprefixin the same options object.
-
Level: Major
Object.fromQueryStringnow performs "smart" conversion of numerals, booleans, and multiple keys by default. To turn this off, passsmart: falsein the options object which is now the second argument to the function. Deep bracket syntax ([]in keys) is now off by defualt but can be enabled withdeepon the options object.
-
Level: Major
RegExp#addFlagandRegExp#removeFlagare nowRegExp#addFlagsandRegExp#removeFlagsand now work on multiple flags at once.
-
Level: Major
Date.past,Date.future,Date.utc.create,Date.utc.past, andDate.utc.futureare all deprecated. Instead, pass an options object as the second argument toDate.createwith the equivalent properties. For example:Date.create('March', { future: true, fromUTC: true, locale: 'ja' }), etc. Additionally, theutcparameter is nowfromUTCand a new parametersetUTChas been added to clear up confusion about what the flag was doing.fromUTCassumes the input to be UTC but the output is a normal Javascript local date.setUTCsets an internal flag which tells Sugar to use utc methods likegetUTCHours.
-
Level: Major
String#startsWithandString#endsWithare now more in compliance with the ES6 spec. They now no longer accept a RegExp (will throw an error) or acaseparameter. If you need to do more complex string checking, useString#matchwith standard regexes instead. Also minor differences in the way the starting/ending positions are coerced may also be present.
-
Level: Major
Object.isNaNwas removed in favor of nativeNumber.isNaN, which Sugar provides a polyfill for.
-
Level: Major
String#normalizewas removed to comply with the ES6 spec. It was also a brute force approach and most likely overkill for most situations. It will be made available as a plugin under the nameString#toAscii.
-
Level: Major
String#capitalizewill now only capitalize the first letter of a string by default. If you want to downcase the rest of the string, pass true for the 1st argument. Capitalizing all words is now the 2nd argument.
-
Level: Major
String#addwas removed and now exists only asString#insert, which it was mainly providing the basis for.
-
Level: Major
Array#all,Array#any,Object.all, andObject.anyaliases were removed to align Sugar more with native methods. If needed, these can still easily be aliased withSugar.Array.alias('all', 'every');.
-
Level: Major
String#paragraphswas removed.
-
Level: Moderate
Object.keysandObject.valuesno longer have callbacks as second arguments. UseObject.forEachfor iteration over an object's properties.
-
Level: Moderate
Number#formatno longer accepts arguments for the thousands separator and decimal point. Instead these can now be set globally using Sugar.Number.thousands() and Sugar.Number.decimal(). These will also be respected by Number#abbr, Number#metric, and Number#bytes as well.
-
Level: Moderate
Number#bytesnow uses powers of 1000 by default instead of powers of 1024. For the old behavior, pass "true" as the 2nd argument (after precision). Further, when using the "binary" flag, units will be standard binary units (KiB, MiB, etc.). For standard units (KB, MB, etc.) pass 'si' for the 3rd argument.
-
Level: Moderate
- Alphanumeric array options are now defined on the global object
Sugarinstead ofArrayitself.
- Alphanumeric array options are now defined on the global object
-
Level: Moderate
Array#atandString#atnow no longer accept enumerated arguments. To get an multiple indexes, pass an array instead.
-
Level: Moderate
Array#atandString#atnow have theirloopargument off by default.
-
Level: Moderate
- Array natural sort options (
AlphanumericSortOrder,AlphanumericSortIgnore, etc) now no longer haveAlphanumericin the name, and are now options that are set by the accessor methodsSugar.Array.getOptionandSugar.Array.setOption. Lastly,AlphanumericSort, which simply exposed Sugar's internal sort algorithm is nowsortCollate.
- Array natural sort options (
-
Level: Moderate
Array#sortBywill now not clone the array by default. This will prevent unnecessary work when it is not needed, however it means that the method is now destructive. Simply usecloneorconcaton the array first for the old behavior.
-
Level: Moderate
Object.selectandObject.rejectnow, when passed an object as a matcher, only check for key existence, not whether values also match or not. To do the "intersect" operation that these methods previously performed,Object.filter,Object.remove, orObject.excludecan instead be used.
-
Level: Moderate
Date#resetnow requires one unit higher when resetting units based on a string. For example, d.reset('day') will now "reset the day", where it's previous behavior was to shift the date to the beginning of the month. Default is also shifted so no change should be necessary when resetting the time.
-
Level: Moderate
Array#subtract,Array#union, andArray#intersectall no longer accept multiple arguments. Simply chain them if more than one argument is needed.
-
Level: Moderate
Array#min,Array#max,Array#least,Array#most,Object.min,Object.max,Object.least,Object.most: Theallargument is now passed beforemapas an optional argument. This will always put the function callback as the last argument.
-
Level: Minor
Date#relativeargumentsfnandlocaleCodeare now reversed (localeCodefirst). As this method was previously acceptinglocaleCodeas a single argument anyway, this change will only have have an effect if both arguments are used together.
-
Level: Minor
Array#removeandArray#excludeno longer accept enumerated paramters. To remove multiple elements, depending on the type a regex or function may be used. Otherwise the method must be called multiple times.
-
Level: Minor
Date.createno longer accepts enumerated parameters (2001, 5, 31, ...). Use the normal date constructor instead.
-
Level: Minor
Number#metricnow uses a "units" string instead of the "limit" argument, which allows a more flexible, intuitive way to define custom units and min/max ranges. Check the docs for more about this.
-
Level: Minor
Date#setnow rewinds dates that have accidentally traversed into a new month, such as setting{ month: 1 }onJanuary 31st. This behavior was previously only onadvanceandrewind.
-
Level: Minor
Date.SugarNewDateis nowSugar.Date.newDateInternal. This method is always on theSugarglobal (notDate).
-
Level: Minor
Object.map,Object.each, (nowObject.forEach) andObject.sizewere moved to the Object module from the Array module. If you were using these methods and making custom builds you may have to include the Object module now as well.
-
Level: Minor
Date#unitSince(Date#hoursSince, etc) now assumes that the passed in format is UTC if the context date is also flagged as UTC (if you're usingsetUTC). This behavior can be overriden by passing{ fromUTC: false }to these methods.
-
Level: Minor
Object.clonenow clones both non-enumerable properties if they exist and the attribute accessors "get" and "set".
-
Level: Minor
Array#isEmptynow does a simple check if the length is zero. To also check ifundefined,null, orNaNare present, useArray#compactfirst.
-
Level: Minor
Object.fromQueryStringnow returns a plain object. If you want what was previously an extended object, use a chainable on the result withnew Sugar.Object().
-
Level: Minor
String#stripTagsandString#removeTagsno longer accept enumerated arguments. Simply pass an array of tags to remove multiple.
-
Level: Minor
String#titleizewas moved from the Inflections module to String.
-
Level: Minor
String.Inflectorhas been removed from the inflections module in favor of the static methodsaddAcronym,addPlural, andaddHuman.
-
Level: Minor
String#uptoandString#downtonow accept "step", which was previously the third argument, as an optional second argument.
-
Level: Very Minor
Array#map,Array#unique,Array#groupBy,Array#min,Array#max,Array#least,Array#most,Array#sortBy: Mapping shortcut strings now accept deep matchers with the dot.token. If you have objects that use.in the keys and are using these methods, be careful as this now makes the methods try to go deep. Pass a function instead to map as before.
-
Level: Very Minor
- Some minor behavior changes around the way
String#removeTagsworks on malformed html. Unmatched closing tags are removed.
- Some minor behavior changes around the way
-
Level: Very Minor
String#hankakuandString#zenkakunow don't take multiple arguments for modes. Just mix them together in the first argument as a string. See docs for more.
- Level: Minor
Object.selectandObject.rejectnow will match values when passed an object. This means that if you pass{foo:'bar'}, it will no longer match if the value offooin your object is notbar. Previously it would match simply if the key existed.
-
Level: Major
pad,padLeft, andpadRightnow pad to the exact character. This means thatpadLeft(20)will produce a string exactly 20 characters long, instead of adding 20 characters worth of padding to the left side of the string as before. You can useString#repeatfor the same effect as the old functionality.
-
Level: Major
Object.fromQueryStringnow does not cast values by default. This means that all values in the resulting object are strings, unlesscastBooleanis true, which will cast boolean values of "true" and "false" only. Digits are no longer cast to numbers at all. Additionally, the "deep" argument is now removed. Deep parameters will always be parsed if they can be.
-
Level: Major
Function#lazynow has different arguments.limitis now the third argument withimmediatetaking its place as second. Additionallyimmediate-- which determines whether lazy functions are executed immediately then lock or lock then execute after a timeout -- is now false by default.
-
Level: Major
- Date range methods
eachDay,eachMonth, etc. are deprecated in favor of the syntaxevery("day"), etc.
- Date range methods
-
Level: Major
- Date range method
durationis deprecated in favor ofspan. Additionally it will add 1 to the duration to include the starting number itself. In effect for date ranges this means thatdurationwill be 1 ms longer.
- Date range method
-
Level: Major
Range#stepalias was removed. UseRange#everyinstead.
-
Level: Major
- Date formatting tokens
zandzzare nowZandZZ. Additionallyzzzwas removed.
- Date formatting tokens
-
Level: Moderate
Array#findnow works according to the ES6 spec. This means that it will no longer take afromIndexorlooparguments. Instead, the second argument is the context in which the function matcher will be run. If you need the previous functionality, useArray#findFromandArray#findIndexFrominstead.
-
Level: Moderate
Array.sortBynow performs a natural sort by default. This means numbers (any consecutive numbers, so this will include currency formatting, etc.) will sort as numbers, (2 before 100). If you do not want this behavior, set the flagArray.AlphanumericSortNaturaltofalse.
-
Level: Moderate
Object.clonenow will error if being called on a user-created class instance or host object (DOM Elements, Events, etc). A number of complex issues tie in here, but in the end it is unreliable to callcloneon an object that is not a standard data types as 1) hidden properties cannot be cloned 2) the original arguments to the constructor cannot be known 3) even if they could be known the issue of whether or not the constructor should actually be called again is not clear.
-
Level: Moderate
- The
splitargument was removed fromString#truncate. For truncating without splitting words, useString#truncateOnWordinstead. Argument position is adjusted accordingly.
- The
-
Level: Moderate
- Class instances are now internally matched by reference only. This means that
Object.equal(new Person, new Person)isfalse. This was in fact the original intended behavior but a bug had not been closed here leading to it not actually beingfalse. Although a case can be made for matching class instances by value, in the end it is too expensive and tricky to distinguish them from host objects, which should never be matched by value. Instead it is better to check for equality of class instances on a unique identifier or the like.
- Class instances are now internally matched by reference only. This means that
-
Level: Moderate
Object.isObjectno longer returns true for class instances for the same reasons listed above. This also was intended behavior but was defective.
-
Level: Moderate
String#normalizeis now deprecated, but still available as a separate script in thelib/pluginsdirectory.
-
Level: Moderate
- Date ranges are now their own module (the "range" module), and are not dependent on the Date module, and work on numbers and strings as well.
-
Level: Minor
- Enumerable methods on object will now coerce primitive types. This means that
Object.findAll('foo')will now treat'foo'asnew String('foo'). This is reversed from the previous behavior which would error on primitive types and coerce objects to primitive types where possible.
- Enumerable methods on object will now coerce primitive types. This means that
-
Level: Minor
String#capitalizepassing theallflag now will not capitalize after an apostrophe.
-
Level: Very Minor
- Date ranges that have an end that is less than the start are now no longer considered invalid, and can be iterated across in exactly the same manner. This means that ranges can now be iterated in reverse and .start and .end are no longer equivalent to .min and .max.
-
Level: Very Minor
- Removed
Number#uptoandNumber#downtowill now work on inverse ranges. In other words (1).downto(5) if represented as an array will now produce [1,2,3,4,5] even though 1 is less than 5 and the operator was "downto". It will also step through the range accordingly.
- Removed
-
Level: Very Minor
- Passing a regex to array matching methods like
findAllwill now match it directly against the element in the array, regardless of whether or not the matched element is a string or not. This makes the logic more straightforward but it also means that it will stringify the element before attempting to match. If, for example, you have instances of classes in the array and the regex is /t/, the /t/ will return true for that element as it will match the stringified "[object Object]" of the instance, which is likely not what you want, so caution is needed here.
- Passing a regex to array matching methods like
-
Level: Very Minor
- Passing
nullto.mapwill now have the same effect asundefined(or no arguments), that is, no mapping will occur. This will apply to any method making use of the internaltransformArgument, soArray#min,Array#max, andArray#groupByare affected as well.
- Passing
-
Level: Very Minor
String#pad/padLeft/padRightwill now raise an error on padding to a negative number. Conversely, they will no longer raise an error on undefined/null/NaN.
Version 1.4.0 improves future-compatibility by ensuring that browser updates do not cause breakages going forward. Upgrading is highly recommended, however as there are also many API changes, this patch was created for older versions. Just drop it in after the main script.
- Level: Major
- Removed
String#namespace.
- Removed
-
Level: Major
- Renamed
Date#getWeekandDate#setWeektoDate#getISOWeekandDate#setISOWeek.
- Renamed
-
Level: Very Minor
- Object.clone will now preserve a date's internal utc flag when set.
-
Level: Major
String#startsWithandString#endsWithnow accept different arguments to better align them with the Harmony proposal of the same name. The second argument is now the "position" that limits where the string starts/ends, and the "case" flag indicating case sensitivity is now pushed to the 3rd argument.
-
Level: Major
- Enumerable object methods are now included when using
Object.extend()making it that much more dangerous, especially as generic methods likecountare now defined on the Object prototype. If you use this method, make sure you are in the habit of usinghasOwnPropertywhen checking for presence inside a hash (probably not a bad idea anyway). Also note that Sugar itself has a number of areas that may exhibit unexpected behavior when this method is applied. Please report if you find any.
- Enumerable object methods are now included when using
-
Level: Moderate
- Aliases on dates such as
daysAgowill now count "past" an integer instead of rounding. This means thatDate.create('23 hours ago').daysAgo()will now be0. There is however a small margin of error (roughly 0.1%) that will trigger a round up, which is higher for months, which have a more vague definition and a higher margin for error.
- Aliases on dates such as
-
Level: Very Minor
- Float values should be properly parsed in
Object.fromQueryString, meaning IP addresses and the like will now parse as strings instead of truncated numbers.
- Float values should be properly parsed in
-
Level: Very Minor
- NaN is no longer true for
isOdd.
- NaN is no longer true for
-
Level: Very Minor
- Date parsing now only allows a maximum of 59 for minutes and seconds.
- Level: Very Minor
Array.createnow properly creates arrays from objects.
- Level: Minor
Date.createwill no longer set the UTC flag on dates created from an ISO string with the "Z" flag. This can be considered a bug introduced in the last release. The "Z" flag indicates that a date is in UTC time, but should not serve as an indication that the date should further be manipulated as UTC, only as a cue when parsing. If you want the date to actually behave as UTC (internally call UTC methods), then you need to explicitly set withDate#utc(true)now.
-
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: Major
Date#toUTCdeprecated. Previously, this method would subtract the timezone offset of the date, providing a pseudo-utc date. This was a very primitive way of handling the challenge of manipulating utc dates and had drawbacks such as subsequent date manipulations resetting to a localized time. This is now deprecated in favor ofDate#utc, which simply sets an internal flag that will tell Sugar to use utc-based date methods or not.Date#utcwill NOT manipulate the time in any way. To create a utc-based date that is set to utc time, a flag has been added toDate#create, and other creation methods likeDate#futureandDate#pastto set the utc flag before parsing out the date.
-
Level: Major
Date#setUTCdeprecated. Instead, simply set the utc flag usingDate#utcor passingtrueas the third argument toDate#create. After this point, utc-based methods will be used internally, making this method unnecessary.
-
Level: Major
Date#setUTCWeekdeprecated. Set the utc flag and useDate#setWeekinstead.
-
Level: Major
Date#getUTCWeekdeprecated. Set the utc flag and useDate#getWeekinstead.
-
Level: Major
Date#setUTCWeekdaydeprecated. Set the utc flag and useDate#setWeekdayinstead.
-
Level: Minor
Number#timesnow returns an array which is the collected return values of the function passed.
-
Level: Minor
Date#clonewill now preserve the utc flag.
-
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: Very Minor
Date#setWeekdaynow returns a timestamp instead ofundefined.
-
Level: Major
- Date locales are now moved into a separate module. This means that now with the default download, 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#mostnow return a single value instead of an array. If you need to get "all min" or "all max" values, then passtrueas the second argument to these methods.
-
Level: Major
Array#hasis deprecated. UseArray#someorArray#anyinstead.
-
Level: Major
String#toDateis deprecated. UseDate.createinstead.
-
Level: Major
String#add,String#insert,Array#add, andArray#insertnow 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.isEmptywill 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#groupByno longer returns extended objects. UseObject.extendedon 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#capitalizewith 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#truncatearguments changed.ellipsis("..."by default) is now the last argument of four. Second argument is nowsplitwhich is true by default, so the method will behave like standard truncate methods by default.fromadded as the third parameter and determines where to truncate. Can be"right"(default),"left", or"middle".
-
Level: Major
Function#debounceno longer has an argumentwait. Equivalent function is nowFunction#throttle(no arguments).fn.debounce(100, false)is nowfn.throttle(100).
-
Level: Minor
Object.isObjectnow returnstruefor 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.
resolveis now the 4th parameter anddeepis now 3rd. - When using extended objects, this are now 2nd and 3rd parameters.
deepis 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
Objectas 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 whosefooproperty 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
falsefor primitive types likenulland 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.