-
Notifications
You must be signed in to change notification settings - Fork 8
/
utils.js
194 lines (164 loc) · 5.07 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
import colorString from 'color-string';
export function isCalendarVisible(calendar, keys) {
if (!Array.isArray(keys)) keys = [keys];
return calendar && (!calendar.private || keys.includes(calendar.key));
}
export function filterHiddenCalendars(config, keys) {
var isVisible = function isVisible(calendar) {
return isCalendarVisible(calendar, keys);
};
for (var groupId in config.calendarGroups) {
var group = config.calendarGroups[groupId];
if (isVisible(group) && group.calendars) group.calendars = group.calendars.filter(function (calendarId) {
return isVisible(config.calendars[calendarId]);
});else delete config.calendarGroups[groupId];
}
for (var calendarId in config.calendars) {
var calendar = config.calendars[calendarId];
if (isVisible(calendar)) {
if (calendar.subCalendars) calendar.subCalendars = calendar.subCalendars.filter(isVisible);
} else delete config.calendars[calendarId];
}
return config;
}
export function getEventSources(calendars) {
var eventSources = [];
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
var _loop = function _loop() {
var calendar = _step.value;
if (calendar) {
(function () {
var color = calendar.color;
var googleCalendarId = calendar.googleCalendarId;
if (googleCalendarId) {
eventSources.push({
googleCalendarId: googleCalendarId,
color: color,
eventDataTransform: function eventDataTransform(eventData) {
return Object.assign(eventData, {
color: color,
calendar: calendar
});
}
});
}
if (calendar.subCalendars) {
var _iteratorNormalCompletion2 = true;
var _didIteratorError2 = false;
var _iteratorError2 = undefined;
try {
for (var _iterator2 = calendar.subCalendars[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
var subCalendar = _step2.value;
eventSources.push({
googleCalendarId: subCalendar.googleCalendarId,
color: color,
eventDataTransform: function eventDataTransform(eventData) {
return Object.assign(eventData, {
color: color,
calendar: calendar
});
}
});
}
} catch (err) {
_didIteratorError2 = true;
_iteratorError2 = err;
} finally {
try {
if (!_iteratorNormalCompletion2 && _iterator2.return) {
_iterator2.return();
}
} finally {
if (_didIteratorError2) {
throw _iteratorError2;
}
}
}
}
})();
}
};
for (var _iterator = calendars[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
_loop();
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator.return) {
_iterator.return();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
return eventSources;
}
export function nl2br(text) {
return text.replace(/(?:\r\n|\r|\n)/g, '<br />');
}
export function ucfirst(str) {
return str.charAt(0).toUpperCase() + str.substring(1);
}
export function camelCaseToWords(str) {
var result = '';
var _iteratorNormalCompletion3 = true;
var _didIteratorError3 = false;
var _iteratorError3 = undefined;
try {
for (var _iterator3 = str[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
var char = _step3.value;
if (result === '') {
result += char.toUpperCase();
} else if (char === char.toUpperCase()) {
result += ' ' + char.toLowerCase();
} else {
result += char;
}
}
} catch (err) {
_didIteratorError3 = true;
_iteratorError3 = err;
} finally {
try {
if (!_iteratorNormalCompletion3 && _iterator3.return) {
_iterator3.return();
}
} finally {
if (_didIteratorError3) {
throw _iteratorError3;
}
}
}
return result;
}
export function rgbaOverRgb(rgba) {
var rgb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [255, 255, 255];
rgba = colorToArray(rgba);
rgb = colorToArray(rgb);
if (rgba.length < 4 || rgba[rgba.length - 1] === 1) return colorString.to.rgb(rgba);
var rgbaAlpha = rgba.pop();
var resultPieces = [];
for (var i = 0; i < rgb.length; i++) {
resultPieces.push(rgb[i] + (rgba[i] - rgb[i]) * rgbaAlpha);
}
return colorString.to.rgb(resultPieces);
}
function colorToArray(color) {
if (!Array.isArray(color)) {
switch (typeof color === 'undefined' ? 'undefined' : _typeof(color)) {
case 'object':
return color.array();
case 'string':
return colorString.get(color).value;
}
}
return color;
}