@tempots/std 0.18.0 → 0.20.0

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/README.md CHANGED
@@ -1,3 +1,144 @@
1
- # Tempo Standard Library
1
+ # Tempo Standard Library (@tempots/std)
2
2
 
3
- A standard library for TypeScript.
3
+ A comprehensive standard library for TypeScript that provides utility functions and types commonly used in web applications. This package serves as a natural complement to the Tempo libraries but can be used independently in any TypeScript project.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@tempots/std.svg)](https://www.npmjs.com/package/@tempots/std)
6
+ [![license](https://img.shields.io/npm/l/@tempots/std.svg)](https://github.com/fponticelli/tempots/blob/main/LICENSE)
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ # npm
12
+ npm install @tempots/std
13
+
14
+ # yarn
15
+ yarn add @tempots/std
16
+
17
+ # pnpm
18
+ pnpm add @tempots/std
19
+ ```
20
+
21
+ ## Features
22
+
23
+ The library provides utility functions for working with:
24
+
25
+ ### Array Operations
26
+
27
+ ```typescript
28
+ import { filterArray, mapArray, uniquePrimitives } from '@tempots/std'
29
+ // or
30
+ import { filterArray, mapArray, uniquePrimitives } from '@tempots/std/array'
31
+
32
+ // Filter an array
33
+ const numbers = [1, 2, 3, 4, 5]
34
+ const evenNumbers = filterArray(numbers, n => n % 2 === 0) // [2, 4]
35
+
36
+ // Map an array
37
+ const doubled = mapArray(numbers, n => n * 2) // [2, 4, 6, 8, 10]
38
+
39
+ // Get unique values
40
+ const withDuplicates = [1, 2, 2, 3, 3, 3]
41
+ const unique = uniquePrimitives(withDuplicates) // [1, 2, 3]
42
+ ```
43
+
44
+ ### String Utilities
45
+
46
+ ```typescript
47
+ import { capitalizeWords, ellipsis } from '@tempots/std'
48
+ // or
49
+ import { capitalizeWords, ellipsis } from '@tempots/std/string'
50
+
51
+ // Capitalize words
52
+ const capitalized = capitalizeWords('hello world') // 'Hello World'
53
+
54
+ // Truncate with ellipsis
55
+ const truncated = ellipsis('This is a very long text', 10) // 'This is a...'
56
+ ```
57
+
58
+ ### Async Utilities
59
+
60
+ ```typescript
61
+ import { deferred } from '@tempots/std'
62
+ // or
63
+ import { deferred } from '@tempots/std/deferred'
64
+
65
+ // Create a deferred promise
66
+ const { promise, resolve, reject } = deferred<number>()
67
+
68
+ // Use the promise
69
+ promise.then(value => console.log(value))
70
+
71
+ // Resolve it later
72
+ setTimeout(() => resolve(42), 1000)
73
+ ```
74
+
75
+ ### Timer Functions
76
+
77
+ ```typescript
78
+ import { delayed, interval } from '@tempots/std'
79
+ // or
80
+ import { delayed, interval } from '@tempots/std/timer'
81
+
82
+ // Delay execution
83
+ const cancelDelay = delayed(() => {
84
+ console.log('Executed after 1 second')
85
+ }, 1000)
86
+
87
+ // Set up an interval
88
+ const cancelInterval = interval(() => {
89
+ console.log('Executed every 2 seconds')
90
+ }, 2000)
91
+
92
+ // Cancel if needed
93
+ cancelDelay() // Cancel the delayed execution
94
+ cancelInterval() // Stop the interval
95
+ ```
96
+
97
+ ### Result and Validation
98
+
99
+ ```typescript
100
+ import { Result, success, failure } from '@tempots/std'
101
+ // or
102
+ import { Result, success, failure } from '@tempots/std/result'
103
+
104
+ // Create success or failure results
105
+ const successResult = success(42)
106
+ const failureResult = failure('Something went wrong')
107
+
108
+ // Handle results
109
+ successResult.match({
110
+ success: value => console.log(`Success: ${value}`),
111
+ failure: error => console.error(`Error: ${error}`)
112
+ })
113
+ ```
114
+
115
+ ## Available Modules
116
+
117
+ The library is organized into the following modules:
118
+
119
+ - `array` - Array manipulation utilities
120
+ - `async-result` - Asynchronous result handling
121
+ - `bigint` - BigInt utilities
122
+ - `boolean` - Boolean utilities
123
+ - `deferred` - Promise deferral utilities
124
+ - `domain` - Domain-specific types
125
+ - `equal` - Deep equality comparison
126
+ - `error` - Error handling utilities
127
+ - `function` - Function composition and manipulation
128
+ - `json` - JSON utilities
129
+ - `number` - Number utilities
130
+ - `object` - Object manipulation
131
+ - `promise` - Promise utilities
132
+ - `regexp` - Regular expression utilities
133
+ - `result` - Result type for error handling
134
+ - `string` - String manipulation utilities
135
+ - `timer` - Timing utilities
136
+ - `validation` - Data validation utilities
137
+
138
+ ## Documentation
139
+
140
+ For comprehensive documentation, visit the [Tempo Documentation Site](https://tempo-ts.com/library/tempots-std.html).
141
+
142
+ ## License
143
+
144
+ This package is licensed under the Apache License 2.0.
package/array.d.ts CHANGED
@@ -1,23 +1,92 @@
1
1
  import { Compare, Maybe, Nothing, Primitive } from './domain';
2
2
  /**
3
- * Applies a function to each element of an array and returns a new array with the results.
4
- *
5
- * @typeParam A - The type of the elements in the input array.
6
- * @typeParam B - The type of the elements in the output array.
7
- * @param arr - The input array.
8
- * @param f - The function to apply to each element.
9
- * @returns The new array with the results of applying the function to each element.
3
+ * Transforms each element of an array using a mapping function, returning a new array.
4
+ *
5
+ * This is a functional programming utility that creates a new array by applying a transformation
6
+ * function to each element of the input array. The original array is not modified.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // Transform numbers to strings
11
+ * const numbers = [1, 2, 3, 4, 5]
12
+ * const strings = mapArray(numbers, n => `Number: ${n}`)
13
+ * // Result: ['Number: 1', 'Number: 2', 'Number: 3', 'Number: 4', 'Number: 5']
14
+ * ```
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * // Transform objects with index
19
+ * const users = [{ name: 'Alice' }, { name: 'Bob' }]
20
+ * const indexed = mapArray(users, (user, index) => ({
21
+ * ...user,
22
+ * id: index + 1
23
+ * }))
24
+ * // Result: [{ name: 'Alice', id: 1 }, { name: 'Bob', id: 2 }]
25
+ * ```
26
+ *
27
+ * @example
28
+ * ```typescript
29
+ * // Use with signals in Tempo
30
+ * const items = prop([1, 2, 3])
31
+ * const doubled = items.map(arr => mapArray(arr, n => n * 2))
32
+ * ```
33
+ *
34
+ * @typeParam A - The type of elements in the input array
35
+ * @typeParam B - The type of elements in the output array
36
+ * @param arr - The input array to transform
37
+ * @param f - Function that transforms each element (receives element and index)
38
+ * @returns A new array with the transformed elements
10
39
  * @public
11
40
  */
12
41
  export declare const mapArray: <A, B>(arr: A[], f: (a: A, index: number) => B) => B[];
13
42
  /**
14
- * Applies a mapping function to each element of an array and flattens the result.
15
- *
16
- * @param arr - The input array.
17
- * @param f - The mapping function to apply to each element of the array.
18
- * @returns A new array with the flattened result of applying the mapping function to each element of the input array.
19
- * @typeParam A - The type of the elements in the input array.
20
- * @typeParam B - The type of the elements in the resulting flattened array.
43
+ * Transforms each element of an array into an array, then flattens all results into a single array.
44
+ *
45
+ * This function combines mapping and flattening operations. It applies a transformation function
46
+ * to each element that returns an array, then concatenates all the resulting arrays into one.
47
+ * This is useful for operations that need to expand elements into multiple items.
48
+ *
49
+ * @example
50
+ * ```typescript
51
+ * // Split strings and flatten
52
+ * const sentences = ['hello world', 'foo bar', 'baz qux']
53
+ * const words = flatMapArray(sentences, sentence => sentence.split(' '))
54
+ * // Result: ['hello', 'world', 'foo', 'bar', 'baz', 'qux']
55
+ * ```
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * // Expand objects into multiple items
60
+ * const users = [
61
+ * { name: 'Alice', skills: ['JS', 'TS'] },
62
+ * { name: 'Bob', skills: ['Python', 'Go'] }
63
+ * ]
64
+ * const allSkills = flatMapArray(users, user =>
65
+ * user.skills.map(skill => ({ user: user.name, skill }))
66
+ * )
67
+ * // Result: [
68
+ * // { user: 'Alice', skill: 'JS' },
69
+ * // { user: 'Alice', skill: 'TS' },
70
+ * // { user: 'Bob', skill: 'Python' },
71
+ * // { user: 'Bob', skill: 'Go' }
72
+ * // ]
73
+ * ```
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * // Generate ranges
78
+ * const ranges = [2, 3, 1]
79
+ * const numbers = flatMapArray(ranges, n =>
80
+ * Array.from({ length: n }, (_, i) => i)
81
+ * )
82
+ * // Result: [0, 1, 0, 1, 2, 0]
83
+ * ```
84
+ *
85
+ * @typeParam A - The type of elements in the input array
86
+ * @typeParam B - The type of elements in the resulting flattened array
87
+ * @param arr - The input array to transform and flatten
88
+ * @param f - Function that transforms each element into an array
89
+ * @returns A new flattened array containing all elements from the transformation results
21
90
  * @public
22
91
  */
23
92
  export declare const flatMapArray: <A, B>(arr: A[], f: (a: A) => B[]) => B[];
@@ -44,11 +113,11 @@ export declare const arrayTail: <A>(arr: A[]) => A[];
44
113
  * @typeParam T - The type of elements in the arrays.
45
114
  * @param a - The first array.
46
115
  * @param b - The second array.
47
- * @param equality - The custom equality function to compare elements.
116
+ * @param equals - The custom equality function to compare elements.
48
117
  * @returns Returns `true` if the arrays are equal, `false` otherwise.
49
118
  * @public
50
119
  */
51
- export declare const areArraysEqual: <T>(a: T[], b: T[], equality: (a: T, b: T) => boolean) => boolean;
120
+ export declare const areArraysEqual: <T>(a: T[], b: T[], equals: (a: T, b: T) => boolean) => boolean;
52
121
  /**
53
122
  * Checks if an array is empty.
54
123
  *
@@ -66,12 +135,43 @@ export declare const isArrayEmpty: <T>(arr: T[]) => arr is [];
66
135
  */
67
136
  export declare const arrayHasValues: <T>(arr: T[]) => arr is [T, ...T[]];
68
137
  /**
69
- * Filters the elements of an array based on a predicate function.
70
- *
71
- * @typeParam T - The type of the elements in the array.
72
- * @param arr - The array to filter.
73
- * @param predicate - The predicate function used to filter the elements.
74
- * @returns The filtered array.
138
+ * Creates a new array containing only elements that satisfy the predicate function.
139
+ *
140
+ * This function provides a functional approach to filtering arrays, creating a new array
141
+ * without modifying the original. Elements are included in the result only if the predicate
142
+ * function returns `true` for that element.
143
+ *
144
+ * @example
145
+ * ```typescript
146
+ * // Filter even numbers
147
+ * const numbers = [1, 2, 3, 4, 5, 6]
148
+ * const evenNumbers = filterArray(numbers, n => n % 2 === 0)
149
+ * // Result: [2, 4, 6]
150
+ * ```
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * // Filter objects by property
155
+ * const users = [
156
+ * { name: 'Alice', active: true },
157
+ * { name: 'Bob', active: false },
158
+ * { name: 'Charlie', active: true }
159
+ * ]
160
+ * const activeUsers = filterArray(users, user => user.active)
161
+ * // Result: [{ name: 'Alice', active: true }, { name: 'Charlie', active: true }]
162
+ * ```
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * // Use with signals in Tempo
167
+ * const allItems = prop([1, 2, 3, 4, 5])
168
+ * const evenItems = allItems.map(arr => filterArray(arr, n => n % 2 === 0))
169
+ * ```
170
+ *
171
+ * @typeParam T - The type of elements in the array
172
+ * @param arr - The array to filter
173
+ * @param predicate - Function that tests each element (returns true to include the element)
174
+ * @returns A new array containing only elements that satisfy the predicate
75
175
  * @public
76
176
  */
77
177
  export declare const filterArray: <T>(arr: T[], predicate: (v: T) => boolean) => T[];
@@ -106,14 +206,50 @@ export declare const filterNullsFromArray: <T>(arr: Array<T | Nothing>) => T[];
106
206
  */
107
207
  export declare const flattenArray: <T>(arr: T[][]) => T[];
108
208
  /**
109
- * Applies a function to each element of an array, accumulating the result from left to right.
110
- *
111
- * @typeParam T - The type of the array elements.
112
- * @typeParam B - The type of the accumulator.
113
- * @param arr - The array to iterate over.
114
- * @param f - The function to apply to each element.
115
- * @param b - The initial value of the accumulator.
116
- * @returns The accumulated result.
209
+ * Reduces an array to a single value by applying an accumulator function from left to right.
210
+ *
211
+ * This function processes each element of the array in order, passing the current accumulator
212
+ * value and the current element to the reducer function. The result becomes the new accumulator
213
+ * value for the next iteration.
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * // Sum all numbers
218
+ * const numbers = [1, 2, 3, 4, 5]
219
+ * const sum = foldLeftArray(numbers, (acc, curr) => acc + curr, 0)
220
+ * // Result: 15
221
+ * ```
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * // Build an object from array
226
+ * const items = ['apple', 'banana', 'cherry']
227
+ * const indexed = foldLeftArray(
228
+ * items,
229
+ * (acc, item, index) => ({ ...acc, [index]: item }),
230
+ * {} as Record<number, string>
231
+ * )
232
+ * // Result: { 0: 'apple', 1: 'banana', 2: 'cherry' }
233
+ * ```
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * // Count occurrences
238
+ * const words = ['apple', 'banana', 'apple', 'cherry', 'banana', 'apple']
239
+ * const counts = foldLeftArray(
240
+ * words,
241
+ * (acc, word) => ({ ...acc, [word]: (acc[word] || 0) + 1 }),
242
+ * {} as Record<string, number>
243
+ * )
244
+ * // Result: { apple: 3, banana: 2, cherry: 1 }
245
+ * ```
246
+ *
247
+ * @typeParam T - The type of elements in the array
248
+ * @typeParam B - The type of the accumulator value
249
+ * @param arr - The array to reduce
250
+ * @param f - Function that combines the accumulator with each element
251
+ * @param b - The initial accumulator value
252
+ * @returns The final accumulated result
117
253
  * @public
118
254
  */
119
255
  export declare const foldLeftArray: <T, B>(arr: T[], f: (acc: B, curr: T) => B, b: B) => B;
@@ -206,21 +342,104 @@ export declare const generateSequenceArray: (length: number, startAt?: number) =
206
342
  */
207
343
  export declare const createFilledArray: <A>(length: number, value: A) => A[];
208
344
  /**
209
- * Returns an array containing only the distinct primitive values from the input array.
210
- *
211
- * @typeParam T - The type of the input array elements.
212
- * @param values - The input array.
213
- * @returns An array containing only the distinct primitive values from the input array.
345
+ * Removes duplicate primitive values from an array, returning only unique values.
346
+ *
347
+ * This function uses JavaScript's Set to efficiently remove duplicates from arrays
348
+ * containing primitive values (strings, numbers, booleans, symbols). The order of
349
+ * first occurrence is preserved.
350
+ *
351
+ * @example
352
+ * ```typescript
353
+ * // Remove duplicate numbers
354
+ * const numbers = [1, 2, 2, 3, 1, 4, 3]
355
+ * const unique = uniquePrimitives(numbers)
356
+ * // Result: [1, 2, 3, 4]
357
+ * ```
358
+ *
359
+ * @example
360
+ * ```typescript
361
+ * // Remove duplicate strings
362
+ * const tags = ['react', 'vue', 'react', 'angular', 'vue']
363
+ * const uniqueTags = uniquePrimitives(tags)
364
+ * // Result: ['react', 'vue', 'angular']
365
+ * ```
366
+ *
367
+ * @example
368
+ * ```typescript
369
+ * // Mixed primitive types
370
+ * const mixed = [1, '1', true, 1, 'hello', true, '1']
371
+ * const uniqueMixed = uniquePrimitives(mixed)
372
+ * // Result: [1, '1', true, 'hello']
373
+ * ```
374
+ *
375
+ * @typeParam T - The type of primitive elements in the array
376
+ * @param values - The input array containing primitive values
377
+ * @returns A new array with duplicate values removed, preserving order of first occurrence
214
378
  * @public
215
379
  */
216
380
  export declare const uniquePrimitives: <T extends Primitive>(values: T[]) => T[];
217
381
  /**
218
- * Returns an array of distinct elements from the input array based on the provided predicate.
219
- *
220
- * @typeParam T - The type of elements in the input array.
221
- * @param values - The input array.
222
- * @param predicate - The predicate function used to determine uniqueness.
223
- * @returns An array of distinct elements.
382
+ * Removes duplicate objects from an array based on a key extraction function.
383
+ *
384
+ * This function removes duplicates from arrays of objects by extracting a primitive
385
+ * key from each object and using that key to determine uniqueness. When duplicates
386
+ * are found, the first occurrence is kept.
387
+ *
388
+ * @example
389
+ * ```typescript
390
+ * // Remove users with duplicate IDs
391
+ * const users = [
392
+ * { id: 1, name: 'Alice' },
393
+ * { id: 2, name: 'Bob' },
394
+ * { id: 1, name: 'Alice Clone' },
395
+ * { id: 3, name: 'Charlie' }
396
+ * ]
397
+ * const uniqueUsers = uniqueByPrimitive(users, user => user.id)
398
+ * // Result: [
399
+ * // { id: 1, name: 'Alice' },
400
+ * // { id: 2, name: 'Bob' },
401
+ * // { id: 3, name: 'Charlie' }
402
+ * // ]
403
+ * ```
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * // Remove products with duplicate names
408
+ * const products = [
409
+ * { name: 'Laptop', price: 1000 },
410
+ * { name: 'Mouse', price: 25 },
411
+ * { name: 'Laptop', price: 1200 },
412
+ * { name: 'Keyboard', price: 75 }
413
+ * ]
414
+ * const uniqueProducts = uniqueByPrimitive(products, p => p.name)
415
+ * // Result: [
416
+ * // { name: 'Laptop', price: 1000 },
417
+ * // { name: 'Mouse', price: 25 },
418
+ * // { name: 'Keyboard', price: 75 }
419
+ * // ]
420
+ * ```
421
+ *
422
+ * @example
423
+ * ```typescript
424
+ * // Use with complex key extraction
425
+ * const events = [
426
+ * { date: '2023-01-01', type: 'click' },
427
+ * { date: '2023-01-01', type: 'hover' },
428
+ * { date: '2023-01-01', type: 'click' },
429
+ * { date: '2023-01-02', type: 'click' }
430
+ * ]
431
+ * const uniqueEvents = uniqueByPrimitive(events, e => `${e.date}-${e.type}`)
432
+ * // Result: [
433
+ * // { date: '2023-01-01', type: 'click' },
434
+ * // { date: '2023-01-01', type: 'hover' },
435
+ * // { date: '2023-01-02', type: 'click' }
436
+ * // ]
437
+ * ```
438
+ *
439
+ * @typeParam T - The type of elements in the input array
440
+ * @param values - The input array containing objects to deduplicate
441
+ * @param predicate - Function that extracts a primitive key from each element for comparison
442
+ * @returns A new array with duplicate elements removed based on the extracted key
224
443
  * @public
225
444
  */
226
445
  export declare const uniqueByPrimitive: <T>(values: T[], predicate: (a: T) => string | number | symbol) => T[];
package/array.js CHANGED
@@ -46,7 +46,7 @@ const q = (t, n) => Array.from({ length: t.length }, (e, r) => n(t[r], r)), B =
46
46
  if (a !== 0) return a;
47
47
  }
48
48
  return 0;
49
- }, C = (t, n) => t.slice().sort(n), d = (t, n) => Array.from({ length: t }, (e, r) => n(r)), L = (t, n = 0) => d(t, (e) => n + e), R = (t, n) => d(t, () => n), V = (t) => Array.from(new Set(t)), W = (t, n) => {
49
+ }, C = (t, n) => t.slice().sort(n), g = (t, n) => Array.from({ length: t }, (e, r) => n(r)), L = (t, n = 0) => g(t, (e) => n + e), R = (t, n) => g(t, () => n), V = (t) => Array.from(new Set(t)), W = (t, n) => {
50
50
  const e = {};
51
51
  return t.forEach((r) => {
52
52
  e[n(r)] = r;
@@ -98,8 +98,8 @@ const q = (t, n) => Array.from({ length: t.length }, (e, r) => n(t[r], r)), B =
98
98
  for (let s = 0; s < A.length; s++) {
99
99
  const o = e(A[s]), i = m.get(o);
100
100
  if (i == null || s === i) continue;
101
- const g = e(p[s]);
102
- m.delete(g), u.push({ from: s, to: i });
101
+ const d = e(p[s]);
102
+ m.delete(d), u.push({ from: s, to: i });
103
103
  }
104
104
  return r;
105
105
  }, U = (t, n) => {
@@ -144,7 +144,7 @@ export {
144
144
  D as flattenArray,
145
145
  P as foldLeftArray,
146
146
  T as forEachElement,
147
- d as generateArray,
147
+ g as generateArray,
148
148
  L as generateSequenceArray,
149
149
  I as isArrayEmpty,
150
150
  X as joinArrayWithConjunction,
package/function.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=e=>e,n=e=>t=>(...r)=>e(t,...r),o=e=>{let t;return()=>(t===void 0&&(t=e()),t)};exports.curryLeft=n;exports.identity=i;exports.memoize=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=e=>e,o=e=>t=>(...r)=>e(t,...r),n=e=>{let t;return()=>(t===void 0&&(t=e()),t)};exports.curryLeft=o;exports.identity=i;exports.memoize=n;
package/function.js CHANGED
@@ -1,9 +1,9 @@
1
- const r = (e) => e, i = (e) => (t) => (...n) => e(t, ...n), o = (e) => {
2
- let t;
3
- return () => (t === void 0 && (t = e()), t);
1
+ const n = (t) => t, o = (t) => (e) => (...r) => t(e, ...r), i = (t) => {
2
+ let e;
3
+ return () => (e === void 0 && (e = t()), e);
4
4
  };
5
5
  export {
6
- i as curryLeft,
7
- r as identity,
8
- o as memoize
6
+ o as curryLeft,
7
+ n as identity,
8
+ i as memoize
9
9
  };
package/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./array.cjs"),m=require("./async-result.cjs"),i=require("./bigint.cjs"),p=require("./deferred.cjs"),o=require("./equal.cjs"),l=require("./function.cjs"),a=require("./json.cjs"),t=require("./number.cjs"),s=require("./object.cjs"),y=require("./promise.cjs"),u=require("./regexp.cjs"),c=require("./result-CdwVhaAc.cjs"),e=require("./string.cjs"),n=require("./timer.cjs");exports.allElements=r.allElements;exports.anyElement=r.anyElement;exports.applyArrayDiffOperations=r.applyArrayDiffOperations;exports.areArraysEqual=r.areArraysEqual;exports.arrayDiffOperations=r.arrayDiffOperations;exports.arrayHasValues=r.arrayHasValues;exports.arrayHead=r.arrayHead;exports.arrayOfIterableIterator=r.arrayOfIterableIterator;exports.arrayTail=r.arrayTail;exports.compareArrays=r.compareArrays;exports.concatArrays=r.concatArrays;exports.createFilledArray=r.createFilledArray;exports.filterArray=r.filterArray;exports.filterMapArray=r.filterMapArray;exports.filterNullsFromArray=r.filterNullsFromArray;exports.flatMapArray=r.flatMapArray;exports.flattenArray=r.flattenArray;exports.foldLeftArray=r.foldLeftArray;exports.forEachElement=r.forEachElement;exports.generateArray=r.generateArray;exports.generateSequenceArray=r.generateSequenceArray;exports.isArrayEmpty=r.isArrayEmpty;exports.joinArrayWithConjunction=r.joinArrayWithConjunction;exports.mapArray=r.mapArray;exports.rankArray=r.rankArray;exports.removeAllFromArray=r.removeAllFromArray;exports.removeAllFromArrayByPredicate=r.removeAllFromArrayByPredicate;exports.removeOneFromArray=r.removeOneFromArray;exports.removeOneFromArrayByPredicate=r.removeOneFromArrayByPredicate;exports.sortArray=r.sortArray;exports.uniqueByPrimitive=r.uniqueByPrimitive;exports.uniquePrimitives=r.uniquePrimitives;exports.AsyncResult=m.AsyncResult;exports.biAbs=i.biAbs;exports.biCeilDiv=i.biCeilDiv;exports.biCompare=i.biCompare;exports.biFloorDiv=i.biFloorDiv;exports.biGcd=i.biGcd;exports.biIsEven=i.biIsEven;exports.biIsNegative=i.biIsNegative;exports.biIsOdd=i.biIsOdd;exports.biIsOne=i.biIsOne;exports.biIsPositive=i.biIsPositive;exports.biIsPrime=i.biIsPrime;exports.biIsZero=i.biIsZero;exports.biLcm=i.biLcm;exports.biMax=i.biMax;exports.biMin=i.biMin;exports.biNextPrime=i.biNextPrime;exports.biPow=i.biPow;exports.biPrevPrime=i.biPrevPrime;exports.deferred=p.deferred;exports.deepEqual=o.deepEqual;exports.looseEqual=o.looseEqual;exports.strictEqual=o.strictEqual;exports.curryLeft=l.curryLeft;exports.identity=l.identity;exports.memoize=l.memoize;exports.isJSONArray=a.isJSONArray;exports.isJSONObject=a.isJSONObject;exports.isJSONPrimitive=a.isJSONPrimitive;exports.parseJSON=a.parseJSON;exports.EPSILON=t.EPSILON;exports.angleDifference=t.angleDifference;exports.ceilTo=t.ceilTo;exports.clamp=t.clamp;exports.clampInt=t.clampInt;exports.clampSym=t.clampSym;exports.compareNumbers=t.compareNumbers;exports.floorTo=t.floorTo;exports.interpolate=t.interpolate;exports.interpolateAngle=t.interpolateAngle;exports.interpolateAngleCCW=t.interpolateAngleCCW;exports.interpolateAngleCW=t.interpolateAngleCW;exports.interpolateWidestAngle=t.interpolateWidestAngle;exports.nearEqualAngles=t.nearEqualAngles;exports.nearEquals=t.nearEquals;exports.nearZero=t.nearZero;exports.root=t.root;exports.roundTo=t.roundTo;exports.sign=t.sign;exports.toHex=t.toHex;exports.widestAngleDifference=t.widestAngleDifference;exports.wrap=t.wrap;exports.wrapCircular=t.wrapCircular;exports.isEmptyObject=s.isEmptyObject;exports.isObject=s.isObject;exports.mergeObjects=s.mergeObjects;exports.objectEntries=s.objectEntries;exports.objectFromEntries=s.objectFromEntries;exports.objectKeys=s.objectKeys;exports.objectValues=s.objectValues;exports.removeObjectFields=s.removeObjectFields;exports.sameObjectKeys=s.sameObjectKeys;exports.sleep=y.sleep;exports.mapRegExp=u.mapRegExp;exports.Result=c.Result;exports.Validation=c.Validation;exports.canonicalizeNewlines=e.canonicalizeNewlines;exports.capitalize=e.capitalize;exports.capitalizeWords=e.capitalizeWords;exports.chunkString=e.chunkString;exports.collapseText=e.collapseText;exports.compareCaseInsensitive=e.compareCaseInsensitive;exports.compareStrings=e.compareStrings;exports.containsAllText=e.containsAllText;exports.containsAllTextCaseInsensitive=e.containsAllTextCaseInsensitive;exports.containsAnyText=e.containsAnyText;exports.containsAnyTextCaseInsensitive=e.containsAnyTextCaseInsensitive;exports.countStringOccurrences=e.countStringOccurrences;exports.dasherize=e.dasherize;exports.decodeBase64=e.decodeBase64;exports.deleteFirstFromString=e.deleteFirstFromString;exports.deleteStringAfter=e.deleteStringAfter;exports.deleteStringBefore=e.deleteStringBefore;exports.deleteSubstring=e.deleteSubstring;exports.ellipsis=e.ellipsis;exports.ellipsisMiddle=e.ellipsisMiddle;exports.encodeBase64=e.encodeBase64;exports.filterCharcodes=e.filterCharcodes;exports.filterChars=e.filterChars;exports.humanize=e.humanize;exports.ifEmptyString=e.ifEmptyString;exports.isAlpha=e.isAlpha;exports.isAlphaNum=e.isAlphaNum;exports.isBreakingWhitespace=e.isBreakingWhitespace;exports.isDigitsOnly=e.isDigitsOnly;exports.isEmptyString=e.isEmptyString;exports.isLowerCase=e.isLowerCase;exports.isSpaceAt=e.isSpaceAt;exports.isUpperCase=e.isUpperCase;exports.jsQuote=e.jsQuote;exports.lowerCaseFirst=e.lowerCaseFirst;exports.lpad=e.lpad;exports.mapChars=e.mapChars;exports.quote=e.quote;exports.randomString=e.randomString;exports.randomStringSequence=e.randomStringSequence;exports.randomStringSequenceBase64=e.randomStringSequenceBase64;exports.repeatString=e.repeatString;exports.replaceAll=e.replaceAll;exports.reverseString=e.reverseString;exports.rpad=e.rpad;exports.smartQuote=e.smartQuote;exports.splitStringOnFirst=e.splitStringOnFirst;exports.splitStringOnLast=e.splitStringOnLast;exports.splitStringOnce=e.splitStringOnce;exports.stringContains=e.stringContains;exports.stringEndsWith=e.stringEndsWith;exports.stringEndsWithAny=e.stringEndsWithAny;exports.stringHasContent=e.stringHasContent;exports.stringHashCode=e.stringHashCode;exports.stringStartsWith=e.stringStartsWith;exports.stringStartsWithAny=e.stringStartsWithAny;exports.stringToCharcodes=e.stringToCharcodes;exports.stringToChars=e.stringToChars;exports.stringsDifferAtIndex=e.stringsDifferAtIndex;exports.substringAfter=e.substringAfter;exports.substringAfterLast=e.substringAfterLast;exports.substringBefore=e.substringBefore;exports.substringBeforeLast=e.substringBeforeLast;exports.surroundString=e.surroundString;exports.textContainsCaseInsensitive=e.textContainsCaseInsensitive;exports.textEndsWithAnyCaseInsensitive=e.textEndsWithAnyCaseInsensitive;exports.textEndsWithCaseInsensitive=e.textEndsWithCaseInsensitive;exports.textStartsWithAnyCaseInsensitive=e.textStartsWithAnyCaseInsensitive;exports.textStartsWithCaseInsensitive=e.textStartsWithCaseInsensitive;exports.textToLines=e.textToLines;exports.trimChars=e.trimChars;exports.trimCharsLeft=e.trimCharsLeft;exports.trimCharsRight=e.trimCharsRight;exports.trimStringSlice=e.trimStringSlice;exports.underscore=e.underscore;exports.upperCaseFirst=e.upperCaseFirst;exports.wrapColumns=e.wrapColumns;exports.wrapLine=e.wrapLine;exports.debounce=n.debounce;exports.delayed=n.delayed;exports.interval=n.interval;exports.throttle=n.throttle;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("./array.cjs"),p=require("./async-result.cjs"),i=require("./bigint.cjs"),s=require("./boolean.cjs"),y=require("./deferred.cjs"),l=require("./equal.cjs"),c=require("./function.cjs"),o=require("./json.cjs"),t=require("./number.cjs"),a=require("./object.cjs"),u=require("./promise.cjs"),g=require("./regexp.cjs"),m=require("./result-CdwVhaAc.cjs"),e=require("./string.cjs"),n=require("./timer.cjs");exports.allElements=r.allElements;exports.anyElement=r.anyElement;exports.applyArrayDiffOperations=r.applyArrayDiffOperations;exports.areArraysEqual=r.areArraysEqual;exports.arrayDiffOperations=r.arrayDiffOperations;exports.arrayHasValues=r.arrayHasValues;exports.arrayHead=r.arrayHead;exports.arrayOfIterableIterator=r.arrayOfIterableIterator;exports.arrayTail=r.arrayTail;exports.compareArrays=r.compareArrays;exports.concatArrays=r.concatArrays;exports.createFilledArray=r.createFilledArray;exports.filterArray=r.filterArray;exports.filterMapArray=r.filterMapArray;exports.filterNullsFromArray=r.filterNullsFromArray;exports.flatMapArray=r.flatMapArray;exports.flattenArray=r.flattenArray;exports.foldLeftArray=r.foldLeftArray;exports.forEachElement=r.forEachElement;exports.generateArray=r.generateArray;exports.generateSequenceArray=r.generateSequenceArray;exports.isArrayEmpty=r.isArrayEmpty;exports.joinArrayWithConjunction=r.joinArrayWithConjunction;exports.mapArray=r.mapArray;exports.rankArray=r.rankArray;exports.removeAllFromArray=r.removeAllFromArray;exports.removeAllFromArrayByPredicate=r.removeAllFromArrayByPredicate;exports.removeOneFromArray=r.removeOneFromArray;exports.removeOneFromArrayByPredicate=r.removeOneFromArrayByPredicate;exports.sortArray=r.sortArray;exports.uniqueByPrimitive=r.uniqueByPrimitive;exports.uniquePrimitives=r.uniquePrimitives;exports.AsyncResult=p.AsyncResult;exports.biAbs=i.biAbs;exports.biCeilDiv=i.biCeilDiv;exports.biCompare=i.biCompare;exports.biFloorDiv=i.biFloorDiv;exports.biGcd=i.biGcd;exports.biIsEven=i.biIsEven;exports.biIsNegative=i.biIsNegative;exports.biIsOdd=i.biIsOdd;exports.biIsOne=i.biIsOne;exports.biIsPositive=i.biIsPositive;exports.biIsPrime=i.biIsPrime;exports.biIsZero=i.biIsZero;exports.biLcm=i.biLcm;exports.biMax=i.biMax;exports.biMin=i.biMin;exports.biNextPrime=i.biNextPrime;exports.biPow=i.biPow;exports.biPrevPrime=i.biPrevPrime;exports.booleanToInt=s.booleanToInt;exports.canParseBoolean=s.canParseBoolean;exports.compareBooleans=s.compareBooleans;exports.parseBoolean=s.parseBoolean;exports.xorBoolean=s.xorBoolean;exports.deferred=y.deferred;exports.deepEqual=l.deepEqual;exports.looseEqual=l.looseEqual;exports.strictEqual=l.strictEqual;exports.curryLeft=c.curryLeft;exports.identity=c.identity;exports.memoize=c.memoize;exports.isJSONArray=o.isJSONArray;exports.isJSONObject=o.isJSONObject;exports.isJSONPrimitive=o.isJSONPrimitive;exports.parseJSON=o.parseJSON;exports.EPSILON=t.EPSILON;exports.angleDifference=t.angleDifference;exports.ceilTo=t.ceilTo;exports.clamp=t.clamp;exports.clampInt=t.clampInt;exports.clampSym=t.clampSym;exports.compareNumbers=t.compareNumbers;exports.floorTo=t.floorTo;exports.interpolate=t.interpolate;exports.interpolateAngle=t.interpolateAngle;exports.interpolateAngleCCW=t.interpolateAngleCCW;exports.interpolateAngleCW=t.interpolateAngleCW;exports.interpolateWidestAngle=t.interpolateWidestAngle;exports.nearEqual=t.nearEqual;exports.nearEqualAngles=t.nearEqualAngles;exports.nearZero=t.nearZero;exports.root=t.root;exports.roundTo=t.roundTo;exports.sign=t.sign;exports.toHex=t.toHex;exports.widestAngleDifference=t.widestAngleDifference;exports.wrap=t.wrap;exports.wrapCircular=t.wrapCircular;exports.isEmptyObject=a.isEmptyObject;exports.isObject=a.isObject;exports.mergeObjects=a.mergeObjects;exports.objectEntries=a.objectEntries;exports.objectFromEntries=a.objectFromEntries;exports.objectKeys=a.objectKeys;exports.objectValues=a.objectValues;exports.removeObjectFields=a.removeObjectFields;exports.sameObjectKeys=a.sameObjectKeys;exports.sleep=u.sleep;exports.mapRegExp=g.mapRegExp;exports.Result=m.Result;exports.Validation=m.Validation;exports.canonicalizeNewlines=e.canonicalizeNewlines;exports.capitalize=e.capitalize;exports.capitalizeWords=e.capitalizeWords;exports.chunkString=e.chunkString;exports.collapseText=e.collapseText;exports.compareCaseInsensitive=e.compareCaseInsensitive;exports.compareStrings=e.compareStrings;exports.containsAllText=e.containsAllText;exports.containsAllTextCaseInsensitive=e.containsAllTextCaseInsensitive;exports.containsAnyText=e.containsAnyText;exports.containsAnyTextCaseInsensitive=e.containsAnyTextCaseInsensitive;exports.countStringOccurrences=e.countStringOccurrences;exports.dasherize=e.dasherize;exports.decodeBase64=e.decodeBase64;exports.deleteFirstFromString=e.deleteFirstFromString;exports.deleteStringAfter=e.deleteStringAfter;exports.deleteStringBefore=e.deleteStringBefore;exports.deleteSubstring=e.deleteSubstring;exports.ellipsis=e.ellipsis;exports.ellipsisMiddle=e.ellipsisMiddle;exports.encodeBase64=e.encodeBase64;exports.filterCharcodes=e.filterCharcodes;exports.filterChars=e.filterChars;exports.humanize=e.humanize;exports.ifEmptyString=e.ifEmptyString;exports.isAlpha=e.isAlpha;exports.isAlphaNum=e.isAlphaNum;exports.isBreakingWhitespace=e.isBreakingWhitespace;exports.isDigitsOnly=e.isDigitsOnly;exports.isEmptyString=e.isEmptyString;exports.isLowerCase=e.isLowerCase;exports.isSpaceAt=e.isSpaceAt;exports.isUpperCase=e.isUpperCase;exports.jsQuote=e.jsQuote;exports.lowerCaseFirst=e.lowerCaseFirst;exports.lpad=e.lpad;exports.mapChars=e.mapChars;exports.quote=e.quote;exports.randomString=e.randomString;exports.randomStringSequence=e.randomStringSequence;exports.randomStringSequenceBase64=e.randomStringSequenceBase64;exports.repeatString=e.repeatString;exports.replaceAll=e.replaceAll;exports.reverseString=e.reverseString;exports.rpad=e.rpad;exports.smartQuote=e.smartQuote;exports.splitStringOnFirst=e.splitStringOnFirst;exports.splitStringOnLast=e.splitStringOnLast;exports.splitStringOnce=e.splitStringOnce;exports.stringContains=e.stringContains;exports.stringEndsWith=e.stringEndsWith;exports.stringEndsWithAny=e.stringEndsWithAny;exports.stringHasContent=e.stringHasContent;exports.stringHashCode=e.stringHashCode;exports.stringStartsWith=e.stringStartsWith;exports.stringStartsWithAny=e.stringStartsWithAny;exports.stringToCharcodes=e.stringToCharcodes;exports.stringToChars=e.stringToChars;exports.stringsDifferAtIndex=e.stringsDifferAtIndex;exports.substringAfter=e.substringAfter;exports.substringAfterLast=e.substringAfterLast;exports.substringBefore=e.substringBefore;exports.substringBeforeLast=e.substringBeforeLast;exports.surroundString=e.surroundString;exports.textContainsCaseInsensitive=e.textContainsCaseInsensitive;exports.textEndsWithAnyCaseInsensitive=e.textEndsWithAnyCaseInsensitive;exports.textEndsWithCaseInsensitive=e.textEndsWithCaseInsensitive;exports.textStartsWithAnyCaseInsensitive=e.textStartsWithAnyCaseInsensitive;exports.textStartsWithCaseInsensitive=e.textStartsWithCaseInsensitive;exports.textToLines=e.textToLines;exports.trimChars=e.trimChars;exports.trimCharsLeft=e.trimCharsLeft;exports.trimCharsRight=e.trimCharsRight;exports.trimStringSlice=e.trimStringSlice;exports.underscore=e.underscore;exports.upperCaseFirst=e.upperCaseFirst;exports.wrapColumns=e.wrapColumns;exports.wrapLine=e.wrapLine;exports.debounce=n.debounce;exports.delayed=n.delayed;exports.delayedAnimationFrame=n.delayedAnimationFrame;exports.interval=n.interval;exports.intervalAnimationFrame=n.intervalAnimationFrame;exports.throttle=n.throttle;
package/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  export * from './array';
2
2
  export * from './async-result';
3
3
  export * from './bigint';
4
+ export * from './boolean';
4
5
  export * from './deferred';
5
6
  export * from './domain';
6
7
  export * from './equal';
@@ -13,4 +14,5 @@ export * from './regexp';
13
14
  export * from './result';
14
15
  export * from './string';
15
16
  export * from './timer';
17
+ export * from './union';
16
18
  export * from './validation';
package/index.js CHANGED
@@ -1,27 +1,28 @@
1
- import { allElements as t, anyElement as i, applyArrayDiffOperations as s, areArraysEqual as a, arrayDiffOperations as n, arrayHasValues as o, arrayHead as l, arrayOfIterableIterator as m, arrayTail as p, compareArrays as c, concatArrays as y, createFilledArray as g, filterArray as A, filterMapArray as d, filterNullsFromArray as f, flatMapArray as u, flattenArray as b, foldLeftArray as S, forEachElement as C, generateArray as x, generateSequenceArray as h, isArrayEmpty as v, joinArrayWithConjunction as E, mapArray as O, rankArray as I, removeAllFromArray as F, removeAllFromArrayByPredicate as W, removeOneFromArray as j, removeOneFromArrayByPredicate as q, sortArray as P, uniqueByPrimitive as T, uniquePrimitives as L } from "./array.js";
2
- import { AsyncResult as B } from "./async-result.js";
1
+ import { allElements as t, anyElement as i, applyArrayDiffOperations as a, areArraysEqual as s, arrayDiffOperations as n, arrayHasValues as o, arrayHead as l, arrayOfIterableIterator as m, arrayTail as p, compareArrays as c, concatArrays as y, createFilledArray as A, filterArray as g, filterMapArray as d, filterNullsFromArray as f, flatMapArray as u, flattenArray as b, foldLeftArray as S, forEachElement as x, generateArray as C, generateSequenceArray as h, isArrayEmpty as v, joinArrayWithConjunction as E, mapArray as O, rankArray as I, removeAllFromArray as F, removeAllFromArrayByPredicate as B, removeOneFromArray as W, removeOneFromArrayByPredicate as j, sortArray as P, uniqueByPrimitive as T, uniquePrimitives as q } from "./array.js";
2
+ import { AsyncResult as N } from "./async-result.js";
3
3
  import { biAbs as D, biCeilDiv as z, biCompare as H, biFloorDiv as M, biGcd as R, biIsEven as J, biIsNegative as V, biIsOdd as k, biIsOne as K, biIsPositive as Q, biIsPrime as Z, biIsZero as G, biLcm as U, biMax as X, biMin as Y, biNextPrime as _, biPow as $, biPrevPrime as ee } from "./bigint.js";
4
- import { deferred as te } from "./deferred.js";
5
- import { deepEqual as se, looseEqual as ae, strictEqual as ne } from "./equal.js";
6
- import { curryLeft as le, identity as me, memoize as pe } from "./function.js";
7
- import { isJSONArray as ye, isJSONObject as ge, isJSONPrimitive as Ae, parseJSON as de } from "./json.js";
8
- import { EPSILON as ue, angleDifference as be, ceilTo as Se, clamp as Ce, clampInt as xe, clampSym as he, compareNumbers as ve, floorTo as Ee, interpolate as Oe, interpolateAngle as Ie, interpolateAngleCCW as Fe, interpolateAngleCW as We, interpolateWidestAngle as je, nearEqualAngles as qe, nearEquals as Pe, nearZero as Te, root as Le, roundTo as Ne, sign as Be, toHex as we, widestAngleDifference as De, wrap as ze, wrapCircular as He } from "./number.js";
9
- import { isEmptyObject as Re, isObject as Je, mergeObjects as Ve, objectEntries as ke, objectFromEntries as Ke, objectKeys as Qe, objectValues as Ze, removeObjectFields as Ge, sameObjectKeys as Ue } from "./object.js";
10
- import { sleep as Ye } from "./promise.js";
11
- import { mapRegExp as $e } from "./regexp.js";
12
- import { R as rr, V as tr } from "./result-CGd0jCdl.js";
13
- import { canonicalizeNewlines as sr, capitalize as ar, capitalizeWords as nr, chunkString as or, collapseText as lr, compareCaseInsensitive as mr, compareStrings as pr, containsAllText as cr, containsAllTextCaseInsensitive as yr, containsAnyText as gr, containsAnyTextCaseInsensitive as Ar, countStringOccurrences as dr, dasherize as fr, decodeBase64 as ur, deleteFirstFromString as br, deleteStringAfter as Sr, deleteStringBefore as Cr, deleteSubstring as xr, ellipsis as hr, ellipsisMiddle as vr, encodeBase64 as Er, filterCharcodes as Or, filterChars as Ir, humanize as Fr, ifEmptyString as Wr, isAlpha as jr, isAlphaNum as qr, isBreakingWhitespace as Pr, isDigitsOnly as Tr, isEmptyString as Lr, isLowerCase as Nr, isSpaceAt as Br, isUpperCase as wr, jsQuote as Dr, lowerCaseFirst as zr, lpad as Hr, mapChars as Mr, quote as Rr, randomString as Jr, randomStringSequence as Vr, randomStringSequenceBase64 as kr, repeatString as Kr, replaceAll as Qr, reverseString as Zr, rpad as Gr, smartQuote as Ur, splitStringOnFirst as Xr, splitStringOnLast as Yr, splitStringOnce as _r, stringContains as $r, stringEndsWith as et, stringEndsWithAny as rt, stringHasContent as tt, stringHashCode as it, stringStartsWith as st, stringStartsWithAny as at, stringToCharcodes as nt, stringToChars as ot, stringsDifferAtIndex as lt, substringAfter as mt, substringAfterLast as pt, substringBefore as ct, substringBeforeLast as yt, surroundString as gt, textContainsCaseInsensitive as At, textEndsWithAnyCaseInsensitive as dt, textEndsWithCaseInsensitive as ft, textStartsWithAnyCaseInsensitive as ut, textStartsWithCaseInsensitive as bt, textToLines as St, trimChars as Ct, trimCharsLeft as xt, trimCharsRight as ht, trimStringSlice as vt, underscore as Et, upperCaseFirst as Ot, wrapColumns as It, wrapLine as Ft } from "./string.js";
14
- import { debounce as jt, delayed as qt, interval as Pt, throttle as Tt } from "./timer.js";
4
+ import { booleanToInt as te, canParseBoolean as ie, compareBooleans as ae, parseBoolean as se, xorBoolean as ne } from "./boolean.js";
5
+ import { deferred as le } from "./deferred.js";
6
+ import { deepEqual as pe, looseEqual as ce, strictEqual as ye } from "./equal.js";
7
+ import { curryLeft as ge, identity as de, memoize as fe } from "./function.js";
8
+ import { isJSONArray as be, isJSONObject as Se, isJSONPrimitive as xe, parseJSON as Ce } from "./json.js";
9
+ import { EPSILON as ve, angleDifference as Ee, ceilTo as Oe, clamp as Ie, clampInt as Fe, clampSym as Be, compareNumbers as We, floorTo as je, interpolate as Pe, interpolateAngle as Te, interpolateAngleCCW as qe, interpolateAngleCW as Le, interpolateWidestAngle as Ne, nearEqual as we, nearEqualAngles as De, nearZero as ze, root as He, roundTo as Me, sign as Re, toHex as Je, widestAngleDifference as Ve, wrap as ke, wrapCircular as Ke } from "./number.js";
10
+ import { isEmptyObject as Ze, isObject as Ge, mergeObjects as Ue, objectEntries as Xe, objectFromEntries as Ye, objectKeys as _e, objectValues as $e, removeObjectFields as er, sameObjectKeys as rr } from "./object.js";
11
+ import { sleep as ir } from "./promise.js";
12
+ import { mapRegExp as sr } from "./regexp.js";
13
+ import { R as or, V as lr } from "./result-CGd0jCdl.js";
14
+ import { canonicalizeNewlines as pr, capitalize as cr, capitalizeWords as yr, chunkString as Ar, collapseText as gr, compareCaseInsensitive as dr, compareStrings as fr, containsAllText as ur, containsAllTextCaseInsensitive as br, containsAnyText as Sr, containsAnyTextCaseInsensitive as xr, countStringOccurrences as Cr, dasherize as hr, decodeBase64 as vr, deleteFirstFromString as Er, deleteStringAfter as Or, deleteStringBefore as Ir, deleteSubstring as Fr, ellipsis as Br, ellipsisMiddle as Wr, encodeBase64 as jr, filterCharcodes as Pr, filterChars as Tr, humanize as qr, ifEmptyString as Lr, isAlpha as Nr, isAlphaNum as wr, isBreakingWhitespace as Dr, isDigitsOnly as zr, isEmptyString as Hr, isLowerCase as Mr, isSpaceAt as Rr, isUpperCase as Jr, jsQuote as Vr, lowerCaseFirst as kr, lpad as Kr, mapChars as Qr, quote as Zr, randomString as Gr, randomStringSequence as Ur, randomStringSequenceBase64 as Xr, repeatString as Yr, replaceAll as _r, reverseString as $r, rpad as et, smartQuote as rt, splitStringOnFirst as tt, splitStringOnLast as it, splitStringOnce as at, stringContains as st, stringEndsWith as nt, stringEndsWithAny as ot, stringHasContent as lt, stringHashCode as mt, stringStartsWith as pt, stringStartsWithAny as ct, stringToCharcodes as yt, stringToChars as At, stringsDifferAtIndex as gt, substringAfter as dt, substringAfterLast as ft, substringBefore as ut, substringBeforeLast as bt, surroundString as St, textContainsCaseInsensitive as xt, textEndsWithAnyCaseInsensitive as Ct, textEndsWithCaseInsensitive as ht, textStartsWithAnyCaseInsensitive as vt, textStartsWithCaseInsensitive as Et, textToLines as Ot, trimChars as It, trimCharsLeft as Ft, trimCharsRight as Bt, trimStringSlice as Wt, underscore as jt, upperCaseFirst as Pt, wrapColumns as Tt, wrapLine as qt } from "./string.js";
15
+ import { debounce as Nt, delayed as wt, delayedAnimationFrame as Dt, interval as zt, intervalAnimationFrame as Ht, throttle as Mt } from "./timer.js";
15
16
  export {
16
- B as AsyncResult,
17
- ue as EPSILON,
18
- rr as Result,
19
- tr as Validation,
17
+ N as AsyncResult,
18
+ ve as EPSILON,
19
+ or as Result,
20
+ lr as Validation,
20
21
  t as allElements,
21
- be as angleDifference,
22
+ Ee as angleDifference,
22
23
  i as anyElement,
23
- s as applyArrayDiffOperations,
24
- a as areArraysEqual,
24
+ a as applyArrayDiffOperations,
25
+ s as areArraysEqual,
25
26
  n as arrayDiffOperations,
26
27
  o as arrayHasValues,
27
28
  l as arrayHead,
@@ -45,152 +46,159 @@ export {
45
46
  _ as biNextPrime,
46
47
  $ as biPow,
47
48
  ee as biPrevPrime,
48
- sr as canonicalizeNewlines,
49
- ar as capitalize,
50
- nr as capitalizeWords,
51
- Se as ceilTo,
52
- or as chunkString,
53
- Ce as clamp,
54
- xe as clampInt,
55
- he as clampSym,
56
- lr as collapseText,
49
+ te as booleanToInt,
50
+ ie as canParseBoolean,
51
+ pr as canonicalizeNewlines,
52
+ cr as capitalize,
53
+ yr as capitalizeWords,
54
+ Oe as ceilTo,
55
+ Ar as chunkString,
56
+ Ie as clamp,
57
+ Fe as clampInt,
58
+ Be as clampSym,
59
+ gr as collapseText,
57
60
  c as compareArrays,
58
- mr as compareCaseInsensitive,
59
- ve as compareNumbers,
60
- pr as compareStrings,
61
+ ae as compareBooleans,
62
+ dr as compareCaseInsensitive,
63
+ We as compareNumbers,
64
+ fr as compareStrings,
61
65
  y as concatArrays,
62
- cr as containsAllText,
63
- yr as containsAllTextCaseInsensitive,
64
- gr as containsAnyText,
65
- Ar as containsAnyTextCaseInsensitive,
66
- dr as countStringOccurrences,
67
- g as createFilledArray,
68
- le as curryLeft,
69
- fr as dasherize,
70
- jt as debounce,
71
- ur as decodeBase64,
72
- se as deepEqual,
73
- te as deferred,
74
- qt as delayed,
75
- br as deleteFirstFromString,
76
- Sr as deleteStringAfter,
77
- Cr as deleteStringBefore,
78
- xr as deleteSubstring,
79
- hr as ellipsis,
80
- vr as ellipsisMiddle,
81
- Er as encodeBase64,
82
- A as filterArray,
83
- Or as filterCharcodes,
84
- Ir as filterChars,
66
+ ur as containsAllText,
67
+ br as containsAllTextCaseInsensitive,
68
+ Sr as containsAnyText,
69
+ xr as containsAnyTextCaseInsensitive,
70
+ Cr as countStringOccurrences,
71
+ A as createFilledArray,
72
+ ge as curryLeft,
73
+ hr as dasherize,
74
+ Nt as debounce,
75
+ vr as decodeBase64,
76
+ pe as deepEqual,
77
+ le as deferred,
78
+ wt as delayed,
79
+ Dt as delayedAnimationFrame,
80
+ Er as deleteFirstFromString,
81
+ Or as deleteStringAfter,
82
+ Ir as deleteStringBefore,
83
+ Fr as deleteSubstring,
84
+ Br as ellipsis,
85
+ Wr as ellipsisMiddle,
86
+ jr as encodeBase64,
87
+ g as filterArray,
88
+ Pr as filterCharcodes,
89
+ Tr as filterChars,
85
90
  d as filterMapArray,
86
91
  f as filterNullsFromArray,
87
92
  u as flatMapArray,
88
93
  b as flattenArray,
89
- Ee as floorTo,
94
+ je as floorTo,
90
95
  S as foldLeftArray,
91
- C as forEachElement,
92
- x as generateArray,
96
+ x as forEachElement,
97
+ C as generateArray,
93
98
  h as generateSequenceArray,
94
- Fr as humanize,
95
- me as identity,
96
- Wr as ifEmptyString,
97
- Oe as interpolate,
98
- Ie as interpolateAngle,
99
- Fe as interpolateAngleCCW,
100
- We as interpolateAngleCW,
101
- je as interpolateWidestAngle,
102
- Pt as interval,
103
- jr as isAlpha,
104
- qr as isAlphaNum,
99
+ qr as humanize,
100
+ de as identity,
101
+ Lr as ifEmptyString,
102
+ Pe as interpolate,
103
+ Te as interpolateAngle,
104
+ qe as interpolateAngleCCW,
105
+ Le as interpolateAngleCW,
106
+ Ne as interpolateWidestAngle,
107
+ zt as interval,
108
+ Ht as intervalAnimationFrame,
109
+ Nr as isAlpha,
110
+ wr as isAlphaNum,
105
111
  v as isArrayEmpty,
106
- Pr as isBreakingWhitespace,
107
- Tr as isDigitsOnly,
108
- Re as isEmptyObject,
109
- Lr as isEmptyString,
110
- ye as isJSONArray,
111
- ge as isJSONObject,
112
- Ae as isJSONPrimitive,
113
- Nr as isLowerCase,
114
- Je as isObject,
115
- Br as isSpaceAt,
116
- wr as isUpperCase,
112
+ Dr as isBreakingWhitespace,
113
+ zr as isDigitsOnly,
114
+ Ze as isEmptyObject,
115
+ Hr as isEmptyString,
116
+ be as isJSONArray,
117
+ Se as isJSONObject,
118
+ xe as isJSONPrimitive,
119
+ Mr as isLowerCase,
120
+ Ge as isObject,
121
+ Rr as isSpaceAt,
122
+ Jr as isUpperCase,
117
123
  E as joinArrayWithConjunction,
118
- Dr as jsQuote,
119
- ae as looseEqual,
120
- zr as lowerCaseFirst,
121
- Hr as lpad,
124
+ Vr as jsQuote,
125
+ ce as looseEqual,
126
+ kr as lowerCaseFirst,
127
+ Kr as lpad,
122
128
  O as mapArray,
123
- Mr as mapChars,
124
- $e as mapRegExp,
125
- pe as memoize,
126
- Ve as mergeObjects,
127
- qe as nearEqualAngles,
128
- Pe as nearEquals,
129
- Te as nearZero,
130
- ke as objectEntries,
131
- Ke as objectFromEntries,
132
- Qe as objectKeys,
133
- Ze as objectValues,
134
- de as parseJSON,
135
- Rr as quote,
136
- Jr as randomString,
137
- Vr as randomStringSequence,
138
- kr as randomStringSequenceBase64,
129
+ Qr as mapChars,
130
+ sr as mapRegExp,
131
+ fe as memoize,
132
+ Ue as mergeObjects,
133
+ we as nearEqual,
134
+ De as nearEqualAngles,
135
+ ze as nearZero,
136
+ Xe as objectEntries,
137
+ Ye as objectFromEntries,
138
+ _e as objectKeys,
139
+ $e as objectValues,
140
+ se as parseBoolean,
141
+ Ce as parseJSON,
142
+ Zr as quote,
143
+ Gr as randomString,
144
+ Ur as randomStringSequence,
145
+ Xr as randomStringSequenceBase64,
139
146
  I as rankArray,
140
147
  F as removeAllFromArray,
141
- W as removeAllFromArrayByPredicate,
142
- Ge as removeObjectFields,
143
- j as removeOneFromArray,
144
- q as removeOneFromArrayByPredicate,
145
- Kr as repeatString,
146
- Qr as replaceAll,
147
- Zr as reverseString,
148
- Le as root,
149
- Ne as roundTo,
150
- Gr as rpad,
151
- Ue as sameObjectKeys,
152
- Be as sign,
153
- Ye as sleep,
154
- Ur as smartQuote,
148
+ B as removeAllFromArrayByPredicate,
149
+ er as removeObjectFields,
150
+ W as removeOneFromArray,
151
+ j as removeOneFromArrayByPredicate,
152
+ Yr as repeatString,
153
+ _r as replaceAll,
154
+ $r as reverseString,
155
+ He as root,
156
+ Me as roundTo,
157
+ et as rpad,
158
+ rr as sameObjectKeys,
159
+ Re as sign,
160
+ ir as sleep,
161
+ rt as smartQuote,
155
162
  P as sortArray,
156
- Xr as splitStringOnFirst,
157
- Yr as splitStringOnLast,
158
- _r as splitStringOnce,
159
- ne as strictEqual,
160
- $r as stringContains,
161
- et as stringEndsWith,
162
- rt as stringEndsWithAny,
163
- tt as stringHasContent,
164
- it as stringHashCode,
165
- st as stringStartsWith,
166
- at as stringStartsWithAny,
167
- nt as stringToCharcodes,
168
- ot as stringToChars,
169
- lt as stringsDifferAtIndex,
170
- mt as substringAfter,
171
- pt as substringAfterLast,
172
- ct as substringBefore,
173
- yt as substringBeforeLast,
174
- gt as surroundString,
175
- At as textContainsCaseInsensitive,
176
- dt as textEndsWithAnyCaseInsensitive,
177
- ft as textEndsWithCaseInsensitive,
178
- ut as textStartsWithAnyCaseInsensitive,
179
- bt as textStartsWithCaseInsensitive,
180
- St as textToLines,
181
- Tt as throttle,
182
- we as toHex,
183
- Ct as trimChars,
184
- xt as trimCharsLeft,
185
- ht as trimCharsRight,
186
- vt as trimStringSlice,
187
- Et as underscore,
163
+ tt as splitStringOnFirst,
164
+ it as splitStringOnLast,
165
+ at as splitStringOnce,
166
+ ye as strictEqual,
167
+ st as stringContains,
168
+ nt as stringEndsWith,
169
+ ot as stringEndsWithAny,
170
+ lt as stringHasContent,
171
+ mt as stringHashCode,
172
+ pt as stringStartsWith,
173
+ ct as stringStartsWithAny,
174
+ yt as stringToCharcodes,
175
+ At as stringToChars,
176
+ gt as stringsDifferAtIndex,
177
+ dt as substringAfter,
178
+ ft as substringAfterLast,
179
+ ut as substringBefore,
180
+ bt as substringBeforeLast,
181
+ St as surroundString,
182
+ xt as textContainsCaseInsensitive,
183
+ Ct as textEndsWithAnyCaseInsensitive,
184
+ ht as textEndsWithCaseInsensitive,
185
+ vt as textStartsWithAnyCaseInsensitive,
186
+ Et as textStartsWithCaseInsensitive,
187
+ Ot as textToLines,
188
+ Mt as throttle,
189
+ Je as toHex,
190
+ It as trimChars,
191
+ Ft as trimCharsLeft,
192
+ Bt as trimCharsRight,
193
+ Wt as trimStringSlice,
194
+ jt as underscore,
188
195
  T as uniqueByPrimitive,
189
- L as uniquePrimitives,
190
- Ot as upperCaseFirst,
191
- De as widestAngleDifference,
192
- ze as wrap,
193
- He as wrapCircular,
194
- It as wrapColumns,
195
- Ft as wrapLine
196
+ q as uniquePrimitives,
197
+ Pt as upperCaseFirst,
198
+ Ve as widestAngleDifference,
199
+ ke as wrap,
200
+ Ke as wrapCircular,
201
+ Tt as wrapColumns,
202
+ qt as wrapLine,
203
+ ne as xorBoolean
196
204
  };
package/number.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./string.cjs"),i=1e-9,l=(e,t,n=360)=>{let r=(t-e)%n;return r<0&&(r+=n),r>n/2&&(r-=n),r},f=(e,t)=>{const n=Math.pow(10,t);return Math.ceil(e*n)/n},c=(e,t,n)=>Math.min(Math.max(e,t),n),g=(e,t,n)=>Math.trunc(c(e,t,n)),u=(e,t)=>c(e,-t,t),M=(e,t)=>e<t?-1:e>t?1:0,h=(e,t)=>{const n=Math.pow(10,t);return Math.floor(e*n)/n},A=(e,t=0)=>p.lpad(e.toString(16),"0",t),s=(e,t,n)=>(t-e)*n+e,d=(e,t,n,r=360)=>o(s(e,e+l(e,t,r),n),r),a=(e,t,n=360)=>{let r=(t-e)%n;return r<0&&(r+=n),r>n/2&&(r-=n),r},w=(e,t,n,r=360)=>o(s(e,e+a(e,t,r),n),r),N=(e,t,n,r=360)=>(e=o(e,r),t=o(t,r),t<e&&(t+=r),o(s(e,t,n),r)),m=(e,t,n,r=360)=>(e=o(e,r),t=o(t,r),t>e&&(t-=r),o(s(e,t,n),r)),C=(e,t,n=i)=>isFinite(e)?isFinite(t)?Math.abs(e-t)<=n:!1:isNaN(e)?isNaN(t):isNaN(t)||isFinite(t)?!1:e>0==t>0,S=(e,t,n=360,r=i)=>Math.abs(l(e,t,n))<=r,T=(e,t=i)=>Math.abs(e)<=t,E=(e,t)=>Math.pow(e,1/t),W=(e,t)=>{const n=Math.pow(10,t);return Math.round(e*n)/n},q=e=>e<0?-1:1,y=(e,t,n)=>{const r=n-t+1;return e<t&&(e+=r*((t-e)/r+1)),t+(e-t)%r},o=(e,t)=>(e=e%t,e<0&&(e+=t),e);exports.EPSILON=i;exports.angleDifference=l;exports.ceilTo=f;exports.clamp=c;exports.clampInt=g;exports.clampSym=u;exports.compareNumbers=M;exports.floorTo=h;exports.interpolate=s;exports.interpolateAngle=d;exports.interpolateAngleCCW=m;exports.interpolateAngleCW=N;exports.interpolateWidestAngle=w;exports.nearEqualAngles=S;exports.nearEquals=C;exports.nearZero=T;exports.root=E;exports.roundTo=W;exports.sign=q;exports.toHex=A;exports.widestAngleDifference=a;exports.wrap=y;exports.wrapCircular=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("./string.cjs"),s=1e-9,l=(e,t,n=360)=>{let r=(t-e)%n;return r<0&&(r+=n),r>n/2&&(r-=n),r},f=(e,t)=>{const n=Math.pow(10,t);return Math.ceil(e*n)/n},c=(e,t,n)=>Math.min(Math.max(e,t),n),g=(e,t,n)=>Math.trunc(c(e,t,n)),u=(e,t)=>c(e,-t,t),M=(e,t)=>e<t?-1:e>t?1:0,h=(e,t)=>{const n=Math.pow(10,t);return Math.floor(e*n)/n},A=(e,t=0)=>p.lpad(e.toString(16),"0",t),i=(e,t,n)=>(t-e)*n+e,d=(e,t,n,r=360)=>o(i(e,e+l(e,t,r),n),r),a=(e,t,n=360)=>{let r=(t-e)%n;return r<0&&(r+=n),r>n/2&&(r-=n),r},w=(e,t,n,r=360)=>o(i(e,e+a(e,t,r),n),r),N=(e,t,n,r=360)=>(e=o(e,r),t=o(t,r),t<e&&(t+=r),o(i(e,t,n),r)),m=(e,t,n,r=360)=>(e=o(e,r),t=o(t,r),t>e&&(t-=r),o(i(e,t,n),r)),C=(e,t,n=s)=>isFinite(e)?isFinite(t)?Math.abs(e-t)<=n:!1:isNaN(e)?isNaN(t):isNaN(t)||isFinite(t)?!1:e>0==t>0,S=(e,t,n=360,r=s)=>Math.abs(l(e,t,n))<=r,T=(e,t=s)=>Math.abs(e)<=t,E=(e,t)=>Math.pow(e,1/t),W=(e,t)=>{const n=Math.pow(10,t);return Math.round(e*n)/n},q=e=>e<0?-1:1,y=(e,t,n)=>{const r=n-t+1;return e<t&&(e+=r*((t-e)/r+1)),t+(e-t)%r},o=(e,t)=>(e=e%t,e<0&&(e+=t),e);exports.EPSILON=s;exports.angleDifference=l;exports.ceilTo=f;exports.clamp=c;exports.clampInt=g;exports.clampSym=u;exports.compareNumbers=M;exports.floorTo=h;exports.interpolate=i;exports.interpolateAngle=d;exports.interpolateAngleCCW=m;exports.interpolateAngleCW=N;exports.interpolateWidestAngle=w;exports.nearEqual=C;exports.nearEqualAngles=S;exports.nearZero=T;exports.root=E;exports.roundTo=W;exports.sign=q;exports.toHex=A;exports.widestAngleDifference=a;exports.wrap=y;exports.wrapCircular=o;
package/number.d.ts CHANGED
@@ -238,7 +238,7 @@ export declare const interpolateAngleCW: (a: number, b: number, t: number, turn?
238
238
  export declare const interpolateAngleCCW: (a: number, b: number, t: number, turn?: number) => number;
239
239
  /**
240
240
  * number numbers can sometime introduce tiny errors even for simple operations.
241
- * `nearEquals` compares two floats using a tiny tollerance (last optional
241
+ * `nearEqual` compares two floats using a tiny tollerance (last optional
242
242
  * argument). By default it is defined as `EPSILON`.
243
243
  *
244
244
  * @param a - The first number to compare.
@@ -248,12 +248,12 @@ export declare const interpolateAngleCCW: (a: number, b: number, t: number, turn
248
248
  * @public
249
249
  * @example
250
250
  * ```ts
251
- * nearEquals(5, 5.000000000000001) // returns true
252
- * nearEquals(5, 5.000000000001) // returns false
253
- * nearEquals(5, 5.000000000001, 1e-9) // returns true
251
+ * nearEqual(5, 5.000000000000001) // returns true
252
+ * nearEqual(5, 5.000000000001) // returns false
253
+ * nearEqual(5, 5.000000000001, 1e-9) // returns true
254
254
  * ```
255
255
  **/
256
- export declare const nearEquals: (a: number, b: number, tollerance?: number) => boolean;
256
+ export declare const nearEqual: (a: number, b: number, tollerance?: number) => boolean;
257
257
  /**
258
258
  * number numbers can sometime introduce tiny errors even for simple operations.
259
259
  * `nearEqualAngles` compares two angles (default is 360deg) using a tiny
package/number.js CHANGED
@@ -32,8 +32,8 @@ export {
32
32
  C as interpolateAngleCCW,
33
33
  m as interpolateAngleCW,
34
34
  d as interpolateWidestAngle,
35
+ E as nearEqual,
35
36
  F as nearEqualAngles,
36
- E as nearEquals,
37
37
  S as nearZero,
38
38
  T as root,
39
39
  W as roundTo,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tempots/std",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "priority": 8,
5
5
  "description": "Std library for TypeScript. Natural complement to the Tempo libraries.",
6
6
  "keywords": [
@@ -93,6 +93,10 @@
93
93
  "import": "./timer.js",
94
94
  "require": "./timer.cjs"
95
95
  },
96
+ "./union": {
97
+ "import": "./union.js",
98
+ "require": "./union.cjs"
99
+ },
96
100
  "./validation": {
97
101
  "import": "./validation.js",
98
102
  "require": "./validation.cjs"
@@ -159,6 +163,9 @@
159
163
  "timer": [
160
164
  "./timer.d.ts"
161
165
  ],
166
+ "union": [
167
+ "./union.d.ts"
168
+ ],
162
169
  "validation": [
163
170
  "./validation.d.ts"
164
171
  ]
package/timer.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=(e,t)=>{const n=setTimeout(e,t);return()=>clearTimeout(n)},w=(e,t)=>{const n=setInterval(e,t);return()=>clearInterval(n)},b=(e,t,n={})=>{const{noTrailing:s=!1,noLeading:u=!1,debounceMode:c}=n;let o,f=!1,i=0;function d(){o&&clearTimeout(o)}function g(a){const{upcomingOnly:r=!1}=a||{};d(),f=!r}function m(...a){if(f)return;const r=this,T=Date.now()-i;function l(){i=Date.now(),t.apply(r,a)}function p(){o=void 0}!u&&c&&!o&&l(),d(),c===void 0&&T>e?u?(i=Date.now(),s||(o=setTimeout(c?p:l,e))):l():s||(o=setTimeout(c?p:l,c===void 0?e-T:e))}return m.cancel=g,m},D=(e,t,{atBegin:n=!1}={})=>b(e,t,{debounceMode:n!==!1});exports.debounce=D;exports.delayed=v;exports.interval=w;exports.throttle=b;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=(n,e)=>{const t=setTimeout(n,e);return()=>clearTimeout(t)},b=(n,e)=>{const t=setInterval(n,e);return()=>clearInterval(t)},F=(n,e,t={})=>{const{noTrailing:o=!1,noLeading:l=!1,debounceMode:i}=t;let a,m=!1,c=0;function f(){a&&clearTimeout(a)}function T(u){const{upcomingOnly:s=!1}=u||{};f(),m=!s}function d(...u){if(m)return;const s=this,v=Date.now()-c;function r(){c=Date.now(),e.apply(s,u)}function A(){a=void 0}!l&&i&&!a&&r(),f(),i===void 0&&v>n?l?(c=Date.now(),o||(a=setTimeout(i?A:r,n))):r():o||(a=setTimeout(i?A:r,i===void 0?n-v:n))}return d.cancel=T,d},g=(n,e,{atBegin:t=!1}={})=>F(n,e,{debounceMode:t!==!1}),y=n=>{let e=null;const t=l=>{e=null,n(l)};return(()=>{e==null&&(e=requestAnimationFrame(t))})(),()=>{e!=null&&(cancelAnimationFrame(e),e=null)}},I=n=>{let e=null;const t=l=>{e=requestAnimationFrame(t),n(l)};return(()=>{e==null&&(e=requestAnimationFrame(t))})(),()=>{e!=null&&(cancelAnimationFrame(e),e=null)}};exports.debounce=g;exports.delayed=p;exports.delayedAnimationFrame=y;exports.interval=b;exports.intervalAnimationFrame=I;exports.throttle=F;
package/timer.d.ts CHANGED
@@ -163,3 +163,17 @@ export type DebounceOptions = {
163
163
  * @public
164
164
  */
165
165
  export declare const debounce: <FN extends (...args: unknown[]) => void>(delay: number, callback: FN, { atBegin }?: DebounceOptions) => ThrottledFunction<Parameters<FN>>;
166
+ /**
167
+ * Delays the execution of a function using requestAnimationFrame.
168
+ *
169
+ * @param callback - The function to delay.
170
+ * @returns A function that, when called, will cancel the delay and prevent the original function from being executed.
171
+ */
172
+ export declare const delayedAnimationFrame: (callback: (time: DOMHighResTimeStamp) => void) => () => void;
173
+ /**
174
+ * Executes a function repeatedly using requestAnimationFrame.
175
+ *
176
+ * @param callback - The function to execute periodically.
177
+ * @returns A function that, when called, will cancel the interval and stop future executions.
178
+ */
179
+ export declare const intervalAnimationFrame: (callback: (time: DOMHighResTimeStamp) => void) => () => void;
package/timer.js CHANGED
@@ -1,38 +1,60 @@
1
- const x = (e, n) => {
2
- const t = setTimeout(e, n);
1
+ const T = (n, e) => {
2
+ const t = setTimeout(n, e);
3
3
  return () => clearTimeout(t);
4
- }, D = (e, n) => {
5
- const t = setInterval(e, n);
4
+ }, I = (n, e) => {
5
+ const t = setInterval(n, e);
6
6
  return () => clearInterval(t);
7
- }, w = (e, n, t = {}) => {
8
- const { noTrailing: r = !1, noLeading: u = !1, debounceMode: c } = t;
9
- let o, f = !1, l = 0;
10
- function d() {
7
+ }, F = (n, e, t = {}) => {
8
+ const { noTrailing: a = !1, noLeading: l = !1, debounceMode: i } = t;
9
+ let o, f = !1, c = 0;
10
+ function m() {
11
11
  o && clearTimeout(o);
12
12
  }
13
- function g(s) {
14
- const { upcomingOnly: a = !1 } = s || {};
15
- d(), f = !a;
13
+ function A(u) {
14
+ const { upcomingOnly: s = !1 } = u || {};
15
+ m(), f = !s;
16
16
  }
17
- function m(...s) {
17
+ function d(...u) {
18
18
  if (f) return;
19
- const a = this, p = Date.now() - l;
20
- function i() {
21
- l = Date.now(), n.apply(a, s);
19
+ const s = this, p = Date.now() - c;
20
+ function r() {
21
+ c = Date.now(), e.apply(s, u);
22
22
  }
23
- function T() {
23
+ function v() {
24
24
  o = void 0;
25
25
  }
26
- !u && c && !o && i(), d(), c === void 0 && p > e ? u ? (l = Date.now(), r || (o = setTimeout(c ? T : i, e))) : i() : r || (o = setTimeout(
27
- c ? T : i,
28
- c === void 0 ? e - p : e
26
+ !l && i && !o && r(), m(), i === void 0 && p > n ? l ? (c = Date.now(), a || (o = setTimeout(i ? v : r, n))) : r() : a || (o = setTimeout(
27
+ i ? v : r,
28
+ i === void 0 ? n - p : n
29
29
  ));
30
30
  }
31
- return m.cancel = g, m;
32
- }, b = (e, n, { atBegin: t = !1 } = {}) => w(e, n, { debounceMode: t !== !1 });
31
+ return d.cancel = A, d;
32
+ }, g = (n, e, { atBegin: t = !1 } = {}) => F(n, e, { debounceMode: t !== !1 }), w = (n) => {
33
+ let e = null;
34
+ const t = (l) => {
35
+ e = null, n(l);
36
+ };
37
+ return (() => {
38
+ e == null && (e = requestAnimationFrame(t));
39
+ })(), () => {
40
+ e != null && (cancelAnimationFrame(e), e = null);
41
+ };
42
+ }, x = (n) => {
43
+ let e = null;
44
+ const t = (l) => {
45
+ e = requestAnimationFrame(t), n(l);
46
+ };
47
+ return (() => {
48
+ e == null && (e = requestAnimationFrame(t));
49
+ })(), () => {
50
+ e != null && (cancelAnimationFrame(e), e = null);
51
+ };
52
+ };
33
53
  export {
34
- b as debounce,
35
- x as delayed,
36
- D as interval,
37
- w as throttle
54
+ g as debounce,
55
+ T as delayed,
56
+ w as delayedAnimationFrame,
57
+ I as interval,
58
+ x as intervalAnimationFrame,
59
+ F as throttle
38
60
  };
package/union.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";
package/union.d.ts ADDED
@@ -0,0 +1 @@
1
+ export type IsUnion<T, U = T> = T extends any ? [U] extends [T] ? false : true : never;
package/union.js ADDED
@@ -0,0 +1 @@
1
+