PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 3.0.4
GiveWP – Donation Plugin and Fundraising Platform v3.0.4
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / src / DonationForms / resources / app / utilities / groups.ts
give / src / DonationForms / resources / app / utilities Last commit date
ConvertFieldAPIRulesToJoi.ts 2 years ago PrepareFormData.ts 2 years ago amountFormatter.ts 2 years ago buildRegisterValidationOptions.ts 2 years ago conditionOperatorFunctions.js 2 years ago convertValuesToFormData.ts 2 years ago createValidationObjectFromFields.js 2 years ago generateRequestErrors.ts 2 years ago getCurrentFormUrlData.js 2 years ago getDefaultValuesFromSections.ts 2 years ago getDonationFormNodeSettings.ts 2 years ago getErrorByFieldName.ts 2 years ago getWindowData.ts 2 years ago groups.ts 2 years ago handleFormRedirect.ts 2 years ago handleFormSubmitRequest.ts 2 years ago handleValidationRequest.ts 2 years ago isRouteInlineRedirect.ts 2 years ago memoNode.ts 2 years ago mountWindowData.ts 2 years ago postData.ts 2 years ago postFormData.ts 2 years ago registerFieldAndBuildProps.tsx 2 years ago
groups.ts
145 lines
1 import {Field, Group, isField, isGroup, Node} from '@givewp/forms/types';
2
3 /**
4 * Finds the first node with a given name within a collection of nodes
5 *
6 * @since 3.0.0
7 */
8 export function findNode(name: string, nodes: Node[]): Node {
9 let node;
10 for (let index = 0; index < nodes.length; index++) {
11 node = nodes[index];
12
13 if (node.name === name) {
14 return node;
15 } else if (isGroup(node)) {
16 const nestedNode = findNode(name, node.nodes);
17 if (nestedNode !== null) {
18 return nestedNode;
19 }
20 }
21 }
22
23 return null;
24 }
25
26 /**
27 * Walks through a group's nodes and calls a callback for each node. If a filter is provided the callback only fires for
28 * nodes which pass the filter.
29 *
30 * @since 3.0.0
31 */
32 export function walkGroup(group: Group, callback: (node: Node) => void, filter?: (node: Node) => boolean) {
33 walkNodes(group.nodes, callback, filter);
34 }
35
36 /**
37 * Maps through a Group's nodes and calls a callback for each node. If a filter is provided the callback only fires for
38 * passing nodes.
39 *
40 * @since 3.0.0
41 */
42 export function mapGroup(group: Group, callback: (node: Node) => unknown, filter?: (node: Node) => boolean) {
43 return mapNodes(group.nodes, callback, filter);
44 }
45
46 /**
47 * Reduces a Group's nodes into a single value. If a filter is provided the callback only fires for passing nodes.
48 * @since 3.0.0
49 */
50 export function reduceGroup(
51 group: Group,
52 callback: (accumulator: unknown, node: Node) => unknown,
53 initialValue: unknown,
54 filter?: (node: Node) => boolean
55 ) {
56 return reduceNodes(group.nodes, callback, initialValue, filter);
57 }
58
59 /**
60 * Walks through a collection of nodes and calls a callback for each node. If a filter is provided the callback only fires for passing nodes.
61 *
62 * @since 3.0.0
63 */
64 export function walkNodes(nodes: Node[], callback: (node: Node) => void, filter?: (node: Node) => boolean) {
65 nodes.forEach((node) => {
66 if (!filter || filter(node)) {
67 callback(node);
68 }
69
70 if (isGroup(node)) {
71 walkNodes(node.nodes, callback, filter);
72 }
73 });
74 }
75
76 /**
77 * Maps a collection of nodes to a new array of values. If a filter is provided the callback only fires for nodes which
78 * pass.
79 *
80 * @since 3.0.0
81 */
82 export function mapNodes<Type>(
83 nodes: Node[],
84 callback: (node: Node) => Type,
85 filter?: (node: Node) => boolean
86 ): Type[] {
87 let mappedValues: Array<Type> = [];
88
89 walkNodes(
90 nodes,
91 (node) => {
92 mappedValues.push(callback(node));
93 },
94 filter
95 );
96
97 return mappedValues;
98 }
99
100 /**
101 * Reduces an array of nodes to a single value. If the filter is provided, only nodes which pass the filter will be used.
102 *
103 * @since 3.0.0
104 */
105 export function reduceNodes<Type>(
106 nodes: Node[],
107 callback: (accumulator: Type, node: Node) => Type,
108 initialValue: Type,
109 filter?: (node: Node) => boolean
110 ): Type {
111 let accumulator = initialValue;
112
113 walkNodes(
114 nodes,
115 (node) => {
116 accumulator = callback(accumulator, node);
117 },
118 filter
119 );
120
121 return accumulator;
122 }
123
124 /**
125 * Walks through an array of nodes, limited by fields, and calls a callback for each field.
126 *
127 * @since 3.0.0
128 */
129 export function walkFields(nodes: Node[], callback: (field: Field) => void) {
130 walkNodes(nodes, callback, isField);
131 }
132
133 /**
134 * Reduces an array of nodes, limited by its fields, into a single value.
135 *
136 * @since 3.0.0
137 */
138 export function reduceFields<Type>(
139 nodes: Parameters<typeof reduceNodes>[0],
140 callback: (accumulator: Type, field: Field) => Type,
141 initialValue: Type
142 ) {
143 return reduceNodes(nodes, callback, initialValue, isField);
144 }
145