-
Notifications
You must be signed in to change notification settings - Fork 0
/
customFunctions.gs
132 lines (101 loc) · 2.98 KB
/
customFunctions.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*******************************
TABLE OF CONTENT
- getReferences()
- getSubString(string, start, end)
- escapeRegExp(string)
- SStoNumColumn(name)
-
********************************/
/**
* This stores reference information and passes it back to the function that called it.
*
* @return A reference objects
*
* @version 1.0 (09.01.21)
* @author Matt Johnson <mdjhnson@gmail.com>
*/
function getReferences() {
u = {
settingHeaders: 1,
//GENERAL INFO
power_loc: {r: 11, c: 2},
power: "",
dataSourceURL_loc: {r: 2, c: 2},
sheetName_loc: {r: 3, c: 2},
dataHeaderRows_loc: {r: 4, c: 2},
filterColumn_loc: {r: 5, c: 2},
filterColumn: "",
destinationURL_loc: {r: 6, c: 2},
headerRows_loc: {r: 7, c: 2},
//FILTER LOGIC
filterValue_loc: {r: 2, c: 6},
filterSheetName_loc: {r: 2, c: 7},
//DATA ROUTES
sourceColumn_loc: {r: 2, c: 9},
toColumn_loc: {r: 2, c: 10},
findSubstring_loc: {r: 2, c: 11},
startString_loc: {r: 2, c: 12},
endString_loc: {r: 2, c:13}
}
u.power = settings[u.power_loc.r-1][u.power_loc.c-1]
u.filterColumn = SStoNumColumn(settings[u.filterColumn_loc.r - 1][u.filterColumn_loc.c - 1]);
return u;
}
/**
* Match all characters between two strings
*
* @params {text} string - the string to search
* @params {text} start - the string before desired text
* @params {text} end - the string after desired text
* @return {text} substring between values
*
* @version 1.0 (10.14.21)
* @author Matt Johnson <mdjhnson@gmail.com>
*/
function getSubString(string, start, end) {
start = escapeRegExp(start)
end = escapeRegExp(end)
var patt = new RegExp("(?<=" + start + ")(.*)(?=" + end + ")", "gm")
var result = string.match(patt)
return result.join('; ')
}
/**
* Escapes special characters in a string. Prepares for RegExp use.
*
* @params {text} string - string that you want the special characters escaped
* @return {text} a string with all special characters escaped.
*
* @version 1.0 (10.14.21)
* @author Matt Johnson <mdjhnson@gmail.com>
*/
function escapeRegExp(string) {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
}
/**
* Converts letters to numbers. Often used to convert columns to array coordinates.
* @param {string} name - The string of letters to be converted (ie. 'A' or 'AB').
* @return numerical equivalent.
*
* @version 1.1 (03.09.21)
* @author Matt JOhnson <mdjhnson@gmail.com>
*/
function SStoNumColumn(name) {
//name = "AA"
var i, index = 0;
name = name.toUpperCase().split('');
for (i = name.length - 1; i >= 0; i--) {
var piece = name[i];
var colNumber = piece.charCodeAt() - 64;
index = index + colNumber * Number(Math.pow(26, name.length - (i + 1)));
}
return index || undefined;
}
function findLargest(arr) {
var temp = 0;
arr.forEach((element) => {
if (temp < element) {
temp = element;
}
});
return temp;
}