mirror of
https://github.com/hanzoai/jose.git
synced 2026-09-24 17:00:01 +00:00
18 lines
517 B
TypeScript
18 lines
517 B
TypeScript
function isObjectLike(value: unknown) {
|
|
return typeof value === 'object' && value !== null
|
|
}
|
|
|
|
export default function isObject<T = object>(input: unknown): input is T {
|
|
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
|
|
}
|