@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 +143 -2
- package/array.d.ts +260 -41
- package/array.js +4 -4
- package/function.cjs +1 -1
- package/function.js +6 -6
- package/index.cjs +1 -1
- package/index.d.ts +2 -0
- package/index.js +161 -153
- package/number.cjs +1 -1
- package/number.d.ts +5 -5
- package/number.js +1 -1
- package/package.json +8 -1
- package/timer.cjs +1 -1
- package/timer.d.ts +14 -0
- package/timer.js +47 -25
- package/union.cjs +1 -0
- package/union.d.ts +1 -0
- package/union.js +1 -0
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
|
+
[](https://www.npmjs.com/package/@tempots/std)
|
|
6
|
+
[](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
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @
|
|
9
|
-
*
|
|
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
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @
|
|
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
|
|
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[],
|
|
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
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
74
|
-
*
|
|
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
|
-
*
|
|
110
|
-
*
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
* @
|
|
116
|
-
*
|
|
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
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
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
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
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),
|
|
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
|
|
102
|
-
m.delete(
|
|
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
|
-
|
|
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,
|
|
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
|
|
2
|
-
let
|
|
3
|
-
return () => (
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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"),
|
|
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
|
|
2
|
-
import { AsyncResult as
|
|
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 {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
N as AsyncResult,
|
|
18
|
+
ve as EPSILON,
|
|
19
|
+
or as Result,
|
|
20
|
+
lr as Validation,
|
|
20
21
|
t as allElements,
|
|
21
|
-
|
|
22
|
+
Ee as angleDifference,
|
|
22
23
|
i as anyElement,
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
+
ae as compareBooleans,
|
|
62
|
+
dr as compareCaseInsensitive,
|
|
63
|
+
We as compareNumbers,
|
|
64
|
+
fr as compareStrings,
|
|
61
65
|
y as concatArrays,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
94
|
+
je as floorTo,
|
|
90
95
|
S as foldLeftArray,
|
|
91
|
-
|
|
92
|
-
|
|
96
|
+
x as forEachElement,
|
|
97
|
+
C as generateArray,
|
|
93
98
|
h as generateSequenceArray,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
Vr as jsQuote,
|
|
125
|
+
ce as looseEqual,
|
|
126
|
+
kr as lowerCaseFirst,
|
|
127
|
+
Kr as lpad,
|
|
122
128
|
O as mapArray,
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
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"),
|
|
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
|
-
* `
|
|
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
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
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
|
|
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tempots/std",
|
|
3
|
-
"version": "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
|
|
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
|
|
2
|
-
const t = setTimeout(
|
|
1
|
+
const T = (n, e) => {
|
|
2
|
+
const t = setTimeout(n, e);
|
|
3
3
|
return () => clearTimeout(t);
|
|
4
|
-
},
|
|
5
|
-
const t = setInterval(
|
|
4
|
+
}, I = (n, e) => {
|
|
5
|
+
const t = setInterval(n, e);
|
|
6
6
|
return () => clearInterval(t);
|
|
7
|
-
},
|
|
8
|
-
const { noTrailing:
|
|
9
|
-
let o, f = !1,
|
|
10
|
-
function
|
|
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
|
|
14
|
-
const { upcomingOnly:
|
|
15
|
-
|
|
13
|
+
function A(u) {
|
|
14
|
+
const { upcomingOnly: s = !1 } = u || {};
|
|
15
|
+
m(), f = !s;
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function d(...u) {
|
|
18
18
|
if (f) return;
|
|
19
|
-
const
|
|
20
|
-
function
|
|
21
|
-
|
|
19
|
+
const s = this, p = Date.now() - c;
|
|
20
|
+
function r() {
|
|
21
|
+
c = Date.now(), e.apply(s, u);
|
|
22
22
|
}
|
|
23
|
-
function
|
|
23
|
+
function v() {
|
|
24
24
|
o = void 0;
|
|
25
25
|
}
|
|
26
|
-
!
|
|
27
|
-
|
|
28
|
-
|
|
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
|
|
32
|
-
},
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
+
|