source: imaps-frontend/node_modules/eslint-plugin-react/lib/util/propWrapper.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.8 KB
Line 
1/**
2 * @fileoverview Utility functions for propWrapperFunctions setting
3 */
4
5'use strict';
6
7const filter = require('es-iterator-helpers/Iterator.prototype.filter');
8const some = require('es-iterator-helpers/Iterator.prototype.some');
9
10function searchPropWrapperFunctions(name, propWrapperFunctions) {
11 const splitName = name.split('.');
12 return some(propWrapperFunctions.values(), (func) => {
13 if (splitName.length === 2 && func.object === splitName[0] && func.property === splitName[1]) {
14 return true;
15 }
16 return name === func || func.property === name;
17 });
18}
19
20function getPropWrapperFunctions(context) {
21 return new Set(context.settings.propWrapperFunctions || []);
22}
23
24function isPropWrapperFunction(context, name) {
25 if (typeof name !== 'string') {
26 return false;
27 }
28 const propWrapperFunctions = getPropWrapperFunctions(context);
29 return searchPropWrapperFunctions(name, propWrapperFunctions);
30}
31
32function getExactPropWrapperFunctions(context) {
33 const propWrapperFunctions = getPropWrapperFunctions(context);
34 const exactPropWrappers = filter(propWrapperFunctions.values(), (func) => func.exact === true);
35 return new Set(exactPropWrappers);
36}
37
38function isExactPropWrapperFunction(context, name) {
39 const exactPropWrappers = getExactPropWrapperFunctions(context);
40 return searchPropWrapperFunctions(name, exactPropWrappers);
41}
42
43function formatPropWrapperFunctions(propWrapperFunctions) {
44 return Array.from(propWrapperFunctions, (func) => {
45 if (func.object && func.property) {
46 return `'${func.object}.${func.property}'`;
47 }
48 if (func.property) {
49 return `'${func.property}'`;
50 }
51 return `'${func}'`;
52 }).join(', ');
53}
54
55module.exports = {
56 formatPropWrapperFunctions,
57 getExactPropWrapperFunctions,
58 getPropWrapperFunctions,
59 isExactPropWrapperFunction,
60 isPropWrapperFunction,
61};
Note: See TracBrowser for help on using the repository browser.