Skip to content

Commit

Permalink
fix(marker): markSimpleObject add null check (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
exuanbo authored Dec 23, 2023
1 parent ed780e0 commit 2d0e181
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/utils/marker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ const constructorString = Object.prototype.constructor.toString();
* support case: https://github.com/unadlib/mutative/issues/17
*/
const isSimpleObject = (value: unknown) => {
if (!value || typeof value !== 'object') return false;
const prototype = Object.getPrototypeOf(value);
if (prototype === null) {
return true;
}
const constructor =
Object.hasOwnProperty.call(prototype, 'constructor') &&
prototype.constructor;

if (constructor === Object) return true;

return (
typeof constructor === 'function' &&
Function.toString.call(constructor) === constructorString
Expand Down

0 comments on commit 2d0e181

Please sign in to comment.