UNPKG

@jsopen/objects

Version:

Helper utilities for working with JavaScript objects and arrays

25 lines (24 loc) 860 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isObject = isObject; exports.isPlainObject = isPlainObject; const objCtorStr = Function.prototype.toString.call(Object); function isObject(v) { return v && typeof v === 'object' && !Array.isArray(v); } function isPlainObject(obj) { if (obj && typeof obj === 'object' && Object.prototype.toString.call(obj) === '[object Object]') { const proto = Object.getPrototypeOf(obj); /* istanbul ignore next */ if (!proto) return true; const ctor = Object.prototype.hasOwnProperty.call(proto, 'constructor') && proto.constructor; return (typeof ctor === 'function' && ctor instanceof ctor && Function.prototype.toString.call(ctor) === objCtorStr); } return false; }