linkComponents.js 724 B

123456789101112131415161718192021222324252627
  1. /**
  2. * @fileoverview Utility functions for propWrapperFunctions setting
  3. */
  4. 'use strict';
  5. /** TODO: type {(string | { name: string, linkAttribute: string })[]} */
  6. /** @type {any} */
  7. const DEFAULT_LINK_COMPONENTS = ['a'];
  8. const DEFAULT_LINK_ATTRIBUTE = 'href';
  9. function getLinkComponents(context) {
  10. const settings = context.settings || {};
  11. const linkComponents = /** @type {typeof DEFAULT_LINK_COMPONENTS} */ (
  12. DEFAULT_LINK_COMPONENTS.concat(settings.linkComponents || [])
  13. );
  14. return new Map(linkComponents.map((value) => {
  15. if (typeof value === 'string') {
  16. return [value, DEFAULT_LINK_ATTRIBUTE];
  17. }
  18. return [value.name, value.linkAttribute];
  19. }));
  20. }
  21. module.exports = {
  22. getLinkComponents
  23. };