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.d.ts
CHANGED
|
@@ -1,9 +1,342 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
declare type Arrayable<T> = T | Array<T>;
|
|
2
|
+
declare type Nullable<T> = T | null | undefined;
|
|
3
|
+
declare type Fn<T = any> = (...args: any[]) => T;
|
|
4
|
+
declare type VoidFn = Fn<void>;
|
|
5
|
+
declare type Obj<V = unknown> = Record<string | symbol | number, V>;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Removes the first n items of an array.
|
|
9
|
+
*
|
|
10
|
+
* @param n - The number of items to remove.
|
|
11
|
+
* @param array - The array.
|
|
12
|
+
* @returns The remaining items.
|
|
13
|
+
*/
|
|
14
|
+
declare function drop<T>(n: number, array: readonly T[]): T[];
|
|
15
|
+
/**
|
|
16
|
+
* Splits an array into groups of size s.
|
|
17
|
+
*
|
|
18
|
+
* @param s - The size of each group.
|
|
19
|
+
* @param array - The array.
|
|
20
|
+
* @returns The array split into groups.
|
|
21
|
+
*/
|
|
22
|
+
declare function groupsOf<T>(s: number, array: readonly T[]): T[][];
|
|
23
|
+
/**
|
|
24
|
+
* Returns the first item of an array.
|
|
25
|
+
*
|
|
26
|
+
* @param array - The array.
|
|
27
|
+
* @returns The first item.
|
|
28
|
+
*/
|
|
29
|
+
declare function head<T>(array: readonly T[]): T;
|
|
30
|
+
/**
|
|
31
|
+
* Returns all but the last item of an array.
|
|
32
|
+
*
|
|
33
|
+
* @param array - The array.
|
|
34
|
+
* @returns The array without the last item.
|
|
35
|
+
*/
|
|
36
|
+
declare function init<T>(array: readonly T[]): T[];
|
|
37
|
+
/**
|
|
38
|
+
* Returns the last item of an array.
|
|
39
|
+
*
|
|
40
|
+
* @param array - The array.
|
|
41
|
+
* @returns The last item.
|
|
42
|
+
*/
|
|
43
|
+
declare function last<T>(array: readonly T[]): T;
|
|
44
|
+
/**
|
|
45
|
+
* Returns the maximum number of an array.
|
|
46
|
+
*
|
|
47
|
+
* @param array - The array of numbers.
|
|
48
|
+
* @returns The maximum number.
|
|
49
|
+
*/
|
|
50
|
+
declare function max(array: readonly number[]): number | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Returns the minimum number of an array.
|
|
53
|
+
*
|
|
54
|
+
* @param array - The array of numbers.
|
|
55
|
+
* @returns The minimum number.
|
|
56
|
+
*/
|
|
57
|
+
declare function min(array: readonly number[]): number | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Splits an array into two based on a predicate function.
|
|
60
|
+
*
|
|
61
|
+
* @param filter - The predicate function.
|
|
62
|
+
* @param array - The array.
|
|
63
|
+
* @returns The array split in two.
|
|
64
|
+
*/
|
|
65
|
+
declare function partition<T>(filter: (x: T, idx: number, a: readonly T[]) => boolean, array: readonly T[]): [T[], T[]];
|
|
66
|
+
/**
|
|
67
|
+
* Splits an array into two at a given index.
|
|
68
|
+
*
|
|
69
|
+
* @param i - The position to split at.
|
|
70
|
+
* @param array - The array.
|
|
71
|
+
* @returns The array split in two.
|
|
72
|
+
*/
|
|
73
|
+
declare function splitAt<T>(i: number, array: readonly T[]): [T[], T[]];
|
|
74
|
+
/**
|
|
75
|
+
* Returns the sum of the numbers of an array.
|
|
76
|
+
*
|
|
77
|
+
* @param array - The array of numbers.
|
|
78
|
+
* @returns The sum.
|
|
79
|
+
*/
|
|
80
|
+
declare function sum(array: readonly number[]): number;
|
|
81
|
+
/**
|
|
82
|
+
* Returns all but the first item of an array.
|
|
83
|
+
*
|
|
84
|
+
* @param array - The array.
|
|
85
|
+
* @returns The array without the first item.
|
|
86
|
+
*/
|
|
87
|
+
declare function tail<T>(array: readonly T[]): T[];
|
|
88
|
+
/**
|
|
89
|
+
* Returns the first n items of an array.
|
|
90
|
+
*
|
|
91
|
+
* @param n - The number of items to return.
|
|
92
|
+
* @param array - The array.
|
|
93
|
+
* @returns The first n items.
|
|
94
|
+
*/
|
|
95
|
+
declare function take<T>(n: number, array: readonly T[]): T[];
|
|
96
|
+
/**
|
|
97
|
+
* Wraps a single value of an array, if not already an array.
|
|
98
|
+
*
|
|
99
|
+
* @param maybeArray - The value to wrap, or the existing array.
|
|
100
|
+
* @returns The item wrapped in an array, or the provided array.
|
|
101
|
+
*/
|
|
102
|
+
declare function toArray<T>(maybeArray: Nullable<Arrayable<T>>): T[];
|
|
103
|
+
/**
|
|
104
|
+
* Removes duplicate primitive values from an array.
|
|
105
|
+
*
|
|
106
|
+
* @param array - The array.
|
|
107
|
+
* @returns The array without duplicated primitive values.
|
|
108
|
+
*/
|
|
109
|
+
declare function uniq<T>(array: readonly T[]): T[];
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Prevents a function from running until it hasn't been called for a certain time period.
|
|
113
|
+
*
|
|
114
|
+
* @param fn - The function.
|
|
115
|
+
* @param delay - The time period (in ms).
|
|
116
|
+
* @returns The debounced function.
|
|
117
|
+
*/
|
|
118
|
+
declare function debounce(fn: Fn, delay: number): VoidFn;
|
|
119
|
+
/**
|
|
120
|
+
* Optimises subsequent calls of a function by caching return values.
|
|
121
|
+
*
|
|
122
|
+
* @param fn - The function.
|
|
123
|
+
* @returns The memoized function.
|
|
124
|
+
*/
|
|
125
|
+
declare function memoize<T>(fn: Fn<T>): Fn<T>;
|
|
126
|
+
/**
|
|
127
|
+
* Prevents a function from running for some time period after it was last called.
|
|
128
|
+
*
|
|
129
|
+
* @param fn - The function.
|
|
130
|
+
* @param limit - The time period.
|
|
131
|
+
* @returns The throttled function.
|
|
132
|
+
*/
|
|
133
|
+
declare function throttle(fn: Fn, limit: number): VoidFn;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Identifies if a value is an array.
|
|
137
|
+
*
|
|
138
|
+
* @param val - The value.
|
|
139
|
+
* @returns If the value is an array.
|
|
140
|
+
*/
|
|
141
|
+
declare function isArray(val: unknown): val is any[];
|
|
142
|
+
/**
|
|
143
|
+
* Identifies if a value is a boolean.
|
|
144
|
+
*
|
|
145
|
+
* @param val - The value.
|
|
146
|
+
* @returns If the value is a boolean.
|
|
147
|
+
*/
|
|
148
|
+
declare function isBoolean(val: unknown): val is boolean;
|
|
149
|
+
/**
|
|
150
|
+
* Identifies if the code is being run in the browser.
|
|
151
|
+
*
|
|
152
|
+
* @returns If the code is being run on a browser.
|
|
153
|
+
*/
|
|
154
|
+
declare function isBrowser(): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Identifies if a value is defined.
|
|
157
|
+
*
|
|
158
|
+
* @param val - The value.
|
|
159
|
+
* @returns If the value is defined.
|
|
160
|
+
*/
|
|
161
|
+
declare function isDefined<T = unknown>(val?: T): val is T;
|
|
162
|
+
/**
|
|
163
|
+
* Identifies if a value is a function.
|
|
164
|
+
*
|
|
165
|
+
* @param val - The value.
|
|
166
|
+
* @returns If the value is a function.
|
|
167
|
+
*/
|
|
168
|
+
declare function isFunction<T extends Fn>(val: unknown): val is T;
|
|
169
|
+
/**
|
|
170
|
+
* Identifies if a value is a number.
|
|
171
|
+
*
|
|
172
|
+
* @param val - The value.
|
|
173
|
+
* @returns If the value is a number.
|
|
174
|
+
*/
|
|
175
|
+
declare function isNumber(val: unknown): val is number;
|
|
176
|
+
/**
|
|
177
|
+
* Identifies if a value is an object.
|
|
178
|
+
*
|
|
179
|
+
* @param val - The value.
|
|
180
|
+
* @returns If the value is an object.
|
|
181
|
+
*/
|
|
182
|
+
declare function isObject(val: unknown): val is Obj;
|
|
183
|
+
/**
|
|
184
|
+
* Identifies if a value is a string.
|
|
185
|
+
*
|
|
186
|
+
* @param val - The value.
|
|
187
|
+
* @returns If the value is a string.
|
|
188
|
+
*/
|
|
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;
|
|
196
|
+
/**
|
|
197
|
+
* Identifies if a value is the global window.
|
|
198
|
+
*
|
|
199
|
+
* @param val - The value.
|
|
200
|
+
* @returns If the value is the global window.
|
|
201
|
+
*/
|
|
202
|
+
declare function isWindow(val: unknown): val is Window;
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Identifies if a number is even.
|
|
206
|
+
*
|
|
207
|
+
* @param n - The number.
|
|
208
|
+
* @returns If the number is even.
|
|
209
|
+
*/
|
|
210
|
+
declare function isEven(n: number): boolean;
|
|
211
|
+
/**
|
|
212
|
+
* Identifies if a number is odd.
|
|
213
|
+
*
|
|
214
|
+
* @param n - The number.
|
|
215
|
+
* @returns If the number is odd.
|
|
216
|
+
*/
|
|
217
|
+
declare function isOdd(n: number): boolean;
|
|
218
|
+
/**
|
|
219
|
+
* Opinionated implementation of modulo (%).
|
|
220
|
+
*
|
|
221
|
+
* @param n - The dividend.
|
|
222
|
+
* @param m - The divisor.
|
|
223
|
+
* @returns The remainder of dividing n by m.
|
|
224
|
+
*/
|
|
225
|
+
declare function modulo(n: number, m: number): number;
|
|
226
|
+
/**
|
|
227
|
+
* Generates a random integer between bounds.
|
|
228
|
+
*
|
|
229
|
+
* @param max - The exclusive maximum bound.
|
|
230
|
+
* @param min - The inclusive minimum bound.
|
|
231
|
+
* @returns The random integer.
|
|
232
|
+
*/
|
|
233
|
+
declare function randomNumber(max: number, min?: number): number;
|
|
234
|
+
/**
|
|
235
|
+
* Rolls an n-sided die.
|
|
236
|
+
*
|
|
237
|
+
* @param n - The number of sides on the die.
|
|
238
|
+
* @returns If the die roll was 0.
|
|
239
|
+
*/
|
|
240
|
+
declare function randomChance(n: number): boolean;
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Does nothing.
|
|
244
|
+
*
|
|
245
|
+
* @returns Nothing.
|
|
246
|
+
*/
|
|
247
|
+
declare function noop(): void;
|
|
248
|
+
/**
|
|
249
|
+
* Halts program execution for a specified time.
|
|
250
|
+
*
|
|
251
|
+
* @param duration - The time to wait (in ms).
|
|
252
|
+
* @returns The halting promise.
|
|
253
|
+
*/
|
|
254
|
+
declare function sleep(duration: number): Promise<void>;
|
|
255
|
+
|
|
256
|
+
declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
257
|
+
/**
|
|
258
|
+
* Recursively merges multiple objects into one.
|
|
259
|
+
*
|
|
260
|
+
* @param objects - The objects to merge.
|
|
261
|
+
* @returns The merged object.
|
|
262
|
+
*/
|
|
263
|
+
declare function deepMerge<T extends Obj<any>[]>(...objects: T): UnionToIntersection<T[number]>;
|
|
264
|
+
|
|
265
|
+
declare type ScrollConfig = {
|
|
266
|
+
to: Element | string | number;
|
|
267
|
+
offset?: number;
|
|
268
|
+
duration?: number;
|
|
269
|
+
container?: Element | string | null;
|
|
270
|
+
};
|
|
271
|
+
/**
|
|
272
|
+
* Scrolls the page or provided container to a target element or y-coordinate.
|
|
273
|
+
*
|
|
274
|
+
* @param config - The scroll config.
|
|
275
|
+
* @param config.to - The scroll target.
|
|
276
|
+
* @param config.offset - The offset from the scroll target (in px).
|
|
277
|
+
* @param config.duration - The scroll duration (in ms).
|
|
278
|
+
* @param config.container - The container to scroll in.
|
|
279
|
+
*/
|
|
280
|
+
declare function scroll({ to, offset, duration, container }: ScrollConfig): void;
|
|
281
|
+
|
|
282
|
+
/**
|
|
283
|
+
* Capitalises the first letter of one word, or all words, in a string.
|
|
284
|
+
*
|
|
285
|
+
* @param str - The string.
|
|
286
|
+
* @param allWords - If all words should be capitalised.
|
|
287
|
+
* @returns The capitalised string.
|
|
288
|
+
*/
|
|
289
|
+
declare function capitalise(str: string, allWords?: boolean): string;
|
|
290
|
+
/**
|
|
291
|
+
* Separates a string into an array of characters.
|
|
292
|
+
*
|
|
293
|
+
* @param str - The string.
|
|
294
|
+
* @returns The string's characters.
|
|
295
|
+
*/
|
|
296
|
+
declare function chars(str: string): string[];
|
|
297
|
+
/**
|
|
298
|
+
* Identifies strings which only contain whitespace.
|
|
299
|
+
*
|
|
300
|
+
* @param str - The string.
|
|
301
|
+
* @returns If the string is blank.
|
|
302
|
+
*/
|
|
303
|
+
declare function isBlank(str: string): boolean;
|
|
304
|
+
/**
|
|
305
|
+
* Identifies empty strings.
|
|
306
|
+
*
|
|
307
|
+
* @param str - The string.
|
|
308
|
+
* @returns If the string is empty.
|
|
309
|
+
*/
|
|
310
|
+
declare function isEmpty(str: string): boolean;
|
|
311
|
+
/**
|
|
312
|
+
* Converts a kebab case string to camel case.
|
|
313
|
+
*
|
|
314
|
+
* @param str - The kebab case string.
|
|
315
|
+
* @returns The camel case string.
|
|
316
|
+
*/
|
|
317
|
+
declare function toCamel(str: string): string;
|
|
318
|
+
/**
|
|
319
|
+
* Converts a camel case string to kebab case.
|
|
320
|
+
*
|
|
321
|
+
* @param str - The camel case string.
|
|
322
|
+
* @returns The kebab case string.
|
|
323
|
+
*/
|
|
324
|
+
declare function toKebab(str: string): string;
|
|
325
|
+
/**
|
|
326
|
+
* Converts a string which contains a number to the number itself.
|
|
327
|
+
*
|
|
328
|
+
* @param str - The string.
|
|
329
|
+
* @returns The number.
|
|
330
|
+
*/
|
|
331
|
+
declare function toNumber(str: string): number;
|
|
332
|
+
/**
|
|
333
|
+
* Truncates a string to a provided length.
|
|
334
|
+
*
|
|
335
|
+
* @param str - The string.
|
|
336
|
+
* @param length - The length.
|
|
337
|
+
* @param truncateStr - The prefix to apply after truncation.
|
|
338
|
+
* @returns The truncated string.
|
|
339
|
+
*/
|
|
340
|
+
declare function truncate(str: string, length: number, truncateStr?: string): string;
|
|
341
|
+
|
|
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 };
|