Skip to content

Commit eee260c

Browse files
committed
[Fix] deep extending should work with a non-object.
Fixes #46.
1 parent fd71078 commit eee260c

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"complexity": [2, 15],
88
"eqeqeq": [2, "allow-null"],
99
"max-depth": [1, 4],
10-
"max-statements": [2, 25],
10+
"max-statements": [2, 26],
1111
"no-extra-parens": [1],
1212
"no-magic-numbers": [0],
1313
"no-restricted-syntax": [2, "BreakStatement", "ContinueStatement", "DebuggerStatement", "LabeledStatement", "WithStatement"]

index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ module.exports = function extend() {
4444
target = arguments[1] || {};
4545
// skip the boolean and the target
4646
i = 2;
47-
} else if ((typeof target !== 'object' && typeof target !== 'function') || target == null) {
47+
}
48+
if (target == null || (typeof target !== 'object' && typeof target !== 'function')) {
4849
target = {};
4950
}
5051

test/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,3 +619,10 @@ test('works without Array.isArray', function (t) {
619619
Array.isArray = savedIsArray;
620620
t.end();
621621
});
622+
623+
test('non-object target', function (t) {
624+
t.deepEqual(extend(3.14, { a: 'b' }), { a: 'b' });
625+
t.deepEqual(extend(true, 3.14, { a: 'b' }), { a: 'b' });
626+
627+
t.end();
628+
});

0 commit comments

Comments
 (0)