-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
120 lines (106 loc) · 5.32 KB
/
utils.js
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
async function loadFakeCsvData() {
return [
["id", "full_name", "email", "is_subscriber", "score"],
["1", "Ambur Wynrehame", "[email protected]", "false", "4.064"],
["2", "Donnamarie Khomin", "[email protected]", "false", "3.351"],
["3", "Almeria Upchurch", "[email protected]", "true", "4.854"],
["4", "Josie Kibel", "[email protected]", "false", "0.04"],
["5", "Raymond Veeler", "[email protected]", "false", "1.464"],
["6", "Agneta Castaneda", "[email protected]", "true", "2.885"],
["7", "Rodrick Jedrys", "[email protected]", "false", "2.343"],
["8", "Cy Simounet", "[email protected]", "true", "2.021"],
["9", "Justino Devo", "[email protected]", "false", "2.616"],
["10", "Shaylah Teall", "[email protected]", "false", "0.078"],
["11", "Nomi Kretschmer", "[email protected]", "false", "1.396"],
["12", "Revkah Trethowan", "[email protected]", "false", "0.457"],
["13", "Gerald Burris", "[email protected]", "true", "1.523"],
["14", "Haskell Dionis", "[email protected]", "true", "0.425"],
["15", "Annamaria Gawith", "[email protected]", "false", "0.303"],
["16", "Romeo Brundill", "[email protected]", "false", "4.534"],
["17", "Sherilyn Gunthorpe", "[email protected]", "true", "4.162"],
["18", "Lambert Spiteri", "[email protected]", "false", "2.077"],
["19", "Herold Jannequin", "[email protected]", "true", "1.348"],
["20", "Haleigh Moncreif", "[email protected]", "true", "2.398"],
["21", "Margaretta Ruppertz", "[email protected]", "false", "3.437"],
["22", "Keefe Wanjek", "[email protected]", "false", "3.686"],
["23", "Lynea Jacobowicz", "[email protected]", "false", "0.92"],
["24", "Yettie Frankcombe", "[email protected]", "true", "0.172"],
["25", "Bathsheba Cleobury", "[email protected]", "true", "0.423"],
["26", "Ginnifer Holttom", "[email protected]", "true", "4.386"],
["27", "Ellynn Whetnell", "[email protected]", "true", "4.062"],
["28", "Jordon Pauleau", "[email protected]", "false", "0.804"],
["29", "Marianne Attwood", "[email protected]", "false", "2.495"],
["30", "Adolf Torvey", "[email protected]", "false", "2.331"],
["31", "Mame Figures", "[email protected]", "false", "0.228"],
["32", "Laurie Longea", "[email protected]", "false", "4.503"],
["33", "Francklyn Brasier", "[email protected]", "true", "2.147"],
["34", "Ardis Bate", "[email protected]", "false", "2.713"],
["35", "Cora Rydeard", "[email protected]", "true", "4.266"],
["36", "Stephana Swaine", "[email protected]", "false", "2.716"],
["37", "Tallie Skunes", "[email protected]", "true", "3.955"],
["38", "Jareb Jansik", "[email protected]", "false", "4.407"],
["39", "Caril Hambribe", "[email protected]", "false", "0.719"],
["40", "Merlina Cornfoot", "[email protected]", "true", "1.854"],
["41", "Priscilla Verdy", "[email protected]", "true", "0.67"],
["42", "Chryste Gehring", "[email protected]", "false", "4.621"],
["43", "Tessi Bedford", "[email protected]", "false", "2.185"],
["44", "Nate Langstone", "[email protected]", "false", "1.444"],
["45", "Veronica Desson", "[email protected]", "true", "4.207"],
["46", "Sherie Rubel", "[email protected]", "false", "3.962"],
["47", "Ellissa Adlard", "[email protected]", "false", "0.42"],
["48", "Aeriel Monery", "[email protected]", "true", "0.877"],
["49", "Danell Pettengell", "[email protected]", "true", "4.139"],
["50", "Fayette Eaklee", "[email protected]", "true", "0.462"]
];
}
const generateNextColumnName = (colNum) => {
if (!colNum || colNum <= 0) {
return ""
}
let response = ""
do {
colNum -= 1
const base = Math.floor(colNum / 26);
const remainder = colNum % 26;
const suffix = String.fromCharCode(65 + remainder)
response = suffix + response
colNum = base;
} while(colNum != 0);
return response;
}
const getColumnNumberFromName = (colName) => {
let letters = [...colName]
let offset = 1
for (let i=letters.length-1; i >= 0; i--) {
let letter = letters[i]
let pos = (letter.charCodeAt(0) - 65) + offset
let newLetter = String.fromCharCode((pos % 26) + 65)
letters[i] = newLetter
offset = Math.floor(pos / 26)
}
if (offset != 0) {
letters = ['A', ...letters]
}
return letters.join("")
}
const getCellPositionFromId = (id) => {
const [rowNum, colNum] = id.split("-").map(s => parseInt(s))
return [
rowNum,
generateNextColumnName(colNum)
]
}
function debounce(func, timeout = 100) {
let timer;
return (...args) => {
clearTimeout(timer);
timer = setTimeout(() => { func.apply(this, args); }, timeout);
};
}
function hasValue(o) {
return o != null && o != undefined
}
const PROPER_REFERENCE_FORMAT = /[A-Z]+[1-9][0-9]*/
function hasReferenceFormat(maybeReference) {
return PROPER_REFERENCE_FORMAT.test(maybeReference)
}