UNPKG

is-explicit

Version:

Combines instance of operator and typeof operator in a way that works seamlessly with objects and literals.

44 lines (31 loc) 1.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isArrayOfPlainObject = exports.default = void 0; var _is = _interopRequireDefault(require("./is")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } /******************************************************************************/ // Data /******************************************************************************/ const { toString } = Object.prototype; /******************************************************************************/ // Main /******************************************************************************/ const isPlainObject = value => { if (typeof value !== 'object' || value === null) return false; if ((0, _is.default)(Object.getPrototypeOf, Function)) { const proto = Object.getPrototypeOf(value); return proto === Object.prototype || proto === null; } return toString.call(value) === '[object Object]'; }; const isArrayOfPlainObject = array => (0, _is.default)(array, Array) && array.length > 0 && array.every(isPlainObject); /******************************************************************************/ // Exports /******************************************************************************/ exports.isArrayOfPlainObject = isArrayOfPlainObject; var _default = isPlainObject; exports.default = _default;