tsu 1.1.0 → 1.1.1

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 CHANGED
@@ -12,6 +12,14 @@ declare type Obj<V = unknown> = Record<string | symbol | number, V>;
12
12
  * @returns The remaining items.
13
13
  */
14
14
  declare function drop<T>(n: number, array: readonly T[]): T[];
15
+ /**
16
+ * Split an array into groups of size `n`.
17
+ *
18
+ * @param n - The size of each group.
19
+ * @param array - The array.
20
+ * @returns The array split into groups.
21
+ */
22
+ declare function groupsOf<T>(n: number, array: readonly T[]): T[][];
15
23
  /**
16
24
  * Returns the first item of an array.
17
25
  *
@@ -54,7 +62,7 @@ declare function min(array: readonly number[]): number | undefined;
54
62
  * @param array - The array.
55
63
  * @returns The array split in two.
56
64
  */
57
- declare function partition<T>(filter: (x: T, idx: number, arr: readonly T[]) => boolean, array: readonly T[]): [T[], T[]];
65
+ declare function partition<T>(filter: (x: T, idx: number, a: readonly T[]) => boolean, array: readonly T[]): [T[], T[]];
58
66
  /**
59
67
  * Splits an array into two at a given index.
60
68
  *
@@ -179,6 +187,12 @@ declare function isObject(val: unknown): val is Obj;
179
187
  * @returns If the value is a string.
180
188
  */
181
189
  declare function isString(val: unknown): val is string;
190
+ /**
191
+ * Identifies if the code is being run on a touch device.
192
+ *
193
+ * @returns If the code is being run on a touch device.
194
+ */
195
+ declare function isTouchDevice(): boolean;
182
196
  /**
183
197
  * Identifies if a value is the global window.
184
198
  *
@@ -325,4 +339,4 @@ declare function toNumber(str: string): number;
325
339
  */
326
340
  declare function truncate(str: string, length: number, truncateStr?: string): string;
327
341
 
328
- export { Arrayable, Fn, Nullable, Obj, VoidFn, capitalise, chars, debounce, deepMerge, drop, head, init, isArray, isBlank, isBoolean, isBrowser, isDefined, isEmpty, isEven, isFunction, isNumber, isObject, isOdd, isString, isWindow, last, max, memoize, min, modulo, noop, partition, randomChance, randomNumber, scroll, sleep, splitAt, sum, tail, take, throttle, toArray, toCamel, toKebab, toNumber, truncate, uniq };
342
+ export { Arrayable, Fn, Nullable, Obj, VoidFn, capitalise, chars, debounce, deepMerge, drop, groupsOf, head, init, isArray, isBlank, isBoolean, isBrowser, isDefined, isEmpty, isEven, isFunction, isNumber, isObject, isOdd, isString, isTouchDevice, isWindow, last, max, memoize, min, modulo, noop, partition, randomChance, randomNumber, scroll, sleep, splitAt, sum, tail, take, throttle, toArray, toCamel, toKebab, toNumber, truncate, uniq };
package/dist/index.js CHANGED
@@ -29,6 +29,7 @@ __export(src_exports, {
29
29
  debounce: () => debounce,
30
30
  deepMerge: () => deepMerge,
31
31
  drop: () => drop,
32
+ groupsOf: () => groupsOf,
32
33
  head: () => head,
33
34
  init: () => init,
34
35
  isArray: () => isArray,
@@ -43,6 +44,7 @@ __export(src_exports, {
43
44
  isObject: () => isObject,
44
45
  isOdd: () => isOdd,
45
46
  isString: () => isString,
47
+ isTouchDevice: () => isTouchDevice,
46
48
  isWindow: () => isWindow,
47
49
  last: () => last,
48
50
  max: () => max,
@@ -75,6 +77,19 @@ function drop(n, array) {
75
77
  }
76
78
  return array.slice(n);
77
79
  }
80
+ function groupsOf(n, array) {
81
+ if (n <= 0) {
82
+ throw new Error("[tsu] Invalid group size");
83
+ }
84
+ if (n >= array.length) {
85
+ return [[...array]];
86
+ }
87
+ const groupedArray = [];
88
+ for (let i = 0; i < array.length; i += n) {
89
+ groupedArray.push(array.slice(i, i + n));
90
+ }
91
+ return groupedArray;
92
+ }
78
93
  function head(array) {
79
94
  return array[0];
80
95
  }
@@ -196,6 +211,9 @@ function isObject(val) {
196
211
  function isString(val) {
197
212
  return typeof val === "string";
198
213
  }
214
+ function isTouchDevice() {
215
+ return "ontouchstart" in window || navigator.maxTouchPoints > 0;
216
+ }
199
217
  function isWindow(val) {
200
218
  return isBrowser() && toString.call(val) === "[object Window]";
201
219
  }
@@ -322,6 +340,7 @@ module.exports = __toCommonJS(src_exports);
322
340
  debounce,
323
341
  deepMerge,
324
342
  drop,
343
+ groupsOf,
325
344
  head,
326
345
  init,
327
346
  isArray,
@@ -336,6 +355,7 @@ module.exports = __toCommonJS(src_exports);
336
355
  isObject,
337
356
  isOdd,
338
357
  isString,
358
+ isTouchDevice,
339
359
  isWindow,
340
360
  last,
341
361
  max,
package/dist/index.mjs CHANGED
@@ -5,6 +5,19 @@ function drop(n, array) {
5
5
  }
6
6
  return array.slice(n);
7
7
  }
8
+ function groupsOf(n, array) {
9
+ if (n <= 0) {
10
+ throw new Error("[tsu] Invalid group size");
11
+ }
12
+ if (n >= array.length) {
13
+ return [[...array]];
14
+ }
15
+ const groupedArray = [];
16
+ for (let i = 0; i < array.length; i += n) {
17
+ groupedArray.push(array.slice(i, i + n));
18
+ }
19
+ return groupedArray;
20
+ }
8
21
  function head(array) {
9
22
  return array[0];
10
23
  }
@@ -126,6 +139,9 @@ function isObject(val) {
126
139
  function isString(val) {
127
140
  return typeof val === "string";
128
141
  }
142
+ function isTouchDevice() {
143
+ return "ontouchstart" in window || navigator.maxTouchPoints > 0;
144
+ }
129
145
  function isWindow(val) {
130
146
  return isBrowser() && toString.call(val) === "[object Window]";
131
147
  }
@@ -250,6 +266,7 @@ export {
250
266
  debounce,
251
267
  deepMerge,
252
268
  drop,
269
+ groupsOf,
253
270
  head,
254
271
  init,
255
272
  isArray,
@@ -264,6 +281,7 @@ export {
264
281
  isObject,
265
282
  isOdd,
266
283
  isString,
284
+ isTouchDevice,
267
285
  isWindow,
268
286
  last,
269
287
  max,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tsu",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "A collection of TypeScript utilities.",
5
5
  "author": "eb3n",
6
6
  "repository": {