isPlainObject.js 442 B

12345678910111213
  1. const getType = (value) => (Object.prototype.toString.call(value).slice(8, -1).toLowerCase());
  2. function isPlainObject(value) {
  3. if (getType(value) !== "object") {
  4. return false;
  5. }
  6. const pp = Object.getPrototypeOf(value);
  7. if (pp === null || pp === undefined) {
  8. return true;
  9. }
  10. const Ctor = pp.constructor && pp.constructor.toString();
  11. return Ctor === Object.toString();
  12. }
  13. export default isPlainObject;