UNPKG

tiny-types

Version:

A tiny library that brings Tiny Types to JavaScript and TypeScript

26 lines (20 loc) 627 B
import { isObject } from './isObject'; export function isRecord(value: unknown): value is Record<any, any> { if (! isObject(value)) { return false; } // It has modified constructor if (value.constructor === undefined) { return true; } // It has modified prototype if (! isObject(value.constructor.prototype)) { return false; } // If constructor does not have an Object-specific method if (! Object.prototype.hasOwnProperty.call(value.constructor.prototype, 'isPrototypeOf')) { return false; } // Most likely a plain Object return true; }