convertDescriptorToString.js 751 B

123456789101112131415161718192021222324252627282930
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', {
  3. value: true
  4. });
  5. exports.default = convertDescriptorToString;
  6. /**
  7. * Copyright (c) Meta Platforms, Inc. and affiliates.
  8. *
  9. * This source code is licensed under the MIT license found in the
  10. * LICENSE file in the root directory of this source tree.
  11. */
  12. function convertDescriptorToString(descriptor) {
  13. switch (typeof descriptor) {
  14. case 'function':
  15. if (descriptor.name) {
  16. return descriptor.name;
  17. }
  18. break;
  19. case 'number':
  20. case 'undefined':
  21. return `${descriptor}`;
  22. case 'string':
  23. return descriptor;
  24. }
  25. throw new Error(
  26. `Invalid first argument, ${descriptor}. It must be a named class, named function, number, or string.`
  27. );
  28. }