Skip to content

Commit

Permalink
fix: deepMix() objects created via Object.create(null) (#106)
Browse files Browse the repository at this point in the history
* fix: deepMix() objects created via Object.create(null)

* chore: lint

---------

Co-authored-by: jialai.zf <[email protected]>
Co-authored-by: yuqi.pyq <[email protected]>
  • Loading branch information
3 people authored Jul 25, 2023
1 parent baab3d7 commit feb4cc7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/lodash/deep-mix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,21 @@ import isPlainObject from './is-plain-object';

const MAX_MIX_LEVEL = 5;

function hasOwn(object, property) {
if ((Object as any).hasOwn) {
return (Object as any).hasOwn(object, property);
}
if (object == null) {
throw new TypeError('Cannot convert undefined or null to object');
}
return Object.prototype.hasOwnProperty.call(Object(object), property);
}

function _deepMix(dist, src, level?, maxLevel?) {
level = level || 0;
maxLevel = maxLevel || MAX_MIX_LEVEL;
for (const key in src) {
if (src.hasOwnProperty(key)) {
if (hasOwn(src, key)) {
const value = src[key];
if (value !== null && isPlainObject(value)) {
if (!isPlainObject(dist[key])) {
Expand Down

0 comments on commit feb4cc7

Please sign in to comment.