@oscarpalmer/atoms 0.193.0 → 0.193.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/package.json +3 -4
  2. package/src/array/difference.ts +0 -73
  3. package/src/array/exists.ts +0 -93
  4. package/src/array/filter.ts +0 -182
  5. package/src/array/find.ts +0 -183
  6. package/src/array/first.ts +0 -196
  7. package/src/array/flatten.ts +0 -20
  8. package/src/array/from.ts +0 -129
  9. package/src/array/get.ts +0 -131
  10. package/src/array/group-by.ts +0 -369
  11. package/src/array/index.ts +0 -26
  12. package/src/array/insert.ts +0 -52
  13. package/src/array/intersection.ts +0 -72
  14. package/src/array/last.ts +0 -194
  15. package/src/array/match.ts +0 -436
  16. package/src/array/move.ts +0 -315
  17. package/src/array/partition.ts +0 -91
  18. package/src/array/push.ts +0 -23
  19. package/src/array/reverse.ts +0 -33
  20. package/src/array/select.ts +0 -260
  21. package/src/array/single.ts +0 -93
  22. package/src/array/slice.ts +0 -335
  23. package/src/array/sort.ts +0 -607
  24. package/src/array/splice.ts +0 -106
  25. package/src/array/swap.ts +0 -322
  26. package/src/array/to-map.ts +0 -371
  27. package/src/array/to-record.ts +0 -351
  28. package/src/array/to-set.ts +0 -80
  29. package/src/array/toggle.ts +0 -79
  30. package/src/array/union.ts +0 -72
  31. package/src/array/unique.ts +0 -67
  32. package/src/array/update.ts +0 -75
  33. package/src/beacon.ts +0 -378
  34. package/src/color/constants.ts +0 -137
  35. package/src/color/index.ts +0 -83
  36. package/src/color/instance.ts +0 -162
  37. package/src/color/misc/alpha.ts +0 -56
  38. package/src/color/misc/format.ts +0 -29
  39. package/src/color/misc/get.ts +0 -210
  40. package/src/color/misc/is.ts +0 -221
  41. package/src/color/misc/state.ts +0 -243
  42. package/src/color/models.ts +0 -389
  43. package/src/color/space/hex.ts +0 -184
  44. package/src/color/space/hsl.ts +0 -174
  45. package/src/color/space/hwb.ts +0 -153
  46. package/src/color/space/rgb.ts +0 -240
  47. package/src/function/assert.ts +0 -174
  48. package/src/function/index.ts +0 -2
  49. package/src/function/limit.ts +0 -83
  50. package/src/function/memoize.ts +0 -202
  51. package/src/function/once.ts +0 -200
  52. package/src/function/retry.ts +0 -175
  53. package/src/function/work.ts +0 -1007
  54. package/src/herald.ts +0 -216
  55. package/src/index.ts +0 -68
  56. package/src/internal/array/callbacks.ts +0 -46
  57. package/src/internal/array/chunk.ts +0 -51
  58. package/src/internal/array/compact.ts +0 -56
  59. package/src/internal/array/find.ts +0 -200
  60. package/src/internal/array/group.ts +0 -42
  61. package/src/internal/array/index-of.ts +0 -182
  62. package/src/internal/array/insert.ts +0 -80
  63. package/src/internal/array/overlap.ts +0 -35
  64. package/src/internal/array/sets.ts +0 -74
  65. package/src/internal/array/shuffle.ts +0 -33
  66. package/src/internal/array/update.ts +0 -52
  67. package/src/internal/function/misc.ts +0 -8
  68. package/src/internal/function/timer.ts +0 -168
  69. package/src/internal/is.ts +0 -244
  70. package/src/internal/math/aggregate.ts +0 -164
  71. package/src/internal/math/misc.ts +0 -28
  72. package/src/internal/number.ts +0 -129
  73. package/src/internal/random.ts +0 -49
  74. package/src/internal/result.ts +0 -92
  75. package/src/internal/sized.ts +0 -25
  76. package/src/internal/string.ts +0 -128
  77. package/src/internal/subscription.ts +0 -264
  78. package/src/internal/value/compare.ts +0 -170
  79. package/src/internal/value/equal.ts +0 -465
  80. package/src/internal/value/get.ts +0 -57
  81. package/src/internal/value/handlers.ts +0 -95
  82. package/src/internal/value/has.ts +0 -118
  83. package/src/internal/value/misc.ts +0 -125
  84. package/src/internal/value/partial.ts +0 -46
  85. package/src/internal/value/set.ts +0 -132
  86. package/src/is.ts +0 -182
  87. package/src/logger.ts +0 -230
  88. package/src/math.ts +0 -281
  89. package/src/models.ts +0 -286
  90. package/src/number.ts +0 -1
  91. package/src/promise/delay.ts +0 -62
  92. package/src/promise/helpers.ts +0 -96
  93. package/src/promise/index.ts +0 -300
  94. package/src/promise/misc.ts +0 -96
  95. package/src/promise/models.ts +0 -195
  96. package/src/promise/timed.ts +0 -91
  97. package/src/query.ts +0 -147
  98. package/src/queue.ts +0 -814
  99. package/src/random.ts +0 -125
  100. package/src/result/index.ts +0 -105
  101. package/src/result/match.ts +0 -124
  102. package/src/result/misc.ts +0 -129
  103. package/src/result/models.ts +0 -83
  104. package/src/result/work/flow.ts +0 -488
  105. package/src/result/work/pipe.ts +0 -496
  106. package/src/sized/map.ts +0 -110
  107. package/src/sized/set.ts +0 -107
  108. package/src/string/case.ts +0 -236
  109. package/src/string/fuzzy.ts +0 -444
  110. package/src/string/index.ts +0 -199
  111. package/src/string/match.ts +0 -80
  112. package/src/string/normalize.ts +0 -205
  113. package/src/string/template.ts +0 -161
  114. package/src/value/clone.ts +0 -319
  115. package/src/value/collection.ts +0 -63
  116. package/src/value/diff.ts +0 -232
  117. package/src/value/freeze.ts +0 -322
  118. package/src/value/handle.ts +0 -3
  119. package/src/value/index.ts +0 -5
  120. package/src/value/merge.ts +0 -278
  121. package/src/value/omit.ts +0 -20
  122. package/src/value/pick.ts +0 -20
  123. package/src/value/shake.ts +0 -45
  124. package/src/value/smush.ts +0 -89
  125. package/src/value/transform.ts +0 -153
  126. package/src/value/unsmush.ts +0 -84
