tsu 1.0.2 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +342 -9
- package/dist/index.js +379 -5
- package/dist/index.mjs +308 -0
- package/package.json +35 -34
- package/dist/array.d.ts +0 -96
- package/dist/function.d.ts +0 -24
- package/dist/is.d.ts +0 -63
- package/dist/maths.d.ts +0 -37
- package/dist/misc.d.ts +0 -13
- package/dist/object.d.ts +0 -10
- package/dist/scroll.d.ts +0 -17
- package/dist/string.d.ts +0 -59
- package/dist/tsu.cjs.development.js +0 -1461
- package/dist/tsu.cjs.development.js.map +0 -1
- package/dist/tsu.cjs.production.min.js +0 -2
- package/dist/tsu.cjs.production.min.js.map +0 -1
- package/dist/tsu.esm.js +0 -1416
- package/dist/tsu.esm.js.map +0 -1
- package/dist/types.d.ts +0 -5
- package/src/array.ts +0 -175
- package/src/function.ts +0 -65
- package/src/index.ts +0 -9
- package/src/is.ts +0 -90
- package/src/maths.ts +0 -51
- package/src/misc.ts +0 -18
- package/src/object.ts +0 -33
- package/src/scroll.ts +0 -68
- package/src/string.ts +0 -103
- package/src/types.ts +0 -7
package/dist/index.js
CHANGED
|
@@ -1,8 +1,382 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
11
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(module2))
|
|
13
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
14
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return target;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
19
|
+
return (module2, temp) => {
|
|
20
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
21
|
+
};
|
|
22
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
1
23
|
|
|
2
|
-
|
|
24
|
+
// src/index.ts
|
|
25
|
+
var src_exports = {};
|
|
26
|
+
__export(src_exports, {
|
|
27
|
+
capitalise: () => capitalise,
|
|
28
|
+
chars: () => chars,
|
|
29
|
+
debounce: () => debounce,
|
|
30
|
+
deepMerge: () => deepMerge,
|
|
31
|
+
drop: () => drop,
|
|
32
|
+
groupsOf: () => groupsOf,
|
|
33
|
+
head: () => head,
|
|
34
|
+
init: () => init,
|
|
35
|
+
isArray: () => isArray,
|
|
36
|
+
isBlank: () => isBlank,
|
|
37
|
+
isBoolean: () => isBoolean,
|
|
38
|
+
isBrowser: () => isBrowser,
|
|
39
|
+
isDefined: () => isDefined,
|
|
40
|
+
isEmpty: () => isEmpty,
|
|
41
|
+
isEven: () => isEven,
|
|
42
|
+
isFunction: () => isFunction,
|
|
43
|
+
isNumber: () => isNumber,
|
|
44
|
+
isObject: () => isObject,
|
|
45
|
+
isOdd: () => isOdd,
|
|
46
|
+
isString: () => isString,
|
|
47
|
+
isTouchDevice: () => isTouchDevice,
|
|
48
|
+
isWindow: () => isWindow,
|
|
49
|
+
last: () => last,
|
|
50
|
+
max: () => max,
|
|
51
|
+
memoize: () => memoize,
|
|
52
|
+
min: () => min,
|
|
53
|
+
modulo: () => modulo,
|
|
54
|
+
noop: () => noop,
|
|
55
|
+
partition: () => partition,
|
|
56
|
+
randomChance: () => randomChance,
|
|
57
|
+
randomNumber: () => randomNumber,
|
|
58
|
+
scroll: () => scroll,
|
|
59
|
+
sleep: () => sleep,
|
|
60
|
+
splitAt: () => splitAt,
|
|
61
|
+
sum: () => sum,
|
|
62
|
+
tail: () => tail,
|
|
63
|
+
take: () => take,
|
|
64
|
+
throttle: () => throttle,
|
|
65
|
+
toArray: () => toArray,
|
|
66
|
+
toCamel: () => toCamel,
|
|
67
|
+
toKebab: () => toKebab,
|
|
68
|
+
toNumber: () => toNumber,
|
|
69
|
+
truncate: () => truncate,
|
|
70
|
+
uniq: () => uniq
|
|
71
|
+
});
|
|
3
72
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
73
|
+
// src/array.ts
|
|
74
|
+
function drop(n, array) {
|
|
75
|
+
if (n <= 0) {
|
|
76
|
+
return [...array];
|
|
77
|
+
}
|
|
78
|
+
return array.slice(n);
|
|
8
79
|
}
|
|
80
|
+
function groupsOf(s, array) {
|
|
81
|
+
if (s <= 0) {
|
|
82
|
+
throw new Error("[tsu] Invalid group size");
|
|
83
|
+
}
|
|
84
|
+
if (s >= array.length) {
|
|
85
|
+
return [[...array]];
|
|
86
|
+
}
|
|
87
|
+
const groupedArray = [];
|
|
88
|
+
for (let i = 0; i < array.length; i += s) {
|
|
89
|
+
groupedArray.push(array.slice(i, i + s));
|
|
90
|
+
}
|
|
91
|
+
return groupedArray;
|
|
92
|
+
}
|
|
93
|
+
function head(array) {
|
|
94
|
+
return array[0];
|
|
95
|
+
}
|
|
96
|
+
function init(array) {
|
|
97
|
+
return array.slice(0, array.length - 1);
|
|
98
|
+
}
|
|
99
|
+
function last(array) {
|
|
100
|
+
return array[array.length - 1];
|
|
101
|
+
}
|
|
102
|
+
function max(array) {
|
|
103
|
+
if (!array.length) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
return Math.max(...array);
|
|
107
|
+
}
|
|
108
|
+
function min(array) {
|
|
109
|
+
if (!array.length) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
return Math.min(...array);
|
|
113
|
+
}
|
|
114
|
+
function partition(filter, array) {
|
|
115
|
+
return array.reduce(([passed, failed], item, idx, arr) => {
|
|
116
|
+
if (filter(item, idx, arr)) {
|
|
117
|
+
return [[...passed, item], failed];
|
|
118
|
+
}
|
|
119
|
+
return [passed, [...failed, item]];
|
|
120
|
+
}, [[], []]);
|
|
121
|
+
}
|
|
122
|
+
function splitAt(i, array) {
|
|
123
|
+
if (i <= 0) {
|
|
124
|
+
return [[], [...array]];
|
|
125
|
+
}
|
|
126
|
+
return [array.slice(0, i), array.slice(i)];
|
|
127
|
+
}
|
|
128
|
+
function sum(array) {
|
|
129
|
+
if (!array.length) {
|
|
130
|
+
return 0;
|
|
131
|
+
}
|
|
132
|
+
return array.reduce((sum2, current) => sum2 + current, 0);
|
|
133
|
+
}
|
|
134
|
+
function tail(array) {
|
|
135
|
+
return array.slice(1);
|
|
136
|
+
}
|
|
137
|
+
function take(n, array) {
|
|
138
|
+
if (n <= 0) {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
return array.slice(0, n);
|
|
142
|
+
}
|
|
143
|
+
function toArray(maybeArray) {
|
|
144
|
+
if (!maybeArray) {
|
|
145
|
+
return [];
|
|
146
|
+
}
|
|
147
|
+
return Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
148
|
+
}
|
|
149
|
+
function uniq(array) {
|
|
150
|
+
return Array.from(new Set(array));
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// src/function.ts
|
|
154
|
+
function debounce(fn, delay) {
|
|
155
|
+
let timeout;
|
|
156
|
+
return function(...args) {
|
|
157
|
+
clearTimeout(timeout);
|
|
158
|
+
timeout = setTimeout(() => {
|
|
159
|
+
clearTimeout(timeout);
|
|
160
|
+
fn(...args);
|
|
161
|
+
}, delay);
|
|
162
|
+
};
|
|
163
|
+
}
|
|
164
|
+
function memoize(fn) {
|
|
165
|
+
const cache = {};
|
|
166
|
+
return function(...args) {
|
|
167
|
+
const argsString = JSON.stringify(args);
|
|
168
|
+
if (argsString in cache) {
|
|
169
|
+
return cache[argsString];
|
|
170
|
+
}
|
|
171
|
+
const result = fn(...args);
|
|
172
|
+
cache[argsString] = result;
|
|
173
|
+
return result;
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
function throttle(fn, limit) {
|
|
177
|
+
let isWaiting = false;
|
|
178
|
+
return function(...args) {
|
|
179
|
+
if (!isWaiting) {
|
|
180
|
+
fn(...args);
|
|
181
|
+
isWaiting = true;
|
|
182
|
+
setTimeout(() => {
|
|
183
|
+
isWaiting = false;
|
|
184
|
+
}, limit);
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// src/is.ts
|
|
190
|
+
function isArray(val) {
|
|
191
|
+
return Array.isArray(val);
|
|
192
|
+
}
|
|
193
|
+
function isBoolean(val) {
|
|
194
|
+
return typeof val === "boolean";
|
|
195
|
+
}
|
|
196
|
+
function isBrowser() {
|
|
197
|
+
return typeof window !== "undefined";
|
|
198
|
+
}
|
|
199
|
+
function isDefined(val) {
|
|
200
|
+
return typeof val !== "undefined";
|
|
201
|
+
}
|
|
202
|
+
function isFunction(val) {
|
|
203
|
+
return typeof val === "function";
|
|
204
|
+
}
|
|
205
|
+
function isNumber(val) {
|
|
206
|
+
return typeof val === "number";
|
|
207
|
+
}
|
|
208
|
+
function isObject(val) {
|
|
209
|
+
return Object.prototype.toString.call(val) === "[object Object]";
|
|
210
|
+
}
|
|
211
|
+
function isString(val) {
|
|
212
|
+
return typeof val === "string";
|
|
213
|
+
}
|
|
214
|
+
function isTouchDevice() {
|
|
215
|
+
return "ontouchstart" in window || navigator.maxTouchPoints > 0;
|
|
216
|
+
}
|
|
217
|
+
function isWindow(val) {
|
|
218
|
+
return isBrowser() && toString.call(val) === "[object Window]";
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/maths.ts
|
|
222
|
+
function isEven(n) {
|
|
223
|
+
return n % 2 === 0;
|
|
224
|
+
}
|
|
225
|
+
function isOdd(n) {
|
|
226
|
+
return n % 2 !== 0;
|
|
227
|
+
}
|
|
228
|
+
function modulo(n, m) {
|
|
229
|
+
return n - Math.floor(n / m) * m;
|
|
230
|
+
}
|
|
231
|
+
function randomNumber(max2, min2 = 0) {
|
|
232
|
+
return Math.floor(Math.random() * (max2 - min2)) + min2;
|
|
233
|
+
}
|
|
234
|
+
function randomChance(n) {
|
|
235
|
+
return randomNumber(n) === 0;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
// src/misc.ts
|
|
239
|
+
function noop() {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
async function sleep(duration) {
|
|
243
|
+
return new Promise((resolve) => setTimeout(resolve, duration));
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// src/object.ts
|
|
247
|
+
function deepMerge(...objects) {
|
|
248
|
+
return objects.reduce((result, current) => {
|
|
249
|
+
Object.keys(current).forEach((key) => {
|
|
250
|
+
if (isArray(result[key]) && isArray(current[key])) {
|
|
251
|
+
result[key] = uniq(result[key].concat(current[key]));
|
|
252
|
+
} else if (isObject(result[key]) && isObject(current[key])) {
|
|
253
|
+
result[key] = deepMerge(result[key], current[key]);
|
|
254
|
+
} else {
|
|
255
|
+
result[key] = current[key];
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
return result;
|
|
259
|
+
}, {});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// src/scroll.ts
|
|
263
|
+
function scroll({
|
|
264
|
+
to,
|
|
265
|
+
offset = 0,
|
|
266
|
+
duration = 1e3,
|
|
267
|
+
container = null
|
|
268
|
+
}) {
|
|
269
|
+
const target = isString(to) ? document.querySelector(to) : to;
|
|
270
|
+
const _container = isString(container) ? document.querySelector(container) : container;
|
|
271
|
+
const start = (_container == null ? void 0 : _container.scrollTop) || (window == null ? void 0 : window.pageYOffset) || 0;
|
|
272
|
+
const end = (isNumber(target) ? target : getElTop(target, start)) + offset;
|
|
273
|
+
const startTime = Date.now();
|
|
274
|
+
function step() {
|
|
275
|
+
const timeElapsed = Date.now() - startTime;
|
|
276
|
+
const isScrolling = timeElapsed < duration;
|
|
277
|
+
const position = isScrolling ? getPosition(start, end, timeElapsed, duration) : end;
|
|
278
|
+
if (isScrolling) {
|
|
279
|
+
requestAnimationFrame(step);
|
|
280
|
+
}
|
|
281
|
+
if (_container) {
|
|
282
|
+
_container.scrollTop = position;
|
|
283
|
+
} else {
|
|
284
|
+
window.scrollTo(0, position);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
step();
|
|
288
|
+
}
|
|
289
|
+
function easing(t) {
|
|
290
|
+
return t < 0.5 ? 4 * Math.pow(t, 3) : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
|
|
291
|
+
}
|
|
292
|
+
function getPosition(s, e, t, d) {
|
|
293
|
+
return s + (e - s) * easing(t / d);
|
|
294
|
+
}
|
|
295
|
+
function getElTop(element, start) {
|
|
296
|
+
return element.nodeName === "HTML" ? -start : element.getBoundingClientRect().top + start;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
// src/string.ts
|
|
300
|
+
function capitalise(str, allWords = false) {
|
|
301
|
+
if (!allWords) {
|
|
302
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
303
|
+
}
|
|
304
|
+
return str.split(" ").map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(" ");
|
|
305
|
+
}
|
|
306
|
+
function chars(str) {
|
|
307
|
+
return str.split("");
|
|
308
|
+
}
|
|
309
|
+
function isBlank(str) {
|
|
310
|
+
return str.trim().length === 0;
|
|
311
|
+
}
|
|
312
|
+
function isEmpty(str) {
|
|
313
|
+
return str.length === 0;
|
|
314
|
+
}
|
|
315
|
+
function toCamel(str) {
|
|
316
|
+
const RE = /-(\w)/g;
|
|
317
|
+
return str.replace(RE, (_, c) => c ? c.toUpperCase() : "");
|
|
318
|
+
}
|
|
319
|
+
function toKebab(str) {
|
|
320
|
+
const RE = /\B([A-Z])/g;
|
|
321
|
+
return str.replace(RE, "-$1").toLowerCase();
|
|
322
|
+
}
|
|
323
|
+
function toNumber(str) {
|
|
324
|
+
if (!str.length) {
|
|
325
|
+
return NaN;
|
|
326
|
+
}
|
|
327
|
+
return Number(str.replace(/[#£€$,%]/g, ""));
|
|
328
|
+
}
|
|
329
|
+
function truncate(str, length, truncateStr = "...") {
|
|
330
|
+
if (length <= 0) {
|
|
331
|
+
return truncateStr;
|
|
332
|
+
}
|
|
333
|
+
return str.slice(0, length) + truncateStr;
|
|
334
|
+
}
|
|
335
|
+
module.exports = __toCommonJS(src_exports);
|
|
336
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
337
|
+
0 && (module.exports = {
|
|
338
|
+
capitalise,
|
|
339
|
+
chars,
|
|
340
|
+
debounce,
|
|
341
|
+
deepMerge,
|
|
342
|
+
drop,
|
|
343
|
+
groupsOf,
|
|
344
|
+
head,
|
|
345
|
+
init,
|
|
346
|
+
isArray,
|
|
347
|
+
isBlank,
|
|
348
|
+
isBoolean,
|
|
349
|
+
isBrowser,
|
|
350
|
+
isDefined,
|
|
351
|
+
isEmpty,
|
|
352
|
+
isEven,
|
|
353
|
+
isFunction,
|
|
354
|
+
isNumber,
|
|
355
|
+
isObject,
|
|
356
|
+
isOdd,
|
|
357
|
+
isString,
|
|
358
|
+
isTouchDevice,
|
|
359
|
+
isWindow,
|
|
360
|
+
last,
|
|
361
|
+
max,
|
|
362
|
+
memoize,
|
|
363
|
+
min,
|
|
364
|
+
modulo,
|
|
365
|
+
noop,
|
|
366
|
+
partition,
|
|
367
|
+
randomChance,
|
|
368
|
+
randomNumber,
|
|
369
|
+
scroll,
|
|
370
|
+
sleep,
|
|
371
|
+
splitAt,
|
|
372
|
+
sum,
|
|
373
|
+
tail,
|
|
374
|
+
take,
|
|
375
|
+
throttle,
|
|
376
|
+
toArray,
|
|
377
|
+
toCamel,
|
|
378
|
+
toKebab,
|
|
379
|
+
toNumber,
|
|
380
|
+
truncate,
|
|
381
|
+
uniq
|
|
382
|
+
});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
// src/array.ts
|
|
2
|
+
function drop(n, array) {
|
|
3
|
+
if (n <= 0) {
|
|
4
|
+
return [...array];
|
|
5
|
+
}
|
|
6
|
+
return array.slice(n);
|
|
7
|
+
}
|
|
8
|
+
function groupsOf(s, array) {
|
|
9
|
+
if (s <= 0) {
|
|
10
|
+
throw new Error("[tsu] Invalid group size");
|
|
11
|
+
}
|
|
12
|
+
if (s >= array.length) {
|
|
13
|
+
return [[...array]];
|
|
14
|
+
}
|
|
15
|
+
const groupedArray = [];
|
|
16
|
+
for (let i = 0; i < array.length; i += s) {
|
|
17
|
+
groupedArray.push(array.slice(i, i + s));
|
|
18
|
+
}
|
|
19
|
+
return groupedArray;
|
|
20
|
+
}
|
|
21
|
+
function head(array) {
|
|
22
|
+
return array[0];
|
|
23
|
+
}
|
|
24
|
+
function init(array) {
|
|
25
|
+
return array.slice(0, array.length - 1);
|
|
26
|
+
}
|
|
27
|
+
function last(array) {
|
|
28
|
+
return array[array.length - 1];
|
|
29
|
+
}
|
|
30
|
+
function max(array) {
|
|
31
|
+
if (!array.length) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
return Math.max(...array);
|
|
35
|
+
}
|
|
36
|
+
function min(array) {
|
|
37
|
+
if (!array.length) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
return Math.min(...array);
|
|
41
|
+
}
|
|
42
|
+
function partition(filter, array) {
|
|
43
|
+
return array.reduce(([passed, failed], item, idx, arr) => {
|
|
44
|
+
if (filter(item, idx, arr)) {
|
|
45
|
+
return [[...passed, item], failed];
|
|
46
|
+
}
|
|
47
|
+
return [passed, [...failed, item]];
|
|
48
|
+
}, [[], []]);
|
|
49
|
+
}
|
|
50
|
+
function splitAt(i, array) {
|
|
51
|
+
if (i <= 0) {
|
|
52
|
+
return [[], [...array]];
|
|
53
|
+
}
|
|
54
|
+
return [array.slice(0, i), array.slice(i)];
|
|
55
|
+
}
|
|
56
|
+
function sum(array) {
|
|
57
|
+
if (!array.length) {
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
return array.reduce((sum2, current) => sum2 + current, 0);
|
|
61
|
+
}
|
|
62
|
+
function tail(array) {
|
|
63
|
+
return array.slice(1);
|
|
64
|
+
}
|
|
65
|
+
function take(n, array) {
|
|
66
|
+
if (n <= 0) {
|
|
67
|
+
return [];
|
|
68
|
+
}
|
|
69
|
+
return array.slice(0, n);
|
|
70
|
+
}
|
|
71
|
+
function toArray(maybeArray) {
|
|
72
|
+
if (!maybeArray) {
|
|
73
|
+
return [];
|
|
74
|
+
}
|
|
75
|
+
return Array.isArray(maybeArray) ? maybeArray : [maybeArray];
|
|
76
|
+
}
|
|
77
|
+
function uniq(array) {
|
|
78
|
+
return Array.from(new Set(array));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// src/function.ts
|
|
82
|
+
function debounce(fn, delay) {
|
|
83
|
+
let timeout;
|
|
84
|
+
return function(...args) {
|
|
85
|
+
clearTimeout(timeout);
|
|
86
|
+
timeout = setTimeout(() => {
|
|
87
|
+
clearTimeout(timeout);
|
|
88
|
+
fn(...args);
|
|
89
|
+
}, delay);
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function memoize(fn) {
|
|
93
|
+
const cache = {};
|
|
94
|
+
return function(...args) {
|
|
95
|
+
const argsString = JSON.stringify(args);
|
|
96
|
+
if (argsString in cache) {
|
|
97
|
+
return cache[argsString];
|
|
98
|
+
}
|
|
99
|
+
const result = fn(...args);
|
|
100
|
+
cache[argsString] = result;
|
|
101
|
+
return result;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function throttle(fn, limit) {
|
|
105
|
+
let isWaiting = false;
|
|
106
|
+
return function(...args) {
|
|
107
|
+
if (!isWaiting) {
|
|
108
|
+
fn(...args);
|
|
109
|
+
isWaiting = true;
|
|
110
|
+
setTimeout(() => {
|
|
111
|
+
isWaiting = false;
|
|
112
|
+
}, limit);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// src/is.ts
|
|
118
|
+
function isArray(val) {
|
|
119
|
+
return Array.isArray(val);
|
|
120
|
+
}
|
|
121
|
+
function isBoolean(val) {
|
|
122
|
+
return typeof val === "boolean";
|
|
123
|
+
}
|
|
124
|
+
function isBrowser() {
|
|
125
|
+
return typeof window !== "undefined";
|
|
126
|
+
}
|
|
127
|
+
function isDefined(val) {
|
|
128
|
+
return typeof val !== "undefined";
|
|
129
|
+
}
|
|
130
|
+
function isFunction(val) {
|
|
131
|
+
return typeof val === "function";
|
|
132
|
+
}
|
|
133
|
+
function isNumber(val) {
|
|
134
|
+
return typeof val === "number";
|
|
135
|
+
}
|
|
136
|
+
function isObject(val) {
|
|
137
|
+
return Object.prototype.toString.call(val) === "[object Object]";
|
|
138
|
+
}
|
|
139
|
+
function isString(val) {
|
|
140
|
+
return typeof val === "string";
|
|
141
|
+
}
|
|
142
|
+
function isTouchDevice() {
|
|
143
|
+
return "ontouchstart" in window || navigator.maxTouchPoints > 0;
|
|
144
|
+
}
|
|
145
|
+
function isWindow(val) {
|
|
146
|
+
return isBrowser() && toString.call(val) === "[object Window]";
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// src/maths.ts
|
|
150
|
+
function isEven(n) {
|
|
151
|
+
return n % 2 === 0;
|
|
152
|
+
}
|
|
153
|
+
function isOdd(n) {
|
|
154
|
+
return n % 2 !== 0;
|
|
155
|
+
}
|
|
156
|
+
function modulo(n, m) {
|
|
157
|
+
return n - Math.floor(n / m) * m;
|
|
158
|
+
}
|
|
159
|
+
function randomNumber(max2, min2 = 0) {
|
|
160
|
+
return Math.floor(Math.random() * (max2 - min2)) + min2;
|
|
161
|
+
}
|
|
162
|
+
function randomChance(n) {
|
|
163
|
+
return randomNumber(n) === 0;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/misc.ts
|
|
167
|
+
function noop() {
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
async function sleep(duration) {
|
|
171
|
+
return new Promise((resolve) => setTimeout(resolve, duration));
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// src/object.ts
|
|
175
|
+
function deepMerge(...objects) {
|
|
176
|
+
return objects.reduce((result, current) => {
|
|
177
|
+
Object.keys(current).forEach((key) => {
|
|
178
|
+
if (isArray(result[key]) && isArray(current[key])) {
|
|
179
|
+
result[key] = uniq(result[key].concat(current[key]));
|
|
180
|
+
} else if (isObject(result[key]) && isObject(current[key])) {
|
|
181
|
+
result[key] = deepMerge(result[key], current[key]);
|
|
182
|
+
} else {
|
|
183
|
+
result[key] = current[key];
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
return result;
|
|
187
|
+
}, {});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// src/scroll.ts
|
|
191
|
+
function scroll({
|
|
192
|
+
to,
|
|
193
|
+
offset = 0,
|
|
194
|
+
duration = 1e3,
|
|
195
|
+
container = null
|
|
196
|
+
}) {
|
|
197
|
+
const target = isString(to) ? document.querySelector(to) : to;
|
|
198
|
+
const _container = isString(container) ? document.querySelector(container) : container;
|
|
199
|
+
const start = (_container == null ? void 0 : _container.scrollTop) || (window == null ? void 0 : window.pageYOffset) || 0;
|
|
200
|
+
const end = (isNumber(target) ? target : getElTop(target, start)) + offset;
|
|
201
|
+
const startTime = Date.now();
|
|
202
|
+
function step() {
|
|
203
|
+
const timeElapsed = Date.now() - startTime;
|
|
204
|
+
const isScrolling = timeElapsed < duration;
|
|
205
|
+
const position = isScrolling ? getPosition(start, end, timeElapsed, duration) : end;
|
|
206
|
+
if (isScrolling) {
|
|
207
|
+
requestAnimationFrame(step);
|
|
208
|
+
}
|
|
209
|
+
if (_container) {
|
|
210
|
+
_container.scrollTop = position;
|
|
211
|
+
} else {
|
|
212
|
+
window.scrollTo(0, position);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
step();
|
|
216
|
+
}
|
|
217
|
+
function easing(t) {
|
|
218
|
+
return t < 0.5 ? 4 * Math.pow(t, 3) : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
|
|
219
|
+
}
|
|
220
|
+
function getPosition(s, e, t, d) {
|
|
221
|
+
return s + (e - s) * easing(t / d);
|
|
222
|
+
}
|
|
223
|
+
function getElTop(element, start) {
|
|
224
|
+
return element.nodeName === "HTML" ? -start : element.getBoundingClientRect().top + start;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// src/string.ts
|
|
228
|
+
function capitalise(str, allWords = false) {
|
|
229
|
+
if (!allWords) {
|
|
230
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
231
|
+
}
|
|
232
|
+
return str.split(" ").map((s) => s.charAt(0).toUpperCase() + s.slice(1)).join(" ");
|
|
233
|
+
}
|
|
234
|
+
function chars(str) {
|
|
235
|
+
return str.split("");
|
|
236
|
+
}
|
|
237
|
+
function isBlank(str) {
|
|
238
|
+
return str.trim().length === 0;
|
|
239
|
+
}
|
|
240
|
+
function isEmpty(str) {
|
|
241
|
+
return str.length === 0;
|
|
242
|
+
}
|
|
243
|
+
function toCamel(str) {
|
|
244
|
+
const RE = /-(\w)/g;
|
|
245
|
+
return str.replace(RE, (_, c) => c ? c.toUpperCase() : "");
|
|
246
|
+
}
|
|
247
|
+
function toKebab(str) {
|
|
248
|
+
const RE = /\B([A-Z])/g;
|
|
249
|
+
return str.replace(RE, "-$1").toLowerCase();
|
|
250
|
+
}
|
|
251
|
+
function toNumber(str) {
|
|
252
|
+
if (!str.length) {
|
|
253
|
+
return NaN;
|
|
254
|
+
}
|
|
255
|
+
return Number(str.replace(/[#£€$,%]/g, ""));
|
|
256
|
+
}
|
|
257
|
+
function truncate(str, length, truncateStr = "...") {
|
|
258
|
+
if (length <= 0) {
|
|
259
|
+
return truncateStr;
|
|
260
|
+
}
|
|
261
|
+
return str.slice(0, length) + truncateStr;
|
|
262
|
+
}
|
|
263
|
+
export {
|
|
264
|
+
capitalise,
|
|
265
|
+
chars,
|
|
266
|
+
debounce,
|
|
267
|
+
deepMerge,
|
|
268
|
+
drop,
|
|
269
|
+
groupsOf,
|
|
270
|
+
head,
|
|
271
|
+
init,
|
|
272
|
+
isArray,
|
|
273
|
+
isBlank,
|
|
274
|
+
isBoolean,
|
|
275
|
+
isBrowser,
|
|
276
|
+
isDefined,
|
|
277
|
+
isEmpty,
|
|
278
|
+
isEven,
|
|
279
|
+
isFunction,
|
|
280
|
+
isNumber,
|
|
281
|
+
isObject,
|
|
282
|
+
isOdd,
|
|
283
|
+
isString,
|
|
284
|
+
isTouchDevice,
|
|
285
|
+
isWindow,
|
|
286
|
+
last,
|
|
287
|
+
max,
|
|
288
|
+
memoize,
|
|
289
|
+
min,
|
|
290
|
+
modulo,
|
|
291
|
+
noop,
|
|
292
|
+
partition,
|
|
293
|
+
randomChance,
|
|
294
|
+
randomNumber,
|
|
295
|
+
scroll,
|
|
296
|
+
sleep,
|
|
297
|
+
splitAt,
|
|
298
|
+
sum,
|
|
299
|
+
tail,
|
|
300
|
+
take,
|
|
301
|
+
throttle,
|
|
302
|
+
toArray,
|
|
303
|
+
toCamel,
|
|
304
|
+
toKebab,
|
|
305
|
+
toNumber,
|
|
306
|
+
truncate,
|
|
307
|
+
uniq
|
|
308
|
+
};
|