Comparing version 1.4.0 to 1.4.1
@@ -5,9 +5,17 @@ ## Caution! | ||
Think of it as a pruned Changelog with the most front-facing changes surfaced. | ||
If your code breaks on update check here first! | ||
If your code breaks on update check here first! Read all the ones that are greater than the version you are migrating from. | ||
### Note about versions < 1.3.9 | ||
Read all the ones that are greater than the version you are migrating from. | ||
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](https://raw.github.com/andrewplummer/Sugar/master/lib/patches/sugar-es6-patch.min.js) was created for older versions. Just drop it in after the main script. | ||
v1.4.1+ | ||
======= | ||
- Level: Minor | ||
- `Object.select` and `Object.reject` now will match values when passed an object. This means that if you pass `{foo:'bar'}`, it will no longer match if the value of `foo` in your object is not `bar`. Previously it would match simply if the key existed. | ||
v1.4.0+ | ||
@@ -47,3 +55,3 @@ ======= | ||
- Level: Moderate | ||
- The `split` argument was removed from `String#truncate`. For truncating without splitting words, use `String#truncateOnWords` instead. Argument position is adjusted accordingly. | ||
- The `split` argument was removed from `String#truncate`. For truncating without splitting words, use `String#truncateOnWord` instead. Argument position is adjusted accordingly. | ||
@@ -50,0 +58,0 @@ - Level: Moderate |
@@ -0,1 +1,11 @@ | ||
v1.4.1 | ||
====== | ||
### API Changes ### | ||
- Fix for Object.select/reject not performing value match. (Issue #362) | ||
- Fix for Object.merge not properly merging when target object isn't an object (Issue #365) | ||
- Fix for development script not running properly in meteor (Issue #361) | ||
v1.4.0 | ||
@@ -2,0 +12,0 @@ ====== |
@@ -337,6 +337,6 @@ | ||
var HalfWidthZeroCode = 48; | ||
var HalfWidthNineCode = 57; | ||
var FullWidthZeroCode = 65296; | ||
var FullWidthNineCode = 65305; | ||
var HalfWidthZeroCode = 0x30; | ||
var HalfWidthNineCode = 0x39; | ||
var FullWidthZeroCode = 0xff10; | ||
var FullWidthNineCode = 0xff19; | ||
@@ -343,0 +343,0 @@ var HalfWidthPeriod = '.'; |
@@ -103,10 +103,12 @@ | ||
var HALF_WIDTH_TO_FULL_WIDTH_TRAVERSAL = 65248; | ||
var widthConversionRanges = [ | ||
{ type: 'a', shift: 65248, start: 65, end: 90 }, | ||
{ type: 'a', shift: 65248, start: 97, end: 122 }, | ||
{ type: 'n', shift: 65248, start: 48, end: 57 }, | ||
{ type: 'p', shift: 65248, start: 33, end: 47 }, | ||
{ type: 'p', shift: 65248, start: 58, end: 64 }, | ||
{ type: 'p', shift: 65248, start: 91, end: 96 }, | ||
{ type: 'p', shift: 65248, start: 123, end: 126 } | ||
{ type: 'a', start: 65, end: 90 }, | ||
{ type: 'a', start: 97, end: 122 }, | ||
{ type: 'n', start: 48, end: 57 }, | ||
{ type: 'p', start: 33, end: 47 }, | ||
{ type: 'p', start: 58, end: 64 }, | ||
{ type: 'p', start: 91, end: 96 }, | ||
{ type: 'p', start: 123, end: 126 } | ||
]; | ||
@@ -148,3 +150,3 @@ | ||
n += r.start; | ||
setWidthConversion(r.type, chr(n), chr(n + r.shift)); | ||
setWidthConversion(r.type, chr(n), chr(n + HALF_WIDTH_TO_FULL_WIDTH_TRAVERSAL)); | ||
}); | ||
@@ -151,0 +153,0 @@ }); |
@@ -66,7 +66,7 @@ | ||
function matchKey(key, match) { | ||
function matchInObject(match, key, value) { | ||
if(isRegExp(match)) { | ||
return match.test(key); | ||
} else if(isObjectType(match)) { | ||
return hasOwnProperty(match, key); | ||
return match[key] === value; | ||
} else { | ||
@@ -82,3 +82,3 @@ return key === string(match); | ||
flattenedArgs(args, function(arg) { | ||
if(matchKey(key, arg)) { | ||
if(matchInObject(arg, key, value)) { | ||
match = true; | ||
@@ -257,3 +257,3 @@ } | ||
'merge': function(target, source, deep, resolve) { | ||
var key, val, goDeep; | ||
var key, sourceIsObject, targetIsObject, sourceVal, targetVal, conflict, result; | ||
// Strings cannot be reliably merged thanks to | ||
@@ -264,28 +264,29 @@ // their properties not being enumerable in < IE8. | ||
if(!hasOwnProperty(source, key) || !target) continue; | ||
val = source[key]; | ||
goDeep = deep && isObjectType(val); | ||
// Conflict! | ||
if(isDefined(target[key])) { | ||
// Do not merge. | ||
if(resolve === false && !goDeep) { | ||
continue; | ||
} | ||
// Use the result of the callback as the result. | ||
sourceVal = source[key]; | ||
targetVal = target[key]; | ||
conflict = isDefined(targetVal); | ||
sourceIsObject = isObjectType(sourceVal); | ||
targetIsObject = isObjectType(targetVal); | ||
result = conflict && resolve === false ? targetVal : sourceVal; | ||
if(conflict) { | ||
if(isFunction(resolve)) { | ||
val = resolve.call(source, key, target[key], source[key]) | ||
// Use the result of the callback as the result. | ||
result = resolve.call(source, key, targetVal, sourceVal) | ||
} | ||
} | ||
// Deep merging. | ||
if(goDeep) { | ||
if(isDate(val)) { | ||
val = new date(val.getTime()); | ||
} else if(isRegExp(val)) { | ||
val = new regexp(val.source, getRegExpFlags(val)); | ||
// Going deep | ||
if(deep && (sourceIsObject || targetIsObject)) { | ||
if(isDate(sourceVal)) { | ||
result = new date(sourceVal.getTime()); | ||
} else if(isRegExp(sourceVal)) { | ||
result = new regexp(sourceVal.source, getRegExpFlags(sourceVal)); | ||
} else { | ||
if(!target[key]) target[key] = array.isArray(val) ? [] : {}; | ||
object.merge(target[key], source[key], deep, resolve); | ||
if(!targetIsObject) target[key] = array.isArray(sourceVal) ? [] : {}; | ||
object.merge(target[key], sourceVal, deep, resolve); | ||
continue; | ||
} | ||
} | ||
target[key] = val; | ||
target[key] = result; | ||
} | ||
@@ -292,0 +293,0 @@ } |
@@ -140,3 +140,21 @@ | ||
extend(string, true, false, { | ||
/*** | ||
* @method repeat([num] = 0) | ||
* @returns String | ||
* @short Returns the string repeated [num] times. | ||
* @example | ||
* | ||
* 'jumpy'.repeat(2) -> 'jumpyjumpy' | ||
* 'a'.repeat(5) -> 'aaaaa' | ||
* 'a'.repeat(0) -> '' | ||
* | ||
***/ | ||
'repeat': function(num) { | ||
num = checkRepeatRange(num); | ||
return repeatString(this, num); | ||
} | ||
}); | ||
extend(string, true, function(reg) { return isRegExp(reg) || arguments.length > 2; }, { | ||
@@ -190,3 +208,2 @@ | ||
extend(string, true, true, { | ||
@@ -805,18 +822,2 @@ | ||
/*** | ||
* @method repeat([num] = 0) | ||
* @returns String | ||
* @short Returns the string repeated [num] times. | ||
* @example | ||
* | ||
* 'jumpy'.repeat(2) -> 'jumpyjumpy' | ||
* 'a'.repeat(5) -> 'aaaaa' | ||
* 'a'.repeat(0) -> '' | ||
* | ||
***/ | ||
'repeat': function(num) { | ||
num = checkRepeatRange(num); | ||
return repeatString(this, num); | ||
}, | ||
/*** | ||
* @method toNumber([base] = 10) | ||
@@ -823,0 +824,0 @@ * @returns Number |
{ | ||
"name": "sugar", | ||
"version": "1.4.0", | ||
"version": "1.4.1", | ||
"description": "A Javascript library for working with native objects.", | ||
@@ -12,3 +12,4 @@ "keywords": ["functional", "utility", "ender"], | ||
"engines" : {"node" : ">= 0.4.0"}, | ||
"scripts": {"test": "node test/environments/node/test.js"} | ||
"scripts": {"test": "node test/environments/node/test.js"}, | ||
"license": "MIT" | ||
} |
@@ -11,5 +11,6 @@ # Sugar | ||
If you are upgrading from an older version, please have a look at `CAUTION.md` which is a vetted changelog | ||
If you are upgrading from an older version, please have a look at [`CAUTION.md`](https://github.com/andrewplummer/Sugar/blob/master/CAUTION.md) which is a vetted changelog | ||
that details the severity of what has changed, and (sometimes) strategies for migrating. | ||
Going through this before you upgrade can make the process a lot less painful! | ||
Also please refer there for notes about a patch that applies to versions prior to v1.3.9. | ||
@@ -16,0 +17,0 @@ |
@@ -245,3 +245,3 @@ test('Object', function () { | ||
equal(Object.merge({ a:null }, { a:2 }), { a:2 }, 'Object.merge | null properties are not overwritten'); | ||
equal(Object.merge({ a:undefined }, { a:2 }, false, false), { a:2 }, 'Object.merge | false |existing but undefined properties are overwritten'); | ||
equal(Object.merge({ a:undefined }, { a:2 }, false, false), { a:2 }, 'Object.merge | false | existing but undefined properties are overwritten'); | ||
equal(Object.merge({ a:null }, { a:2 }, false, false), { a:null }, 'Object.merge | false | null properties are not overwritten'); | ||
@@ -873,3 +873,3 @@ equal(Object.merge([{ foo:'bar' }], [{ moo:'car' }], true, true), [{ foo:'bar',moo:'car' }], 'Object.merge | can merge arrays as well'); | ||
testClassAndInstance('select', obj, [{ one: 1 }], { one: 1 }, 'Object.select | comparing object'); | ||
testClassAndInstance('select', obj, [{ one: 'foobar' }], { one: 1 }, 'Object.select | comparing object with different values'); | ||
testClassAndInstance('select', obj, [{ one: 'foobar' }], {}, 'Object.select | should not match with different values'); | ||
testClassAndInstance('select', obj, [{}], {}, 'Object.select | empty object'); | ||
@@ -898,3 +898,3 @@ testClassAndInstance('select', obj, [[/^o/, /^f/]], { one: 1, four: 4, five: 5 }, 'Object.select | complex nested array of regexes'); | ||
testClassAndInstance('reject', obj, [{ one: 1 }], { two: 2, three: 3, four: 4, five: 5 }, 'Object.reject | comparing object'); | ||
testClassAndInstance('reject', obj, [{ one: 'foobar' }], { two: 2, three: 3, four: 4, five: 5 }, 'Object.reject | comparing object with different values'); | ||
testClassAndInstance('reject', obj, [{ one: 'foobar' }], obj, 'Object.reject | comparing object with different values'); | ||
testClassAndInstance('reject', obj, [{}], obj, 'Object.reject | empty object'); | ||
@@ -987,2 +987,8 @@ testClassAndInstance('reject', obj, [[/^o/, /^f/]], { two: 2, three: 3 }, 'Object.reject | complex nested array of regexes'); | ||
// Issue #365 Object.merge can skip when source is object and target is not. | ||
equal(Object.merge({a:''}, {a:{b:1}}, true), {a:{b:1}}, 'Object.merge | source object wins with empty string'); | ||
equal(Object.merge({a:'1'}, {a:{b:1}}, true), {a:{b:1}}, 'Object.merge | source object wins with number as string'); | ||
}); |
@@ -14,7 +14,7 @@ | ||
Array.create = overridingFunction; | ||
Array.prototype.findAll = overridingFunction; | ||
Array.prototype.all = overridingFunction; | ||
Array.prototype.add = overridingFunction; | ||
Array.prototype.groupBy = overridingFunction; | ||
Array.create = overridingFunction; | ||
Array.prototype.findAll = overridingFunction; | ||
Array.prototype.all = overridingFunction; | ||
Array.prototype.add = overridingFunction; | ||
Array.prototype.groupBy = overridingFunction; | ||
@@ -61,1 +61,10 @@ String.extend = overridingFunction; | ||
// ES6 | ||
// Array.prototype.find = overridingFunction; | ||
// Array.prototype.findIndex = overridingFunction; | ||
// String.prototype.repeat = overridingFunction; | ||
// String.prototype.normalize = overridingFunction; |
Sorry, the diff of this file is too big to display
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
1731220
85
32976
98
2