1234567891011121314151617181920212223242526272829303132333435363738394041 |
- 'use strict';
- Object.defineProperty(exports, '__esModule', {
- value: true
- });
- exports.default = convertDescriptorToString;
- function convertDescriptorToString(descriptor) {
- if (
- typeof descriptor === 'string' ||
- typeof descriptor === 'number' ||
- descriptor === undefined
- ) {
- return descriptor;
- }
- if (typeof descriptor !== 'function') {
- throw new Error('describe expects a class, function, number, or string.');
- }
- if (descriptor.name !== undefined) {
- return descriptor.name;
- }
- const stringified = descriptor.toString();
- const typeDescriptorMatch = stringified.match(/class|function/);
- const indexOfNameSpace =
- typeDescriptorMatch.index + typeDescriptorMatch[0].length;
- const indexOfNameAfterSpace = stringified.search(/\(|\{/);
- const name = stringified.substring(indexOfNameSpace, indexOfNameAfterSpace);
- return name.trim();
- }
|