is-plain-object.js 592 B

1234567891011121314151617181920
  1. "use strict";
  2. var getPrototypeOf = Object.getPrototypeOf
  3. , prototype = Object.prototype
  4. , objToString = prototype.toString
  5. , id = Object().toString();
  6. module.exports = function (value) {
  7. var proto, valueConstructor;
  8. if (!value || typeof value !== "object" || objToString.call(value) !== id) {
  9. return false;
  10. }
  11. proto = getPrototypeOf(value);
  12. if (proto === null) {
  13. valueConstructor = value.constructor;
  14. if (typeof valueConstructor !== "function") return true;
  15. return valueConstructor.prototype !== value;
  16. }
  17. return proto === prototype || getPrototypeOf(proto) === null;
  18. };