Skip to content

Commit

Permalink
1.4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
sttk committed Jan 27, 2017
1 parent b0bd194 commit 080df12
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ This program is free software under [MIT][mit-url] License.
See the file LICENSE in this distribution for more details.

[repo-url]: https://github.com/sttk/copy-props/
[npm-img]: https://img.shields.io/badge/npm-v1.4.0-blue.svg
[npm-img]: https://img.shields.io/badge/npm-v1.4.1-blue.svg
[npm-url]: https://www.npmjs.org/package/copy-props/
[mit-img]: https://img.shields.io/badge/license-MIT-green.svg
[mit-url]: https://opensource.org/licenses.MIT
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "copy-props",
"version": "1.4.0",
"version": "1.4.1",
"description": "Copy properties deeply between two objects.",
"main": "index.js",
"files": [
Expand Down
34 changes: 18 additions & 16 deletions test/web/copy-props.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ function copyWithFromto(value, keyChain, nodeInfo) {

for (var i = 0, n = dstKeyChains.length; i < n; i++) {
var dstValue = nodeInfo.convert(value, keyChain, dstKeyChains[i]);
if (dstValue !== undefined) {
setDeep(nodeInfo.dest, dstKeyChains[i], dstValue);
}
setDeep(nodeInfo.dest, dstKeyChains[i], dstValue);
}
}

Expand Down Expand Up @@ -8105,38 +8103,42 @@ module.exports = function(obj, fn, opts) {
return;
}

var nodeInfo = isPlainObject(opts) ? objectAssign({}, opts) : {};
nodeInfo.depth = 0;
if (!isPlainObject(opts)) {
opts = {};
}

forEachChild(obj, '', fn, nodeInfo);
forEachChild(obj, '', fn, 0, opts);
};

function forEachChild(node, baseKey, fn, nodeInfo) {
function forEachChild(node, baseKey, fn, depth, opts) {
var keys = Object.keys(node);
if (typeof nodeInfo.sort === 'function') {
var sortedKeys = nodeInfo.sort(keys);
if (typeof opts.sort === 'function') {
var sortedKeys = opts.sort(keys);
if (Array.isArray(sortedKeys)) {
keys = sortedKeys;
}
}

depth += 1;

for (var i = 0, n = keys.length; i < n; i++) {
var key = keys[i];
var keyChain = baseKey + '.' + key;
var value = node[key];

var childInfo = objectAssign({}, nodeInfo);
childInfo.index = i;
childInfo.count = n;
childInfo.depth = nodeInfo.depth + 1;
childInfo.parent = node;
var nodeInfo = objectAssign({}, opts);
nodeInfo.name = key;
nodeInfo.index = i;
nodeInfo.count = n;
nodeInfo.depth = depth;
nodeInfo.parent = node;

var notDigg = fn(value, keyChain.slice(1), childInfo);
var notDigg = fn(value, keyChain.slice(1), nodeInfo);
if (notDigg || !isPlainObject(value)) {
continue;
}

forEachChild(value, keyChain, fn, childInfo);
forEachChild(value, keyChain, fn, depth, opts);
}
}

Expand Down
2 changes: 1 addition & 1 deletion web/copy-props.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 080df12

Please sign in to comment.