/
githubmirror
/
immutable-js
Обзор
Документация
Войти
/
githubmirror
/
immutable-js
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/utils/isPlainObj.ts
26 строк
780 B
Julien Deniau
Migrate utiles to TypeScript (except deepEqual and mixin)
24 фев 2025, 00:23
24 фев 2025, 00:23
f472e43
Код
Авторство
О чём код?
const toString = Object.prototype.toString; export default function isPlainObject(value: unknown): value is object { // The base prototype's toString deals with Argument objects and native namespaces like Math if ( !value || typeof value !== 'object' || toString.call(value) !== '[object Object]' ) { return false; } const proto = Object.getPrototypeOf(value); if (proto === null) { return true; } // Iteratively going up the prototype chain is needed for cross-realm environments (differing contexts, iframes, etc) let parentProto = proto; let nextProto = Object.getPrototypeOf(proto); while (nextProto !== null) { parentProto = nextProto; nextProto = Object.getPrototypeOf(parentProto); } return parentProto === proto; }