1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | export function clamp(min, n, max) {
|
11 | return Math.max(min, Math.min(n, max));
|
12 | }
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export function deepCopy(obj) {
|
19 | return JSON.parse(JSON.stringify(obj));
|
20 | }
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | export function deepEqual(a, b) {
|
28 | if (a === b) {
|
29 | return true;
|
30 | }
|
31 | return JSON.stringify(a) === JSON.stringify(b);
|
32 | }
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | export function debounce(fn, wait, immediate) {
|
41 | if (immediate === void 0) { immediate = false; }
|
42 | var timeout, args, context, timestamp, result;
|
43 | return function () {
|
44 | context = this;
|
45 | args = arguments;
|
46 | timestamp = Date.now();
|
47 | var later = function () {
|
48 | var last = Date.now() - timestamp;
|
49 | if (last < wait) {
|
50 | timeout = setTimeout(later, wait - last);
|
51 | }
|
52 | else {
|
53 | timeout = null;
|
54 | if (!immediate)
|
55 | result = fn.apply(context, args);
|
56 | }
|
57 | };
|
58 | var callNow = immediate && !timeout;
|
59 | if (!timeout) {
|
60 | timeout = setTimeout(later, wait);
|
61 | }
|
62 | if (callNow)
|
63 | result = fn.apply(context, args);
|
64 | return result;
|
65 | };
|
66 | }
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | export function normalizeURL(url) {
|
74 | var ionic = ((window))['Ionic'];
|
75 | if (ionic && ionic.normalizeURL) {
|
76 | return ionic.normalizeURL(url);
|
77 | }
|
78 | return url;
|
79 | }
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 | export function defaults(dest) {
|
89 | var _args = [];
|
90 | for (var _i = 1; _i < arguments.length; _i++) {
|
91 | _args[_i - 1] = arguments[_i];
|
92 | }
|
93 | for (var i = arguments.length - 1; i >= 1; i--) {
|
94 | var source = arguments[i];
|
95 | if (source) {
|
96 | for (var key in source) {
|
97 | if (source.hasOwnProperty(key) && !dest.hasOwnProperty(key)) {
|
98 | dest[key] = source[key];
|
99 | }
|
100 | }
|
101 | }
|
102 | }
|
103 | return dest;
|
104 | }
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | export function isBoolean(val) { return typeof val === 'boolean'; }
|
111 |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 | export function isString(val) { return typeof val === 'string'; }
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | export function isNumber(val) { return typeof val === 'number'; }
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 | export function isFunction(val) { return typeof val === 'function'; }
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | export function isDefined(val) { return typeof val !== 'undefined'; }
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | export function isUndefined(val) { return typeof val === 'undefined'; }
|
141 |
|
142 |
|
143 |
|
144 |
|
145 |
|
146 | export function isPresent(val) { return val !== undefined && val !== null; }
|
147 |
|
148 |
|
149 |
|
150 |
|
151 |
|
152 | export function isBlank(val) { return val === undefined || val === null; }
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 | export function isObject(val) { return typeof val === 'object'; }
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 | export function isArray(val) { return Array.isArray(val); }
|
165 |
|
166 |
|
167 |
|
168 |
|
169 |
|
170 | export function isPrimitive(val) {
|
171 | return isString(val) || isBoolean(val) || (isNumber(val) && !isNaN(val));
|
172 | }
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 | export function isTrueProperty(val) {
|
179 | if (typeof val === 'string') {
|
180 | val = val.toLowerCase().trim();
|
181 | return (val === 'true' || val === 'on' || val === '');
|
182 | }
|
183 | return !!val;
|
184 | }
|
185 |
|
186 |
|
187 |
|
188 |
|
189 |
|
190 |
|
191 | export function isCheckedProperty(a, b) {
|
192 | if (a === undefined || a === null || a === '') {
|
193 | return (b === undefined || b === null || b === '');
|
194 | }
|
195 | else if (a === true || a === 'true') {
|
196 | return (b === true || b === 'true');
|
197 | }
|
198 | else if (a === false || a === 'false') {
|
199 | return (b === false || b === 'false');
|
200 | }
|
201 | else if (a === 0 || a === '0') {
|
202 | return (b === 0 || b === '0');
|
203 | }
|
204 |
|
205 | return (a == b);
|
206 | }
|
207 |
|
208 |
|
209 |
|
210 |
|
211 |
|
212 |
|
213 |
|
214 |
|
215 |
|
216 | export function isRightSide(side, isRTL, defaultRight) {
|
217 | if (defaultRight === void 0) { defaultRight = false; }
|
218 | switch (side) {
|
219 | case 'right': return true;
|
220 | case 'left': return false;
|
221 | case 'end': return !isRTL;
|
222 | case 'start': return isRTL;
|
223 | default: return defaultRight ? !isRTL : isRTL;
|
224 | }
|
225 | }
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 | export function reorderArray(array, indexes) {
|
233 | var element = array[indexes.from];
|
234 | array.splice(indexes.from, 1);
|
235 | array.splice(indexes.to, 0, element);
|
236 | return array;
|
237 | }
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 |
|
244 | export function removeArrayItem(array, item) {
|
245 | var index = array.indexOf(item);
|
246 | return !!~index && !!array.splice(index, 1);
|
247 | }
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 | export function swipeShouldReset(isResetDirection, isMovingFast, isOnResetZone) {
|
256 |
|
257 |
|
258 |
|
259 |
|
260 |
|
261 |
|
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 |
|
269 |
|
270 | var shouldClose = (!isMovingFast && isOnResetZone) || (isResetDirection && isMovingFast);
|
271 | return shouldClose;
|
272 | }
|
273 |
|
274 |
|
275 |
|
276 | var ASSERT_ENABLED = true;
|
277 |
|
278 |
|
279 |
|
280 |
|
281 |
|
282 | function _runInDev(fn) {
|
283 | if (ASSERT_ENABLED === true) {
|
284 | return fn();
|
285 | }
|
286 | }
|
287 |
|
288 |
|
289 |
|
290 |
|
291 |
|
292 |
|
293 | function _assert(actual, reason) {
|
294 | if (!actual && ASSERT_ENABLED === true) {
|
295 | var message = 'IONIC ASSERT: ' + reason;
|
296 | console.error(message);
|
297 | debugger;
|
298 | throw new Error(message);
|
299 | }
|
300 | }
|
301 |
|
302 |
|
303 |
|
304 |
|
305 |
|
306 | export function requestIonicCallback(functionToLazy) {
|
307 | if ('requestIdleCallback' in window) {
|
308 | return ((window)).requestIdleCallback(functionToLazy);
|
309 | }
|
310 | else {
|
311 | return setTimeout(functionToLazy, 500);
|
312 | }
|
313 | }
|
314 |
|
315 | export { _assert as assert };
|
316 |
|
317 | export { _runInDev as runInDev };
|
318 |
|
\ | No newline at end of file |