get-class-name.js 493 B

12345678910111213141516171819202122
  1. "use strict";
  2. var valueToString = require("@sinonjs/commons").valueToString;
  3. var re = /function (\w+)\s*\(/;
  4. function getClassName(value) {
  5. if (value.constructor && "name" in value.constructor) {
  6. return value.constructor.name;
  7. }
  8. if (typeof value.constructor === "function") {
  9. var match = valueToString(value.constructor).match(re);
  10. if (match.length > 1) {
  11. return match[1];
  12. }
  13. }
  14. return null;
  15. }
  16. module.exports = getClassName;