@techmely/utils
Version:
Collection of helpful JavaScript / TypeScript utils
33 lines (29 loc) • 793 B
JavaScript
/*!
* @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);
}
export { getTag, isPlainObject };