forked from grahamearley/FirestoreGoogleAppsScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtil.js
40 lines (34 loc) · 910 Bytes
/
Util.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
// Assumes n is a Number.
function isInt_(n) {
return n % 1 === 0;
}
function base64EncodeSafe_(string) {
var encoded = Utilities.base64EncodeWebSafe(string);
return encoded.replace(/=/g, "");
}
function removeTrailingSlash_(string) {
const length = string.length;
if (string.charAt(length - 1) === '/') {
// Remove trailing slash
return string.substr(0, length - 1);
} else {
return string;
}
}
function getObjectFromResponse_(response) {
return JSON.parse(response.getContentText());
}
function checkForError_(responseObj) {
if (responseObj["error"]) {
throw new Error(responseObj["error"]["message"]);
}
}
function getIdFromPath_(path) {
return path.split("/").pop();
}
function addAll_(array, itemsToAdd) {
for (var i = 0; i < itemsToAdd.length; i++) {
var item = itemsToAdd[i];
array.push(item);
}
}