Skip to content

Commit

Permalink
fix(isPlainObject): support check Object.create(null) (#4633)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Dorr <timdorr@users.noreply.github.com>
  • Loading branch information
zhe-he and timdorr committed Dec 6, 2023
1 parent 0e8a7b0 commit cfc3145
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/utils/isPlainObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export default function isPlainObject(obj: any): obj is object {
proto = Object.getPrototypeOf(proto)
}

return Object.getPrototypeOf(obj) === proto
return Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null
}
1 change: 1 addition & 0 deletions test/utils/isPlainObject.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ describe('isPlainObject', () => {
expect(isPlainObject(null)).toBe(false)
expect(isPlainObject(undefined)).toBe(false)
expect(isPlainObject({ x: 1, y: 2 })).toBe(true)
expect(isPlainObject(Object.create(null))).toBe(true)
})
})

0 comments on commit cfc3145

Please sign in to comment.