package/src/models.ts DELETED
@@ -1,286 +0,0 @@
1
- // #region Types
2
-
3
- /**
4
- * A generic array or object
5
- */
6
- export type ArrayOrPlainObject = unknown[] | Record<PropertyKey, unknown>;
7
-
8
- /**
9
- * An asynchronous callback that can be canceled
10
- */
11
- export type AsyncCancelableCallback<Callback extends GenericAsyncCallback | GenericCallback> =
12
- (ReturnType<Callback> extends Promise<any>
13
- ? (...args: Parameters<Callback>) => Promise<Awaited<ReturnType<Callback>>>
14
- : (...args: Parameters<Callback>) => Promise<ReturnType<Callback>>) & {
15
- /**
16
- * Cancel the callback
17
- */
18
- cancel: () => void;
19
- };
20
-
21
- /**
22
- * For matching any `void`, `Date`, primitive, or `RegExp` values
23
- *
24
- * _(Thanks, type-fest!)_
25
- */
26
- export type BuiltIns = void | Date | Primitive | RegExp;
27
-
28
- /**
29
- * A synchronous callback that can be canceled
30
- */
31
- export type CancelableCallback<Callback extends GenericCallback> = Callback & {
32
- /**
33
- * Cancel the callback
34
- */
35
- cancel: () => void;
36
- };
37
-
38
- /**
39
- * A generic class constructor
40
- */
41
- export type Constructor<Instance = unknown> = new (...args: any[]) => Instance;
42
-
43
- /**
44
- * Position of an event
45
- */
46
- export type EventPosition = {
47
- x: number;
48
- y: number;
49
- };
50
-
51
- /**
52
- * A generic async callback function
53
- */
54
- export type GenericAsyncCallback = (...args: any[]) => Promise<any>;
55
-
56
- /**
57
- * A generic callback function
58
- */
59
- export type GenericCallback = (...args: any[]) => any;
60
-
61
- /**
62
- * A generic key type
63
- */
64
- export type Key = number | string;
65
-
66
- export type KeyedValue<Item, ItemKey extends keyof Item> = Item[ItemKey] extends PropertyKey
67
- ? Item[ItemKey]
68
- : never;
69
-
70
- /**
71
- * A nested array
72
- */
73
- export type NestedArray<Value> =
74
- Value extends Array<infer NestedValue> ? NestedArray<NestedValue> : Value;
75
-
76
- /**
77
- * All nested keys of an object as dot notation strings _(up to 5 levels deep)_
78
- */
79
- export type NestedKeys<Value extends PlainObject> = _NestedKeys<Value>;
80
-
81
- type _NestedKeys<Value, Depth extends number = 5> = Depth extends 0
82
- ? never
83
- : Value extends readonly any[]
84
- ? Value extends readonly [any, ...any]
85
- ? // Tuple: extract actual indices
86
- {
87
- [ItemKey in keyof Value]-?: ItemKey extends `${number}`
88
- ? NonNullable<Value[ItemKey]> extends readonly any[] | PlainObject
89
- ?
90
- | `${ItemKey}`
91
- | `${ItemKey}.${_NestedKeys<NonNullable<Value[ItemKey]>, SubtractDepth<Depth>>}`
92
- : `${ItemKey}`
93
- : never;
94
- }[number]
95
- : // Array: use no indices
96
- never
97
- : Value extends PlainObject
98
- ? {
99
- [ItemKey in keyof Value]-?: ItemKey extends number | string
100
- ? NonNullable<Value[ItemKey]> extends readonly any[] | PlainObject
101
- ?
102
- | `${ItemKey}`
103
- | `${ItemKey}.${_NestedKeys<NonNullable<Value[ItemKey]>, SubtractDepth<Depth>>}`
104
- : `${ItemKey}`
105
- : never;
106
- }[keyof Value]
107
- : never;
108
-
109
- /**
110
- * An extended version of `Partial` that allows for nested properties to be optional
111
- */
112
- export type NestedPartial<Value> = {
113
- [ItemKey in keyof Value]?: Value[ItemKey] extends object
114
- ? NestedPartial<Value[ItemKey]>
115
- : Value[ItemKey];
116
- };
117
-
118
- /**
119
- * The value for a nested key of an object
120
- */
121
- export type NestedValue<Value extends PlainObject, Path extends string> = _NestedValue<Value, Path>;
122
-
123
- type _NestedValue<Value, Path extends string> = Path extends `${infer ItemKey}.${infer Rest}`
124
- ? ItemKey extends keyof Value
125
- ? undefined extends Value[ItemKey]
126
- ? _NestedValue<Exclude<Value[ItemKey], undefined>, Rest> | undefined
127
- : _NestedValue<Value[ItemKey], Rest>
128
- : ItemKey extends `${number}`
129
- ? Value extends readonly any[]
130
- ? _NestedValue<Value[number], Rest>
131
- : never
132
- : never
133
- : Path extends `${number}`
134
- ? Value extends readonly any[]
135
- ? Value[number]
136
- : never
137
- : Path extends keyof Value
138
- ? Value[Path]
139
- : never;
140
-
141
- /**
142
- * The nested _(keyed)_ values of an object _(up to 5 levels deep)_
143
- */
144
- export type NestedValues<Value extends PlainObject> = {
145
- [Path in NestedKeys<Value>]: NestedValue<Value, Path>;
146
- };
147
-
148
- /**
149
- * The numerical keys of an object
150
- */
151
- export type NumericalKeys<Value> = {
152
- [ItemKey in keyof Value]: ItemKey extends number
153
- ? ItemKey
154
- : ItemKey extends `${number}`
155
- ? ItemKey
156
- : never;
157
- }[keyof Value];
158
-
159
- /**
160
- * The numerical values of an object
161
- */
162
- export type NumericalValues<Item extends PlainObject> = {
163
- [ItemKey in keyof Item as Item[ItemKey] extends number ? ItemKey : never]: Item[ItemKey];
164
- };
165
-
166
- /**
167
- * An asynchronous function that can only be called once, returning the same value on subsequent calls
168
- */
169
- export type OnceAsyncCallback<Callback extends GenericAsyncCallback> = {
170
- /**
171
- * Did the callback's promise reject?
172
- */
173
- readonly error: boolean;
174
- /**
175
- * Has the callback finished?
176
- */
177
- readonly finished: boolean;
178
- } & Callback &
179
- OnceCallbackProperties;
180
-
181
- /**
182
- * A callback function that can only be called once, returning the same value on subsequent calls
183
- */
184
- export type OnceCallback<Callback extends GenericCallback> = Callback & OnceCallbackProperties;
185
-
186
- type OnceCallbackProperties = {
187
- /**
188
- * Has the callback been called?
189
- */
190
- readonly called: boolean;
191
- /**
192
- * Has the callback's value been cleared?
193
- */
194
- readonly cleared: boolean;
195
- /**
196
- * Clear the callback's cached value
197
- */
198
- clear: () => void;
199
- };
200
-
201
- /**
202
- * A generic object
203
- */
204
- export type PlainObject = Record<PropertyKey, unknown>;
205
-
206
- /**
207
- * A primitive value
208
- *
209
- * _(Thanks, type-fest!)_
210
- */
211
- export type Primitive = null | undefined | string | number | boolean | symbol | bigint;
212
-
213
- /**
214
- * Set required keys for a type
215
- */
216
- export type RequiredKeys<Model extends object, Keys extends keyof Model> = Required<
217
- Pick<Model, Keys>
218
- > &
219
- Omit<Model, Keys>;
220
-
221
- /**
222
- * Flattens the type to improve type hints in IDEs
223
- *
224
- * _(Thanks, type-fest!)_
225
- */
226
- export type Simplify<Value> = {[ValueKey in keyof Value]: Value[ValueKey]} & {};
227
-
228
- type SubtractDepth<Value extends number> = Value extends 5
229
- ? 4
230
- : Value extends 4
231
- ? 3
232
- : Value extends 3
233
- ? 2
234
- : Value extends 2
235
- ? 1
236
- : Value extends 1
237
- ? 0
238
- : never;
239
-
240
- /**
241
- * Get the value's type as a string
242
- *
243
- * _(Thanks, type-fest!)_
244
- */
245
- export type ToString<Value> = Value extends string | number ? `${Value}` : never;
246
-
247
- /**
248
- * A union type of all typed arrays
249
- */
250
- export type TypedArray =
251
- | Int8Array
252
- | Uint8Array
253
- | Uint8ClampedArray
254
- | Int16Array
255
- | Uint16Array
256
- | Int32Array
257
- | Uint32Array
258
- | Float32Array
259
- | Float64Array
260
- | BigInt64Array
261
- | BigUint64Array;
262
-
263
- /**
264
- * Converts a union type to an intersection type
265
- *
266
- * @example
267
- * ```typescript
268
- * type A = {a: string};
269
- * type B = {b: number};
270
- * type C = UnionToIntersection<A | B>; // => {a: string} & {b: number}
271
- * ```
272
- *
273
- * Thanks, type-fest!
274
- */
275
- export type UnionToIntersection<Union> = (
276
- Union extends unknown ? (distributedUnion: Union) => void : never
277
- ) extends (mergedIntersection: infer Intersection) => void
278
- ? Intersection & Union
279
- : never;
280
-
281
- /**
282
- * A function that unsubscribes from a subscription
283
- */
284
- export type Unsubscriber = () => void;
285
-
286
- // #endregion
package/src/number.ts DELETED
@@ -1 +0,0 @@
1
- export {between, clamp, getNumber} from './internal/number';
@@ -1,62 +0,0 @@
1
- import {getTimer, TIMER_WAIT} from '../internal/function/timer';
2
- import {getPromiseOptions} from './helpers';
3
- import {settlePromise} from './misc';
4
- import {PROMISE_ABORT_OPTIONS, PROMISE_ABORT_EVENT, type PromiseOptions} from './models';
5
-
6
- // #region Functions
7
-
8
- /**
9
- * Create a delayed promise that resolves after a certain amount of time, or rejects if aborted
10
- *
11
- * @param options Options for the delay
12
- * @returns Delayed promise
13
- */
14
- export function delay(options?: PromiseOptions): Promise<void>;
15
-
16
- /**
17
- * Create a delayed promise that resolves after a certain amount of time
18
- *
19
- * @param time How long to wait for _(in milliseconds; defaults to `0`)_
20
- * @returns Delayed promise
21
- */
22
- export function delay(time?: number): Promise<void>;
23
-
24
- export function delay(options?: unknown): Promise<void> {
25
- const {signal, time} = getPromiseOptions(options);
26
-
27
- if (signal?.aborted ?? false) {
28
- return Promise.reject(signal!.reason);
29
- }
30
-
31
- function abort(): void {
32
- timer.cancel();
33
-
34
- rejector(signal!.reason);
35
- }
36
-
37
- const timer = getTimer(
38
- TIMER_WAIT,
39
- () => {
40
- settlePromise(abort, resolver, undefined, signal);
41
- },
42
- time,
43
- );
44
-
45
- signal?.addEventListener(PROMISE_ABORT_EVENT, abort, PROMISE_ABORT_OPTIONS);
46
-
47
- let rejector: (reason: unknown) => void;
48
- let resolver: () => void;
49
-
50
- return new Promise((resolve, reject) => {
51
- rejector = reject;
52
- resolver = resolve;
53
-
54
- if (time === 0) {
55
- settlePromise(abort, resolve, undefined, signal);
56
- } else {
57
- timer();
58
- }
59
- });
60
- }
61
-
62
- // #endregion
@@ -1,96 +0,0 @@
1
- import {getNumberOrDefault} from '../internal/number';
2
- import type {RequiredKeys} from '../models';
3
- import {error, ok} from '../result/misc';
4
- import type {Result} from '../result/models';
5
- import {
6
- PROMISE_STRATEGY_ALL,
7
- PROMISE_STRATEGY_DEFAULT,
8
- PROMISE_TYPE_FULFILLED,
9
- PROMISE_TYPE_REJECTED,
10
- type FulfilledPromise,
11
- type PromiseOptions,
12
- type PromisesOptions,
13
- type PromiseStrategy,
14
- type PromisesValue,
15
- type RejectedPromise,
16
- } from './models';
17
-
18
- // #region Functions
19
-
20
- export function getPromiseOptions(input: unknown): RequiredKeys<PromiseOptions, 'time'> {
21
- if (typeof input === 'number') {
22
- return {
23
- time: getNumberOrDefault(input, 0),
24
- };
25
- }
26
-
27
- if (input instanceof AbortSignal) {
28
- return {signal: input, time: 0};
29
- }
30
-
31
- const options = typeof input === 'object' && input !== null ? (input as PromiseOptions) : {};
32
-
33
- return {
34
- signal: options.signal instanceof AbortSignal ? options.signal : undefined,
35
- time: getNumberOrDefault(options.time, 0),
36
- };
37
- }
38
-
39
- export function getPromisesOptions(input: unknown): RequiredKeys<PromisesOptions, 'strategy'> {
40
- if (typeof input === 'string') {
41
- return {
42
- strategy: getStrategyOrDefault(input),
43
- };
44
- }
45
-
46
- if (input instanceof AbortSignal) {
47
- return {signal: input, strategy: PROMISE_STRATEGY_DEFAULT};
48
- }
49
-
50
- const options = typeof input === 'object' && input !== null ? (input as PromisesOptions) : {};
51
-
52
- return {
53
- signal: options.signal instanceof AbortSignal ? options.signal : undefined,
54
- strategy: getStrategyOrDefault(options.strategy),
55
- };
56
- }
57
-
58
- export function getResultsFromPromises<Value>(promised: PromisesValue<Value>[]): Result<Value>[] {
59
- return promised.map(result =>
60
- isFulfilled(result) ? ok(result.value) : error(result.reason),
61
- ) as Result<Value>[];
62
- }
63
-
64
- export function getStrategyOrDefault(value: unknown): PromiseStrategy {
65
- return PROMISE_STRATEGY_ALL.has(value as PromiseStrategy)
66
- ? (value as PromiseStrategy)
67
- : PROMISE_STRATEGY_DEFAULT;
68
- }
69
-
70
- /**
71
- * Is the value a fulfilled _Promise_ result?
72
- *
73
- * @param value Value to check
74
- * @returns `true` if the value is a fulfilled _Promise_ result, otherwise `false`
75
- */
76
- export function isFulfilled<Value>(value: unknown): value is FulfilledPromise<Value> {
77
- return isType(value, PROMISE_TYPE_FULFILLED);
78
- }
79
-
80
- /**
81
- * Is the value a rejected _Promise_ result?
82
- *
83
- * @param value Value to check
84
- * @returns `true` if the value is a rejected _Promise_ result, otherwise `false`
85
- */
86
- export function isRejected(value: unknown): value is RejectedPromise {
87
- return isType(value, PROMISE_TYPE_REJECTED);
88
- }
89
-
90
- function isType(value: unknown, type: string): boolean {
91
- return (
92
- typeof value === 'object' && value !== null && (value as PromisesValue<unknown>).status === type
93
- );
94
- }
95
-
96
- // #endregion