1.3.7
◀Back | Minified | Changelog | Cautionlog2012-11-29
select/reject
Analogous to Underscore's Object.pick and Object.omit, Sugar now has Object.select and Object.reject. These methods do pretty much what you would expect from the names -- returning a new object that contains properties that match/do not match the keys passed -- but have some special hidden features. Multiple keys may be specified through enumerated arguments, or also by passing an array of keys. Additionally, regexes will match against the key. And finally, passing another object will result in a match if that object also has the given key. This in effect will produce something like an "intersect" operation in the case of select, and a "subtract" operation in the case of reject. Some examples:
As "hash" methods, select and reject are most powerful when used in extended objects (Sugar's answer to hashes):
Other changes
String#startsWith and String#endsWith were modified to allow a second argument that is the position from which startsWith or to which endsWith the operation will be performed on. This is to bring in line these methods with those of the Harmony proposals of the same name. The "case sensitivity" flag that was previously the second argument is now the third, and as always Sugar will detect when/if to defer to the native method if available.
Fixes
- Fix for Date.create not preserving the UTC flag when the source is also a date.
- Object.clone on arrays with the "deep" flag set to true should create a deep clone of the array.
- Array#min/max should throw an error when comparing to undefined.
- Fix for dates that fallback to native parsing when forcing UTC flag.
- Date#since/fromNow aliases will now count "past" integers instead of rounding.