@oscarpalmer/atoms 0.184.2 → 0.185.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.
Files changed (88) hide show
  1. package/dist/array/index.d.mts +2 -2
  2. package/dist/array/index.mjs +2 -2
  3. package/dist/array/{position.d.mts → match.d.mts} +9 -6
  4. package/dist/array/{position.mjs → match.mjs} +16 -16
  5. package/dist/array/move.mjs +1 -1
  6. package/dist/array/sort.d.mts +9 -4
  7. package/dist/array/sort.mjs +1 -1
  8. package/dist/array/swap.mjs +1 -1
  9. package/dist/beacon.d.mts +12 -0
  10. package/dist/beacon.mjs +9 -0
  11. package/dist/color/instance.d.mts +8 -0
  12. package/dist/color/instance.mjs +3 -0
  13. package/dist/color/models.d.mts +30 -0
  14. package/dist/function/assert.d.mts +29 -8
  15. package/dist/function/assert.mjs +29 -8
  16. package/dist/function/memoize.d.mts +3 -0
  17. package/dist/function/memoize.mjs +3 -0
  18. package/dist/function/retry.d.mts +3 -0
  19. package/dist/function/retry.mjs +3 -0
  20. package/dist/function/work.mjs +1 -1
  21. package/dist/index.d.mts +271 -158
  22. package/dist/index.mjs +230 -163
  23. package/dist/internal/value/compare.d.mts +2 -1
  24. package/dist/internal/value/equal.d.mts +5 -0
  25. package/dist/internal/value/get.d.mts +2 -2
  26. package/dist/internal/value/has.d.mts +3 -3
  27. package/dist/internal/value/has.mjs +1 -1
  28. package/dist/internal/value/misc.d.mts +2 -2
  29. package/dist/internal/value/misc.mjs +10 -4
  30. package/dist/logger.d.mts +11 -0
  31. package/dist/logger.mjs +11 -0
  32. package/dist/promise/helpers.mjs +1 -1
  33. package/dist/promise/index.d.mts +0 -6
  34. package/dist/promise/models.d.mts +36 -0
  35. package/dist/promise/models.mjs +6 -0
  36. package/dist/queue.d.mts +13 -1
  37. package/dist/queue.mjs +9 -0
  38. package/dist/result/index.d.mts +0 -8
  39. package/dist/result/index.mjs +0 -8
  40. package/dist/result/match.d.mts +4 -4
  41. package/dist/result/work/flow.d.mts +12 -36
  42. package/dist/result/work/pipe.d.mts +11 -33
  43. package/dist/sized/set.d.mts +3 -2
  44. package/dist/sized/set.mjs +3 -2
  45. package/dist/value/handle.mjs +1 -1
  46. package/dist/value/shake.d.mts +3 -0
  47. package/dist/value/smush.d.mts +3 -0
  48. package/dist/value/transform.d.mts +9 -0
  49. package/dist/value/unsmush.d.mts +3 -0
  50. package/package.json +2 -2
  51. package/src/array/difference.ts +4 -0
  52. package/src/array/from.ts +4 -0
  53. package/src/array/index.ts +1 -1
  54. package/src/array/intersection.ts +4 -0
  55. package/src/array/{position.ts → match.ts} +28 -25
  56. package/src/array/move.ts +5 -1
  57. package/src/array/reverse.ts +4 -0
  58. package/src/array/select.ts +2 -0
  59. package/src/array/sort.ts +9 -4
  60. package/src/array/swap.ts +5 -1
  61. package/src/array/toggle.ts +4 -0
  62. package/src/array/union.ts +4 -0
  63. package/src/beacon.ts +12 -0
  64. package/src/color/index.ts +0 -3
  65. package/src/color/instance.ts +9 -1
  66. package/src/color/models.ts +30 -0
  67. package/src/function/assert.ts +66 -7
  68. package/src/function/memoize.ts +3 -0
  69. package/src/function/once.ts +5 -1
  70. package/src/function/retry.ts +3 -0
  71. package/src/internal/value/compare.ts +2 -1
  72. package/src/internal/value/equal.ts +5 -0
  73. package/src/internal/value/get.ts +2 -2
  74. package/src/internal/value/has.ts +6 -6
  75. package/src/internal/value/misc.ts +24 -13
  76. package/src/logger.ts +11 -0
  77. package/src/promise/index.ts +0 -6
  78. package/src/promise/models.ts +36 -0
  79. package/src/queue.ts +13 -1
  80. package/src/result/index.ts +0 -8
  81. package/src/result/match.ts +4 -4
  82. package/src/result/work/flow.ts +12 -36
  83. package/src/result/work/pipe.ts +11 -33
  84. package/src/sized/set.ts +4 -3
  85. package/src/value/shake.ts +3 -0
  86. package/src/value/smush.ts +3 -0
  87. package/src/value/transform.ts +9 -0
  88. package/src/value/unsmush.ts +3 -0
