class-name.js 921 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. var functionName = require("./function-name");
  3. /**
  4. * Returns a display name for a value from a constructor
  5. *
  6. * @param {object} value A value to examine
  7. * @returns {(string|null)} A string or null
  8. */
  9. function className(value) {
  10. return (
  11. (value.constructor && value.constructor.name) ||
  12. // The next branch is for IE11 support only:
  13. // Because the name property is not set on the prototype
  14. // of the Function object, we finally try to grab the
  15. // name from its definition. This will never be reached
  16. // in node, so we are not able to test this properly.
  17. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  18. (typeof value.constructor === "function" &&
  19. /* istanbul ignore next */
  20. functionName(value.constructor)) ||
  21. null
  22. );
  23. }
  24. module.exports = className;