is-plain-object.js 574 B

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