class.js 597 B

123456789101112131415161718
  1. import getFuncName from 'get-func-name'
  2. import inspectObject from './object'
  3. const toStringTag = typeof Symbol !== 'undefined' && Symbol.toStringTag ? Symbol.toStringTag : false
  4. export default function inspectClass(value, options) {
  5. let name = ''
  6. if (toStringTag && toStringTag in value) {
  7. name = value[toStringTag]
  8. }
  9. name = name || getFuncName(value.constructor)
  10. // Babel transforms anonymous classes to the name `_class`
  11. if (!name || name === '_class') {
  12. name = '<Anonymous Class>'
  13. }
  14. options.truncate -= name.length
  15. return `${name}${inspectObject(value, options)}`
  16. }