[d565449] | 1 | /**
|
---|
| 2 | * @fileoverview Utility functions for propWrapperFunctions setting
|
---|
| 3 | */
|
---|
| 4 |
|
---|
| 5 | 'use strict';
|
---|
| 6 |
|
---|
| 7 | const iterFrom = require('es-iterator-helpers/Iterator.from');
|
---|
| 8 | const map = require('es-iterator-helpers/Iterator.prototype.map');
|
---|
| 9 |
|
---|
| 10 | /** TODO: type {(string | { name: string, linkAttribute: string })[]} */
|
---|
| 11 | /** @type {any} */
|
---|
| 12 | const DEFAULT_LINK_COMPONENTS = ['a'];
|
---|
| 13 | const DEFAULT_LINK_ATTRIBUTE = 'href';
|
---|
| 14 |
|
---|
| 15 | /** TODO: type {(string | { name: string, formAttribute: string })[]} */
|
---|
| 16 | /** @type {any} */
|
---|
| 17 | const DEFAULT_FORM_COMPONENTS = ['form'];
|
---|
| 18 | const DEFAULT_FORM_ATTRIBUTE = 'action';
|
---|
| 19 |
|
---|
| 20 | function getFormComponents(context) {
|
---|
| 21 | const settings = context.settings || {};
|
---|
| 22 | const formComponents = /** @type {typeof DEFAULT_FORM_COMPONENTS} */ (
|
---|
| 23 | DEFAULT_FORM_COMPONENTS.concat(settings.formComponents || [])
|
---|
| 24 | );
|
---|
| 25 | return new Map(map(iterFrom(formComponents), (value) => {
|
---|
| 26 | if (typeof value === 'string') {
|
---|
| 27 | return [value, [DEFAULT_FORM_ATTRIBUTE]];
|
---|
| 28 | }
|
---|
| 29 | return [value.name, [].concat(value.formAttribute)];
|
---|
| 30 | }));
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | function getLinkComponents(context) {
|
---|
| 34 | const settings = context.settings || {};
|
---|
| 35 | const linkComponents = /** @type {typeof DEFAULT_LINK_COMPONENTS} */ (
|
---|
| 36 | DEFAULT_LINK_COMPONENTS.concat(settings.linkComponents || [])
|
---|
| 37 | );
|
---|
| 38 | return new Map(map(iterFrom(linkComponents), (value) => {
|
---|
| 39 | if (typeof value === 'string') {
|
---|
| 40 | return [value, [DEFAULT_LINK_ATTRIBUTE]];
|
---|
| 41 | }
|
---|
| 42 | return [value.name, [].concat(value.linkAttribute)];
|
---|
| 43 | }));
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | module.exports = {
|
---|
| 47 | getFormComponents,
|
---|
| 48 | getLinkComponents,
|
---|
| 49 | };
|
---|