|
Last change
on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago |
|
Added visualizations
|
-
Property mode
set to
100644
|
|
File size:
1.2 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|---|
| 4 |
|
|---|
| 5 | const isNil = require('../../predicate/isNil.js');
|
|---|
| 6 | const isIterateeCall = require('../_internal/isIterateeCall.js');
|
|---|
| 7 | const isEqualsSameValueZero = require('../../_internal/isEqualsSameValueZero.js');
|
|---|
| 8 |
|
|---|
| 9 | function defaults(object, ...sources) {
|
|---|
| 10 | object = Object(object);
|
|---|
| 11 | const objectProto = Object.prototype;
|
|---|
| 12 | let length = sources.length;
|
|---|
| 13 | const guard = length > 2 ? sources[2] : undefined;
|
|---|
| 14 | if (guard && isIterateeCall.isIterateeCall(sources[0], sources[1], guard)) {
|
|---|
| 15 | length = 1;
|
|---|
| 16 | }
|
|---|
| 17 | for (let i = 0; i < length; i++) {
|
|---|
| 18 | if (isNil.isNil(sources[i])) {
|
|---|
| 19 | continue;
|
|---|
| 20 | }
|
|---|
| 21 | const source = sources[i];
|
|---|
| 22 | const keys = Object.keys(source);
|
|---|
| 23 | for (let j = 0; j < keys.length; j++) {
|
|---|
| 24 | const key = keys[j];
|
|---|
| 25 | const value = object[key];
|
|---|
| 26 | if (value === undefined ||
|
|---|
| 27 | (!Object.hasOwn(object, key) && isEqualsSameValueZero.isEqualsSameValueZero(value, objectProto[key]))) {
|
|---|
| 28 | object[key] = source[key];
|
|---|
| 29 | }
|
|---|
| 30 | }
|
|---|
| 31 | }
|
|---|
| 32 | return object;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | exports.defaults = defaults;
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.