Skip to content

Commit

Permalink
[#39] null as forced default value
Browse files Browse the repository at this point in the history
  • Loading branch information
nagarajanchinnasamy committed Sep 16, 2017
1 parent 291a524 commit 564371f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/object-mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function _map(fromObject, toObject, propertyMap, propertyKeys) {
function _mapKey(fromObject, fromKey, toObject, toKey) {
var fromValue
, restToKeys
, _default = null
, _default // = null
, transform
;

Expand All @@ -87,14 +87,14 @@ function _mapKey(fromObject, fromKey, toObject, toKey) {
}

if (toKey instanceof Object && Object.getPrototypeOf(toKey) === Object.prototype) {
_default = toKey.default || null;
_default = toKey.default; // || null;
transform = toKey.transform;
toKey = toKey.key;
}

if (Array.isArray(toKey)) {
transform = toKey[1];
_default = toKey[2] || null;
_default = toKey[2]; // || null;
toKey = toKey[0];
}

Expand All @@ -103,7 +103,7 @@ function _mapKey(fromObject, fromKey, toObject, toKey) {
}

fromValue = getKeyValue(fromObject, fromKey);
if (typeof fromValue === 'undefined' || fromValue === null) {
if (typeof fromValue === 'undefined') { // || fromValue === null) {
fromValue = _default;
}

Expand Down
2 changes: 2 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1653,6 +1653,8 @@ test('original various tests', function (t) {
t.deepEqual(result, expected, 'override sku');

obj["inventory"] = null;
map["inventory.onHandQty"] = {key: ["Envelope.Request.Item.Inventory?", null, null]};
map["inventory.replenishQty"] = {key: ["Envelope.Request.Item.RelpenishQuantity?", null, null]};
expected.Envelope.Request.Item.Inventory = null;

result = merge(obj, {}, map);
Expand Down

0 comments on commit 564371f

Please sign in to comment.