@@ -6,7 +6,7 @@ type WrapValue<Value> = Result<UnwrapValue<Value>>;
6
6
  /**
7
7
  * Attempt to pipe a value through a function
8
8
  *
9
- * Available as `attemptAsyncPipe` and `attempt.pipe.async`
9
+ * Available as `attemptAsyncPipe` and `attemptPipe.async`
10
10
  * @param initial Initial value
11
11
  * @returns Piped result
12
12
  */
@@ -14,7 +14,7 @@ declare function attemptAsyncPipe<Initial, Piped>(initial: GenericCallback | Ini
14
14
  /**
15
15
  * Attempt to pipe a value through a series of functions
16
16
  *
17
- * Available as `attemptAsyncPipe` and `attempt.pipe.async`
17
+ * Available as `attemptAsyncPipe` and `attemptPipe.async`
18
18
  * @param initial Initial value
19
19
  * @returns Piped result
20
20
  */
@@ -22,7 +22,7 @@ declare function attemptAsyncPipe<Initial, First, Second>(initial: GenericCallba
22
22
  /**
23
23
  * Attempt to pipe a value through a series of functions
24
24
  *
25
- * Available as `attemptAsyncPipe` and `attempt.pipe.async`
25
+ * Available as `attemptAsyncPipe` and `attemptPipe.async`
26
26
  * @param initial Initial value
27
27
  * @returns Piped result
28
28
  */
@@ -30,7 +30,7 @@ declare function attemptAsyncPipe<Initial, First, Second, Third>(initial: Generi
30
30
  /**
31
31
  * Attempt to pipe a value through a series of functions
32
32
  *
33
- * Available as `attemptAsyncPipe` and `attempt.pipe.async`
33
+ * Available as `attemptAsyncPipe` and `attemptPipe.async`
34
34
  * @param initial Initial value
35
35
  * @returns Piped result
36
36
  */
@@ -38,7 +38,7 @@ declare function attemptAsyncPipe<Initial, First, Second, Third, Fourth>(initial
38
38
  /**
39
39
  * Attempt to pipe a value through a series of functions
40
40
  *
41
- * Available as `attemptAsyncPipe` and `attempt.pipe.async`
41
+ * Available as `attemptAsyncPipe` and `attemptPipe.async`
42
42
  * @param initial Initial value
43
43
  * @returns Piped result
44
44
  */
@@ -46,7 +46,7 @@ declare function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth>(
46
46
  /**
47
47
  * Attempt to pipe a value through a series of functions
48
48
  *
49
- * Available as `attemptAsyncPipe` and `attempt.pipe.async`
49
+ * Available as `attemptAsyncPipe` and `attemptPipe.async`
50
50
  * @param initial Initial value
51
51
  * @returns Piped result
52
52
  */
@@ -54,7 +54,7 @@ declare function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth,
54
54
  /**
55
55
  * Attempt to pipe a value through a series of functions
56
56
  *
57
- * Available as `attemptAsyncPipe` and `attempt.pipe.async`
57
+ * Available as `attemptAsyncPipe` and `attemptPipe.async`
58
58
  * @param initial Initial value
59
59
  * @returns Piped result
60
60
  */
@@ -62,7 +62,7 @@ declare function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth,
62
62
  /**
63
63
  * Attempt to pipe a value through a series of functions
64
64
  *
65
- * Available as `attemptAsyncPipe` and `attempt.pipe.async`
65
+ * Available as `attemptAsyncPipe` and `attemptPipe.async`
66
66
  * @param initial Initial value
67
67
  * @returns Piped result
68
68
  */
@@ -70,7 +70,7 @@ declare function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth,
70
70
  /**
71
71
  * Attempt to pipe a value through a series of functions
72
72
  *
73
- * Available as `attemptAsyncPipe` and `attempt.pipe.async`
73
+ * Available as `attemptAsyncPipe` and `attemptPipe.async`
74
74
  * @param initial Initial value
75
75
  * @returns Piped result
76
76
  */
@@ -78,7 +78,7 @@ declare function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth,
78
78
  /**
79
79
  * Attempt to pipe a value through a series of functions
80
80
  *
81
- * Available as `attemptAsyncPipe` and `attempt.pipe.async`
81
+ * Available as `attemptAsyncPipe` and `attemptPipe.async`
82
82
  * @param initial Initial value
83
83
  * @returns Piped result
84
84
  */
@@ -86,95 +86,73 @@ declare function attemptAsyncPipe<Initial, First, Second, Third, Fourth, Fifth,
86
86
  /**
87
87
  * Attempt to pipe a result through a series of functions
88
88
  *
89
- * Available as `attemptAsyncPipe` and `attempt.pipe.async`
89
+ * Available as `attemptAsyncPipe` and `attemptPipe.async`
90
90
  * @param initial Initial result
91
91
  * @returns Piped result
92
92
  */
93
93
  declare function attemptAsyncPipe<Initial>(initial: GenericCallback | Initial | Promise<Initial> | Result<Initial>, first?: (value: UnwrapValue<Initial>) => unknown, ...seconds: Array<(value: unknown) => unknown>): Promise<WrapValue<Initial>>;
94
94
  /**
95
95
  * Attempt to pipe a value through a function
96
- *
97
- * Available as `attemptPipe` and `attempt.pipe`
98
96
  * @param initial Initial value
99
97
  * @returns Piped result
100
98
  */
101
99
  declare function attemptPipe<Initial, Pipe>(initial: GenericCallback | Initial | Result<Initial>, pipe: (value: UnwrapValue<Initial>) => Pipe): WrapValue<Pipe>;
102
100
  /**
103
101
  * Attempt to pipe a value through a series of functions
104
- *
105
- * Available as `attemptPipe` and `attempt.pipe`
106
102
  * @param initial Initial value
107
103
  * @returns Piped result
108
104
  */
109
105
  declare function attemptPipe<Initial, First, Second>(initial: GenericCallback | Initial | Result<Initial>, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second): WrapValue<Second>;
110
106
  /**
111
107
  * Attempt to pipe a value through a series of functions
112
- *
113
- * Available as `attemptPipe` and `attempt.pipe`
114
108
  * @param initial Initial value
115
109
  * @returns Piped result
116
110
  */
117
111
  declare function attemptPipe<Initial, First, Second, Third>(initial: GenericCallback | Initial | Result<Initial>, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third): WrapValue<Third>;
118
112
  /**
119
113
  * Attempt to pipe a value through a series of functions
120
- *
121
- * Available as `attemptPipe` and `attempt.pipe`
122
114
  * @param initial Initial value
123
115
  * @returns Piped result
124
116
  */
125
117
  declare function attemptPipe<Initial, First, Second, Third, Fourth>(initial: GenericCallback | Initial | Result<Initial>, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth): WrapValue<Fourth>;
126
118
  /**
127
119
  * Attempt to pipe a value through a series of functions
128
- *
129
- * Available as `attemptPipe` and `attempt.pipe`
130
120
  * @param initial Initial value
131
121
  * @returns Piped result
132
122
  */
133
123
  declare function attemptPipe<Initial, First, Second, Third, Fourth, Fifth>(initial: GenericCallback | Initial | Result<Initial>, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth): WrapValue<Fifth>;
134
124
  /**
135
125
  * Attempt to pipe a value through a series of functions
136
- *
137
- * Available as `attemptPipe` and `attempt.pipe`
138
126
  * @param initial Initial value
139
127
  * @returns Piped result
140
128
  */
141
129
  declare function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth>(initial: GenericCallback | Initial | Result<Initial>, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth): WrapValue<Sixth>;
142
130
  /**
143
131
  * Attempt to pipe a value through a series of functions
144
- *
145
- * Available as `attemptPipe` and `attempt.pipe`
146
132
  * @param initial Initial value
147
133
  * @returns Piped result
148
134
  */
149
135
  declare function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh>(initial: GenericCallback | Initial | Result<Initial>, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh): WrapValue<Seventh>;
150
136
  /**
151
137
  * Attempt to pipe a value through a series of functions
152
- *
153
- * Available as `attemptPipe` and `attempt.pipe`
154
138
  * @param initial Initial value
155
139
  * @returns Piped result
156
140
  */
157
141
  declare function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth>(initial: GenericCallback | Initial | Result<Initial>, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh, eighth: (value: UnwrapValue<Seventh>) => Eighth): WrapValue<Eighth>;
158
142
  /**
159
143
  * Attempt to pipe a value through a series of functions
160
- *
161
- * Available as `attemptPipe` and `attempt.pipe`
162
144
  * @param initial Initial value
163
145
  * @returns Piped result
164
146
  */
165
147
  declare function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth>(initial: GenericCallback | Initial | Result<Initial>, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh, eighth: (value: UnwrapValue<Seventh>) => Eighth, ninth: (value: UnwrapValue<Eighth>) => Ninth): WrapValue<Ninth>;
166
148
  /**
167
149
  * Attempt to pipe a value through a series of functions
168
- *
169
- * Available as `attemptPipe` and `attempt.pipe`
170
150
  * @param initial Initial value
171
151
  * @returns Piped result
172
152
  */
173
153
  declare function attemptPipe<Initial, First, Second, Third, Fourth, Fifth, Sixth, Seventh, Eighth, Ninth, Tenth>(initial: GenericCallback | Initial | Result<Initial>, first: (value: UnwrapValue<Initial>) => First, second: (value: UnwrapValue<First>) => Second, third: (value: UnwrapValue<Second>) => Third, fourth: (value: UnwrapValue<Third>) => Fourth, fifth: (value: UnwrapValue<Fourth>) => Fifth, sixth: (value: UnwrapValue<Fifth>) => Sixth, seventh: (value: UnwrapValue<Sixth>) => Seventh, eighth: (value: UnwrapValue<Seventh>) => Eighth, ninth: (value: UnwrapValue<Eighth>) => Ninth, tenth: (value: UnwrapValue<Ninth>) => Tenth): WrapValue<Tenth>;
174
154
  /**
175
155
  * Attempt to pipe a result through a series of functions
176
- *
177
- * Available as `attemptPipe` and `attempt.pipe`
178
156
  * @param initial Initial result
179
157
  * @returns Piped result
180
158
  */
@@ -1,7 +1,8 @@
1
1
  //#region src/sized/set.d.ts
2
2
  /**
3
- * - A Set with a maximum size
4
- * - Behavior is similar to a _LRU_-cache, where the oldest values are removed
3
+ * A Set with a maximum size
4
+ *
5
+ * Behavior is similar to a _LRU_-cache, where the oldest values are removed
5
6
  */
6
7
  declare class SizedSet<Value = unknown> extends Set<Value> {
7
8
  #private;
@@ -1,8 +1,9 @@
1
1
  import { getSizedMaximum } from "../internal/sized.mjs";
2
2
  //#region src/sized/set.ts
3
3
  /**
4
- * - A Set with a maximum size
5
- * - Behavior is similar to a _LRU_-cache, where the oldest values are removed
4
+ * A Set with a maximum size
5
+ *
6
+ * Behavior is similar to a _LRU_-cache, where the oldest values are removed
6
7
  */
7
8
  var SizedSet = class extends Set {
8
9
  /**
@@ -1,4 +1,4 @@
1
- import { getValue } from "../internal/value/get.mjs";
2
1
  import { hasValue } from "../internal/value/has.mjs";
2
+ import { getValue } from "../internal/value/get.mjs";
3
3
  import { setValue } from "../internal/value/set.mjs";
4
4
  export { getValue, hasValue, setValue };
@@ -1,6 +1,9 @@
1
1
  import { PlainObject } from "../models.mjs";
2
2
 
3
3
  //#region src/value/shake.d.ts
4
+ /**
5
+ * A shaken object, without any `undefined` values
6
+ */
4
7
  type Shaken<Value extends PlainObject> = { [Key in keyof Value]: Value[Key] extends undefined ? never : Value[Key] };
5
8
  /**
6
9
  * Shake an object, removing all keys with `undefined` values
@@ -1,6 +1,9 @@
1
1
  import { NestedKeys, NestedValue, PlainObject, Simplify, ToString } from "../models.mjs";
2
2
 
3
3
  //#region src/value/smush.d.ts
4
+ /**
5
+ * A smushed object, with all nested objects flattened into a single level, using dot notation keys
6
+ */
4
7
  type Smushed<Value extends PlainObject> = Simplify<{ [NestedKey in NestedKeys<Value>]: NestedValue<Value, ToString<NestedKey>> }>;
5
8
  /**
6
9
  * Smush an object into a flat object that uses dot notation keys
@@ -1,8 +1,17 @@
1
1
  import { PlainObject } from "../models.mjs";
2
2
 
3
3
  //#region src/value/transform.d.ts
4
+ /**
5
+ * A callback transform an object's properties
6
+ */
4
7
  type TransformCallback<Value extends PlainObject, Key extends keyof Value> = (key: Key, value: Value[Key]) => Value[Key];
8
+ /**
9
+ * A collection of keyed callbacks to transform an object's properties
10
+ */
5
11
  type TransformCallbacks<Value extends PlainObject> = Partial<{ [Key in keyof Value]: (value: Value[Key]) => Value[Key] }>;
12
+ /**
13
+ * A transformer function for an object, with predefined callbacks for transforming its properties
14
+ */
6
15
  type Transformer<Value extends PlainObject> = {
7
16
  (value: Value): Value;
8
17
  };
@@ -9,6 +9,9 @@ type KeysOfUnion<ObjectType> = keyof UnionToIntersection<ObjectType extends unkn
9
9
  * Thanks, type-fest!
10
10
  */
11
11
  type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
12
+ /**
13
+ * An unsmushed object, with all dot notation keys turned into nested keys
14
+ */
12
15
  type Unsmushed<Value extends PlainObject> = Simplify<Omit<{ [UnionKey in KeysOfUnion<Value>]: Value[UnionKey] }, `${string}.${string}`>>;
13
16
  /**
14
17
  * Unsmush a smushed object _(turning dot notation keys into nested keys)_
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oscarpalmer/atoms",
3
- "version": "0.184.2",
3
+ "version": "0.185.0",
4
4
  "description": "Atomic utilities for making your JavaScript better.",
5
5
  "keywords": [
6
6
  "helper",
@@ -253,7 +253,7 @@
253
253
  "watch": "npx vite build --watch"
254
254
  },
255
255
  "devDependencies": {
256
- "@oxlint/plugins": "^1.61",
256
+ "@oxlint/plugins": "^1.62",
257
257
  "@types/node": "^25.6",
258
258
  "@vitest/coverage-istanbul": "^4.1",
259
259
  "eslint": "^10.2",
@@ -1,6 +1,8 @@
1
1
  import {COMPARE_SETS_DIFFERENCE, compareSets} from '../internal/array/sets';
2
2
  import type {PlainObject} from '../models';
3
3
 
4
+ // #region Functions
5
+
4
6
  /**
5
7
  * Get the items from the first array that are not in the second array
6
8
  * @param first First array
@@ -38,3 +40,5 @@ export function difference<First, Second>(first: First[], second: Second[]): Fir
38
40
  export function difference(first: unknown[], second: unknown[], key?: unknown): unknown[] {
39
41
  return compareSets(COMPARE_SETS_DIFFERENCE, first, second, key);
40
42
  }
43
+
44
+ // #endregion
package/src/array/from.ts CHANGED
@@ -1,3 +1,5 @@
1
+ // #region Functions
2
+
1
3
  /**
2
4
  * Get an array with a specified length, filled with indices
3
5
  * @param length Length of the array
@@ -87,3 +89,5 @@ export function times(length: number, value?: unknown): unknown[] {
87
89
 
88
90
  return values;
89
91
  }
92
+
93
+ // #endregion
@@ -12,7 +12,7 @@ export * from './get';
12
12
  export * from './insert';
13
13
  export * from './intersection';
14
14
  export * from './partition';
15
- export * from './position';
15
+ export * from './match';
16
16
  export * from './push';
17
17
  export * from './reverse';
18
18
  export * from './select';
@@ -1,5 +1,7 @@
1
1
  import {COMPARE_SETS_INTERSECTION, compareSets} from '../internal/array/sets';
2
2
 
3
+ // #region Functions
4
+
3
5
  /**
4
6
  * Get the common values between two arrays
5
7
  * @param first First array
@@ -37,3 +39,5 @@ export function intersection<First, Second>(first: First[], second: Second[]): F
37
39
  export function intersection(first: unknown[], second: unknown[], key?: unknown): unknown[] {
38
40
  return compareSets(COMPARE_SETS_INTERSECTION, first, second, key);
39
41
  }
42
+
43
+ // #endregion
@@ -1,9 +1,12 @@
1
- // #region Types
2
-
3
1
  import {getArrayCallback} from '../internal/array/callbacks';
4
2
  import type {PlainObject} from '../models';
5
3
 
6
- export type ArrayPosition = 'end' | 'inside' | 'invalid' | 'outside' | 'same' | 'start';
4
+ // #region Types
5
+
6
+ /**
7
+ * Comparison of an array within another array
8
+ */
9
+ export type ArrayComparison = 'end' | 'inside' | 'invalid' | 'outside' | 'same' | 'start';
7
10
 
8
11
  // #endregion
9
12
 
@@ -54,11 +57,11 @@ export function endsWithArray(haystack: unknown[], needle: unknown[], key?: unkn
54
57
  * @param key Key to get an item's value for matching
55
58
  * @returns Position of the needle within the haystack
56
59
  */
57
- export function getArrayPosition<Item extends PlainObject>(
60
+ export function getArrayComparison<Item extends PlainObject>(
58
61
  haystack: Item[],
59
62
  needle: Item[],
60
63
  key: keyof Item,
61
- ): ArrayPosition;
64
+ ): ArrayComparison;
62
65
 
63
66
  /**
64
67
  * Get the position of an array within another array
@@ -67,11 +70,11 @@ export function getArrayPosition<Item extends PlainObject>(
67
70
  * @param callback Callback to get an item's value for matching
68
71
  * @returns Position of the needle within the haystack
69
72
  */
70
- export function getArrayPosition<Item>(
73
+ export function getArrayComparison<Item>(
71
74
  haystack: Item[],
72
75
  needle: Item[],
73
76
  callback: (item: Item, index: number, array: Item[]) => unknown,
74
- ): ArrayPosition;
77
+ ): ArrayComparison;
75
78
 
76
79
  /**
77
80
  * Get the position of an array within another array
@@ -79,29 +82,29 @@ export function getArrayPosition<Item>(
79
82
  * @param needle Needle array
80
83
  * @returns Position of the needle within the haystack
81
84
  */
82
- export function getArrayPosition<Item>(haystack: Item[], needle: Item[]): ArrayPosition;
85
+ export function getArrayComparison<Item>(haystack: Item[], needle: Item[]): ArrayComparison;
83
86
 
84
- export function getArrayPosition(
87
+ export function getArrayComparison(
85
88
  haystack: unknown[],
86
89
  needle: unknown[],
87
90
  key?: unknown,
88
- ): ArrayPosition {
91
+ ): ArrayComparison {
89
92
  return getPosition(haystack, needle, key)[1];
90
93
  }
91
94
 
92
- function getName(start: number, haystack: number, needle: number): ArrayPosition {
95
+ function getName(start: number, haystack: number, needle: number): ArrayComparison {
93
96
  if (start === 0) {
94
- return haystack === needle ? POSITION_SAME : POSITION_START;
97
+ return haystack === needle ? COMPARISON_SAME : COMPARISON_START;
95
98
  }
96
99
 
97
- return start + needle === haystack ? POSITION_END : POSITION_INSIDE;
100
+ return start + needle === haystack ? COMPARISON_END : COMPARISON_INSIDE;
98
101
  }
99
102
 
100
103
  function getPosition(
101
104
  haystack: unknown[],
102
105
  needle: unknown[],
103
106
  key?: unknown,
104
- ): readonly [number, ArrayPosition] {
107
+ ): readonly [number, ArrayComparison] {
105
108
  if (!Array.isArray(haystack) || !Array.isArray(needle)) {
106
109
  return invalid;
107
110
  }
@@ -278,26 +281,26 @@ export function startsWithArray(haystack: unknown[], needle: unknown[], key?: un
278
281
 
279
282
  // #region Variables
280
283
 
281
- const POSITION_END: ArrayPosition = 'end';
284
+ const COMPARISON_END: ArrayComparison = 'end';
282
285
 
283
- const POSITION_INSIDE: ArrayPosition = 'inside';
286
+ const COMPARISON_INSIDE: ArrayComparison = 'inside';
284
287
 
285
- const POSITION_INVALID: ArrayPosition = 'invalid';
288
+ const COMPARISON_INVALID: ArrayComparison = 'invalid';
286
289
 
287
- const POSITION_OUTSIDE: ArrayPosition = 'outside';
290
+ const COMPARISON_OUTSIDE: ArrayComparison = 'outside';
288
291
 
289
- const POSITION_SAME: ArrayPosition = 'same';
292
+ const COMPARISON_SAME: ArrayComparison = 'same';
290
293
 
291
- const POSITION_START: ArrayPosition = 'start';
294
+ const COMPARISON_START: ArrayComparison = 'start';
292
295
 
293
- const endings = new Set<ArrayPosition>([POSITION_END, POSITION_SAME]);
296
+ const endings = new Set<ArrayComparison>([COMPARISON_END, COMPARISON_SAME]);
294
297
 
295
- const invalid = [-1, POSITION_INVALID] as const;
298
+ const invalid = [-1, COMPARISON_INVALID] as const;
296
299
 
297
- const outside = [-1, POSITION_OUTSIDE] as const;
300
+ const outside = [-1, COMPARISON_OUTSIDE] as const;
298
301
 
299
- const outsides = new Set<ArrayPosition>([POSITION_INVALID, POSITION_OUTSIDE]);
302
+ const outsides = new Set<ArrayComparison>([COMPARISON_INVALID, COMPARISON_OUTSIDE]);
300
303
 
301
- const starts = new Set<ArrayPosition>([POSITION_START, POSITION_SAME]);
304
+ const starts = new Set<ArrayComparison>([COMPARISON_START, COMPARISON_SAME]);
302
305
 
303
306
  // #endregion
package/src/array/move.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import {arraysOverlap} from '../internal/array/overlap';
2
2
  import type {PlainObject} from '../models';
3
- import {indexOfArray} from './position';
3
+ import {indexOfArray} from './match';
4
+
5
+ // #region Functions
4
6
 
5
7
  /**
6
8
  * Move an item _(or array of items)_ to the position of another item _(or array of items)_ within an array
@@ -239,3 +241,5 @@ export function moveToIndex(
239
241
 
240
242
  return array;
241
243
  }
244
+
245
+ // #endregion
@@ -1,3 +1,5 @@
1
+ // #region Functions
2
+
1
3
  /**
2
4
  * Reverse the order of items in an array
3
5
  * @param array Array to reverse
@@ -26,3 +28,5 @@ export function reverse<Item>(array: Item[]): Item[] {
26
28
 
27
29
  return array;
28
30
  }
31
+
32
+ // #endregion Functions
@@ -1,6 +1,8 @@
1
1
  import {FIND_VALUES_ALL, findValues} from '../internal/array/find';
2
2
  import type {PlainObject} from '../models';
3
3
 
4
+ // #region Functions
5
+
4
6
  /**
5
7
  * Get a filtered and mapped array of items
6
8
  * @param array Array to search in
package/src/array/sort.ts CHANGED
@@ -104,6 +104,11 @@ type InternalSorterCompare = {
104
104
  */
105
105
  export type SortDirection = 'ascending' | 'descending';
106
106
 
107
+ /**
108
+ * Sorter for an array with predefined sorters
109
+ *
110
+ * Can be used to sort an array, get the predicted index for an item, and check if an array is sorted
111
+ */
107
112
  export type Sorter<Item> = {
108
113
  /**
109
114
  * Sort an array of items
@@ -245,7 +250,7 @@ function getObjectSorter(obj: PlainObject, modifier: number): InternalSorter | u
245
250
  *
246
251
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
247
252
  *
248
- * Available as `getSortedIndex` and `sort.index`
253
+ * Available as `getSortedIndex` and `sort.getIndex`
249
254
  * @param array Array to get the index from
250
255
  * @param item Item to get the index for
251
256
  * @param sorters Sorters to use to determine sorting
@@ -264,7 +269,7 @@ export function getSortedIndex<Item>(
264
269
  *
265
270
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
266
271
  *
267
- * Available as `getSortedIndex` and `sort.index`
272
+ * Available as `getSortedIndex` and `sort.getIndex`
268
273
  * @param array Array to get the index from
269
274
  * @param item Item to get the index for
270
275
  * @param sorter Sorter to use to determine sorting
@@ -283,7 +288,7 @@ export function getSortedIndex<Item>(
283
288
  *
284
289
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
285
290
  *
286
- * Available as `getSortedIndex` and `sort.index`
291
+ * Available as `getSortedIndex` and `sort.getIndex`
287
292
  * @param array Array to get the index from
288
293
  * @param item Item to get the index for
289
294
  * @param descending Sorted in descending order? _(defaults to `false`)_
@@ -552,7 +557,7 @@ function sortArray(array: unknown[], sorters: InternalSorter[]): unknown[] {
552
557
  : array;
553
558
  }
554
559
 
555
- sort.index = getSortedIndex;
560
+ sort.getIndex = getSortedIndex;
556
561
  sort.initialize = initializeSorter;
557
562
  sort.is = isSorted;
558
563
 
package/src/array/swap.ts CHANGED
@@ -2,7 +2,9 @@ import {getArrayCallback} from '../internal/array/callbacks';
2
2
  import {indexOf} from '../internal/array/index-of';
3
3
  import {arraysOverlap} from '../internal/array/overlap';
4
4
  import type {PlainObject} from '../models';
5
- import {indexOfArray} from './position';
5
+ import {indexOfArray} from './match';
6
+
7
+ // #region Functions
6
8
 
7
9
  /**
8
10
  * Swap two smaller arrays within a larger array
@@ -211,3 +213,5 @@ function swapValues(array: unknown[], from: unknown, to: unknown, key?: unknown)
211
213
 
212
214
  return swapIndices(array, first, second);
213
215
  }
216
+
217
+ // #endregion
@@ -1,6 +1,8 @@
1
1
  import {updateInArray} from '../internal/array/update';
2
2
  import type {PlainObject} from '../models';
3
3
 
4
+ // #region Functions
5
+
4
6
  /**
5
7
  * Toggle an item in an array: if the item exists, it will be removed; if it doesn't, it will be added
6
8
  * @param destination Array to toggle within
@@ -38,3 +40,5 @@ export function toggle<Item>(destination: Item[], toggled: Item[]): Item[];
38
40
  export function toggle(array: unknown[], values: unknown[], key?: unknown): unknown[] {
39
41
  return updateInArray(array, values, key, false);
40
42
  }
43
+
44
+ // #endregion
@@ -1,5 +1,7 @@
1
1
  import {COMPARE_SETS_UNION, compareSets} from '../internal/array/sets';
2
2
 
3
+ // #region Functions
4
+
3
5
  /**
4
6
  * Get the combined, unique values from two arrays
5
7
  * @param first First array
@@ -37,3 +39,5 @@ export function union<First, Second>(first: First[], second: Second[]): (First |
37
39
  export function union(first: unknown[], second: unknown[], key?: unknown): unknown[] {
38
40
  return compareSets(COMPARE_SETS_UNION, first, second, key);
39
41
  }
42
+
43
+ // #endregion
package/src/beacon.ts CHANGED
@@ -4,6 +4,9 @@ import type {PlainObject} from './models';
4
4
 
5
5
  // #region Types
6
6
 
7
+ /**
8
+ * A beacon is a lighthouse, holding an observable value that can be subscribed to and emitted from
9
+ */
7
10
  class Beacon<Value> {
8
11
  readonly #options: Options;
9
12
  readonly #state: BeaconState<Value>;
@@ -122,6 +125,9 @@ type BeaconState<Value> = {
122
125
  value: Value;
123
126
  };
124
127
 
128
+ /**
129
+ * An observable holds a value and allows observers to subscribe to changes in that value
130
+ */
125
131
  class Observable<Value> {
126
132
  readonly #state: ObservableState<Value>;
127
133
 
@@ -186,6 +192,9 @@ type ObservableState<Value> = {
186
192
  observers: Map<Subscription<Value>, Observer<Value>>;
187
193
  };
188
194
 
195
+ /**
196
+ * An observer receives notifications from an observable
197
+ */
189
198
  type Observer<Value> = {
190
199
  /**
191
200
  * Callback for when the observable is completed
@@ -203,6 +212,9 @@ type Observer<Value> = {
203
212
 
204
213
  type Options = Required<BeaconOptions<unknown>>;
205
214
 
215
+ /**
216
+ * A subscription represents an active subscription to an observable, holding its state and allowing it to be destroyed or unsubscribed from
217
+ */
206
218
  class Subscription<Value> {
207
219
  readonly #state: SubscriptionState<Value>;
208
220
 
@@ -39,11 +39,8 @@ export {
39
39
  } from './misc/is';
40
40
 
41
41
  export {getNormalizedHex, hexToHsl, hexToHsla, hexToRgb, hexToRgba} from './space/hex';
42
-
43
42
  export {hslToHex, hslToRgb, hslToRgba} from './space/hsl';
44
-
45
43
  export {rgbToHex, rgbToHsl, rgbToHsla} from './space/rgb';
46
-
47
44
  export type {Color, HSLAColor, HSLColor, RGBAColor, RGBColor};
48
45
 
49
46
  // #endregion