1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | export function clamp(min, n, max) {
|
10 | return Math.max(min, Math.min(n, max));
|
11 | }
|
12 |
|
13 | export function deepCopy(obj) {
|
14 | return JSON.parse(JSON.stringify(obj));
|
15 | }
|
16 |
|
17 | export function deepEqual(a, b) {
|
18 | if (a === b) {
|
19 | return true;
|
20 | }
|
21 | return JSON.stringify(a) === JSON.stringify(b);
|
22 | }
|
23 |
|
24 | export function debounce(fn, wait, immediate) {
|
25 | if (immediate === void 0) { immediate = false; }
|
26 | var timeout, args, context, timestamp, result;
|
27 | return function () {
|
28 | context = this;
|
29 | args = arguments;
|
30 | timestamp = Date.now();
|
31 | var later = function () {
|
32 | var last = Date.now() - timestamp;
|
33 | if (last < wait) {
|
34 | timeout = setTimeout(later, wait - last);
|
35 | }
|
36 | else {
|
37 | timeout = null;
|
38 | if (!immediate)
|
39 | result = fn.apply(context, args);
|
40 | }
|
41 | };
|
42 | var callNow = immediate && !timeout;
|
43 | if (!timeout) {
|
44 | timeout = setTimeout(later, wait);
|
45 | }
|
46 | if (callNow)
|
47 | result = fn.apply(context, args);
|
48 | return result;
|
49 | };
|
50 | }
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | export function normalizeURL(url) {
|
56 | var ionic = window['Ionic'];
|
57 | if (ionic && ionic.normalizeURL) {
|
58 | return ionic.normalizeURL(url);
|
59 | }
|
60 | return url;
|
61 | }
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 | export function defaults(dest) {
|
69 | var _args = [];
|
70 | for (var _i = 1; _i < arguments.length; _i++) {
|
71 | _args[_i - 1] = arguments[_i];
|
72 | }
|
73 | for (var i = arguments.length - 1; i >= 1; i--) {
|
74 | var source = arguments[i];
|
75 | if (source) {
|
76 | for (var key in source) {
|
77 | if (source.hasOwnProperty(key) && !dest.hasOwnProperty(key)) {
|
78 | dest[key] = source[key];
|
79 | }
|
80 | }
|
81 | }
|
82 | }
|
83 | return dest;
|
84 | }
|
85 |
|
86 | export function isBoolean(val) { return typeof val === 'boolean'; }
|
87 |
|
88 | export function isString(val) { return typeof val === 'string'; }
|
89 |
|
90 | export function isNumber(val) { return typeof val === 'number'; }
|
91 |
|
92 | export function isFunction(val) { return typeof val === 'function'; }
|
93 |
|
94 | export function isDefined(val) { return typeof val !== 'undefined'; }
|
95 |
|
96 | export function isUndefined(val) { return typeof val === 'undefined'; }
|
97 |
|
98 | export function isPresent(val) { return val !== undefined && val !== null; }
|
99 |
|
100 | export function isBlank(val) { return val === undefined || val === null; }
|
101 |
|
102 | export function isObject(val) { return typeof val === 'object'; }
|
103 |
|
104 | export function isArray(val) { return Array.isArray(val); }
|
105 |
|
106 | export function isPrimitive(val) {
|
107 | return isString(val) || isBoolean(val) || (isNumber(val) && !isNaN(val));
|
108 | }
|
109 |
|
110 | export function isTrueProperty(val) {
|
111 | if (typeof val === 'string') {
|
112 | val = val.toLowerCase().trim();
|
113 | return (val === 'true' || val === 'on' || val === '');
|
114 | }
|
115 | return !!val;
|
116 | }
|
117 |
|
118 | export function isCheckedProperty(a, b) {
|
119 | if (a === undefined || a === null || a === '') {
|
120 | return (b === undefined || b === null || b === '');
|
121 | }
|
122 | else if (a === true || a === 'true') {
|
123 | return (b === true || b === 'true');
|
124 | }
|
125 | else if (a === false || a === 'false') {
|
126 | return (b === false || b === 'false');
|
127 | }
|
128 | else if (a === 0 || a === '0') {
|
129 | return (b === 0 || b === '0');
|
130 | }
|
131 |
|
132 | return (a == b);
|
133 | }
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 |
|
141 |
|
142 | export function isRightSide(side, isRTL, defaultRight) {
|
143 | if (defaultRight === void 0) { defaultRight = false; }
|
144 | switch (side) {
|
145 | case 'right': return true;
|
146 | case 'left': return false;
|
147 | case 'end': return !isRTL;
|
148 | case 'start': return isRTL;
|
149 | default: return defaultRight ? !isRTL : isRTL;
|
150 | }
|
151 | }
|
152 |
|
153 | export function reorderArray(array, indexes) {
|
154 | var element = array[indexes.from];
|
155 | array.splice(indexes.from, 1);
|
156 | array.splice(indexes.to, 0, element);
|
157 | return array;
|
158 | }
|
159 |
|
160 | export function removeArrayItem(array, item) {
|
161 | var index = array.indexOf(item);
|
162 | return !!~index && !!array.splice(index, 1);
|
163 | }
|
164 |
|
165 | export function swipeShouldReset(isResetDirection, isMovingFast, isOnResetZone) {
|
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 | var shouldClose = (!isMovingFast && isOnResetZone) || (isResetDirection && isMovingFast);
|
181 | return shouldClose;
|
182 | }
|
183 |
|
184 | var ASSERT_ENABLED = true;
|
185 |
|
186 | function _runInDev(fn) {
|
187 | if (ASSERT_ENABLED === true) {
|
188 | return fn();
|
189 | }
|
190 | }
|
191 |
|
192 | function _assert(actual, reason) {
|
193 | if (!actual && ASSERT_ENABLED === true) {
|
194 | var message = 'IONIC ASSERT: ' + reason;
|
195 | console.error(message);
|
196 | debugger;
|
197 | throw new Error(message);
|
198 | }
|
199 | }
|
200 |
|
201 | export function requestIonicCallback(functionToLazy) {
|
202 | if ('requestIdleCallback' in window) {
|
203 | return window.requestIdleCallback(functionToLazy);
|
204 | }
|
205 | else {
|
206 | return setTimeout(functionToLazy, 500);
|
207 | }
|
208 | }
|
209 |
|
210 | export { _assert as assert };
|
211 |
|
212 | export { _runInDev as runInDev };
|
213 |
|
\ | No newline at end of file |