-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathutil.gs
33 lines (29 loc) · 872 Bytes
/
util.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
function datetimeToDate(datetime) {
// 2017-03-02T08:00:00+0000
var date = datetime.match(/\d{4}-\d{2}-\d{2}/) || [];
return date[0];
}
function log(obj) {
Logger.log(JSON.stringify(obj, null, 2));
}
/**
* Variable substitution on a string.
*
* Scans through a string looking for expressions enclosed within double curly braces.
* If an expression is found, use it as a key on the object,
* and if the key has a string or number value,
* it is substituted for the bracket expression and it repeats.
*
* Originally by Douglas Crockford: http://javascript.crockford.com/remedial.html
*/
if (!String.prototype.supplant) {
String.prototype.supplant = function (o) {
return this.replace(
/{{([^{}]*)}}/g,
function (a, b) {
var r = o[b];
return typeof r === 'string' || typeof r === 'number' ? r : a;
}
);
};
}