-
-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: isObject helper in different vm contexts or jest re-assigned glo…
…bals closes #178
- Loading branch information
Showing
5 changed files
with
33 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
function isObjectLike(value: unknown) { | ||
return typeof value === 'object' && value !== null | ||
} | ||
|
||
export default function isObject(input: unknown): boolean { | ||
return typeof input === 'object' && !!input && input.constructor === Object | ||
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== '[object Object]') { | ||
return false | ||
} | ||
if (Object.getPrototypeOf(input) === null) { | ||
return true | ||
} | ||
let proto = input | ||
while (Object.getPrototypeOf(proto) !== null) { | ||
proto = Object.getPrototypeOf(proto) | ||
} | ||
return Object.getPrototypeOf(input) === proto | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters