UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

36 lines (31 loc) 838 B
'use strict'; /*! * @techmely/utils * Copyright(c) 2021-2024 Techmely <techmely.creation@gmail.com> * MIT Licensed */ // src/isPlainObject/index.ts function isPlainObject(value) { if (!isObjectLike(value) || getTag(value) !== "[object Object]") { return false; } if (Object.getPrototypeOf(value) === null) { return true; } let proto = value; while (Object.getPrototypeOf(proto) !== null) { proto = Object.getPrototypeOf(proto); } return Object.getPrototypeOf(value) === proto; } function isObjectLike(value) { return typeof value === "object" && value !== null; } function getTag(value) { if (value == null) { return value === void 0 ? "[object Undefined]" : "[object Null]"; } return Object.prototype.toString.call(value); } exports.getTag = getTag; exports.isPlainObject = isPlainObject;