source: imaps-frontend/node_modules/eslint-plugin-react/lib/util/linkComponents.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/**
2 * @fileoverview Utility functions for propWrapperFunctions setting
3 */
4
5'use strict';
6
7const iterFrom = require('es-iterator-helpers/Iterator.from');
8const map = require('es-iterator-helpers/Iterator.prototype.map');
9
10/** TODO: type {(string | { name: string, linkAttribute: string })[]} */
11/** @type {any} */
12const DEFAULT_LINK_COMPONENTS = ['a'];
13const DEFAULT_LINK_ATTRIBUTE = 'href';
14
15/** TODO: type {(string | { name: string, formAttribute: string })[]} */
16/** @type {any} */
17const DEFAULT_FORM_COMPONENTS = ['form'];
18const DEFAULT_FORM_ATTRIBUTE = 'action';
19
20function 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
33function 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
46module.exports = {
47 getFormComponents,
48 getLinkComponents,
49};
Note: See TracBrowser for help on using the repository browser.