isPOJO.js 433 B

123456789101112
  1. 'use strict';
  2. module.exports = function isPOJO(arg) {
  3. if (arg == null || typeof arg !== 'object') {
  4. return false;
  5. }
  6. const proto = Object.getPrototypeOf(arg);
  7. // Prototype may be null if you used `Object.create(null)`
  8. // Checking `proto`'s constructor is safe because `getPrototypeOf()`
  9. // explicitly crosses the boundary from object data to object metadata
  10. return !proto || proto.constructor.name === 'Object';
  11. };