@oscarpalmer/atoms 0.201.0 → 0.203.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 (156) hide show
  1. package/dist/array/difference.d.mts +4 -5
  2. package/dist/array/exists.d.mts +5 -6
  3. package/dist/array/filter.d.mts +10 -11
  4. package/dist/array/find.d.mts +10 -11
  5. package/dist/array/first.d.mts +10 -11
  6. package/dist/array/flatten.d.mts +2 -3
  7. package/dist/array/from.d.mts +7 -8
  8. package/dist/array/group-by.d.mts +16 -185
  9. package/dist/array/insert.d.mts +3 -4
  10. package/dist/array/intersection.d.mts +4 -5
  11. package/dist/array/last.d.mts +10 -11
  12. package/dist/array/move.d.mts +9 -10
  13. package/dist/array/partition.d.mts +5 -6
  14. package/dist/array/push.d.mts +2 -3
  15. package/dist/array/reverse.d.mts +2 -3
  16. package/dist/array/select.d.mts +11 -12
  17. package/dist/array/single.d.mts +4 -5
  18. package/dist/array/slice.d.mts +12 -13
  19. package/dist/array/sort.d.mts +31 -32
  20. package/dist/array/sort.mjs +41 -33
  21. package/dist/array/splice.d.mts +5 -6
  22. package/dist/array/swap.d.mts +8 -9
  23. package/dist/array/to-map.d.mts +18 -175
  24. package/dist/array/to-record.d.mts +18 -175
  25. package/dist/array/to-set.d.mts +4 -5
  26. package/dist/array/toggle.d.mts +4 -5
  27. package/dist/array/union.d.mts +4 -5
  28. package/dist/array/unique.d.mts +4 -5
  29. package/dist/array/update.d.mts +4 -5
  30. package/dist/beacon.d.mts +8 -9
  31. package/dist/beacon.mjs +90 -65
  32. package/dist/color/constants.d.mts +14 -13
  33. package/dist/color/constants.mjs +9 -2
  34. package/dist/color/index.d.mts +2 -2
  35. package/dist/color/instance.d.mts +3 -3
  36. package/dist/color/instance.mjs +125 -61
  37. package/dist/color/misc/alpha.d.mts +4 -5
  38. package/dist/color/misc/format.d.mts +6 -7
  39. package/dist/color/misc/format.mjs +15 -12
  40. package/dist/color/misc/get.d.mts +14 -15
  41. package/dist/color/misc/is.d.mts +16 -17
  42. package/dist/color/misc/is.mjs +3 -4
  43. package/dist/color/misc/state.d.mts +8 -10
  44. package/dist/color/misc/state.mjs +22 -20
  45. package/dist/color/models.d.mts +25 -19
  46. package/dist/color/space/hex.d.mts +9 -10
  47. package/dist/color/space/hsl.d.mts +8 -9
  48. package/dist/color/space/hwb.d.mts +9 -10
  49. package/dist/color/space/rgb.d.mts +11 -12
  50. package/dist/function/limit.d.mts +9 -8
  51. package/dist/function/limit.mjs +5 -5
  52. package/dist/function/once.d.mts +26 -6
  53. package/dist/function/once.mjs +135 -76
  54. package/dist/function/retry.d.mts +5 -6
  55. package/dist/function/retry.mjs +3 -3
  56. package/dist/index.d.mts +244 -584
  57. package/dist/index.mjs +1191 -810
  58. package/dist/internal/abort.d.mts +3 -4
  59. package/dist/internal/array/callbacks.d.mts +4 -5
  60. package/dist/internal/array/chunk.d.mts +2 -3
  61. package/dist/internal/array/compact.d.mts +3 -4
  62. package/dist/internal/array/find.d.mts +10 -11
  63. package/dist/internal/array/get.d.mts +7 -8
  64. package/dist/internal/array/group.d.mts +2 -3
  65. package/dist/internal/array/index-of.d.mts +10 -11
  66. package/dist/internal/array/insert.d.mts +5 -6
  67. package/dist/internal/array/match.d.mts +17 -18
  68. package/dist/internal/array/overlap.d.mts +2 -3
  69. package/dist/internal/array/sets.d.mts +5 -6
  70. package/dist/internal/array/shuffle.d.mts +2 -3
  71. package/dist/internal/array/update.d.mts +2 -3
  72. package/dist/internal/defaults.d.mts +3 -4
  73. package/dist/internal/function/assert.d.mts +10 -11
  74. package/dist/internal/function/limit.d.mts +41 -0
  75. package/dist/internal/function/limit.mjs +110 -0
  76. package/dist/internal/function/memoize.d.mts +4 -5
  77. package/dist/internal/function/memoize.mjs +53 -31
  78. package/dist/internal/function/misc.d.mts +2 -3
  79. package/dist/internal/function/work.d.mts +53 -54
  80. package/dist/internal/herald.d.mts +8 -9
  81. package/dist/internal/herald.mjs +38 -26
  82. package/dist/internal/is.d.mts +19 -20
  83. package/dist/internal/math/aggregate.d.mts +14 -15
  84. package/dist/internal/math/misc.d.mts +3 -4
  85. package/dist/internal/number.d.mts +4 -5
  86. package/dist/internal/random.d.mts +3 -4
  87. package/dist/internal/result/misc.d.mts +29 -14
  88. package/dist/internal/result/misc.mjs +4 -0
  89. package/dist/internal/result/models.d.mts +9 -10
  90. package/dist/internal/sized/map.d.mts +2 -3
  91. package/dist/internal/sized/misc.d.mts +2 -3
  92. package/dist/internal/string/case.d.mts +9 -10
  93. package/dist/internal/string/misc.d.mts +8 -9
  94. package/dist/internal/subscription.d.mts +14 -15
  95. package/dist/internal/subscription.mjs +69 -57
  96. package/dist/internal/value/compare.d.mts +17 -9
  97. package/dist/internal/value/compare.mjs +7 -7
  98. package/dist/internal/value/equal.d.mts +34 -15
  99. package/dist/internal/value/equal.mjs +28 -13
  100. package/dist/internal/value/get.d.mts +3 -4
  101. package/dist/internal/value/handlers.d.mts +19 -9
  102. package/dist/internal/value/handlers.mjs +50 -50
  103. package/dist/internal/value/has.d.mts +6 -7
  104. package/dist/internal/value/misc.d.mts +6 -7
  105. package/dist/internal/value/partial.d.mts +3 -4
  106. package/dist/internal/value/set.d.mts +4 -5
  107. package/dist/is.d.mts +13 -13
  108. package/dist/logger.d.mts +5 -4
  109. package/dist/logger.mjs +61 -54
  110. package/dist/math.d.mts +20 -20
  111. package/dist/models.d.mts +58 -46
  112. package/dist/promise/constants.d.mts +14 -15
  113. package/dist/promise/delay.d.mts +3 -4
  114. package/dist/promise/delay.mjs +4 -4
  115. package/dist/promise/helpers.d.mts +7 -8
  116. package/dist/promise/index.d.mts +13 -14
  117. package/dist/promise/misc.d.mts +6 -6
  118. package/dist/promise/models.d.mts +16 -17
  119. package/dist/promise/timed.d.mts +4 -5
  120. package/dist/promise/timed.mjs +5 -5
  121. package/dist/query.d.mts +3 -4
  122. package/dist/queue.d.mts +14 -15
  123. package/dist/queue.mjs +185 -129
  124. package/dist/random.d.mts +8 -8
  125. package/dist/result/index.d.mts +8 -9
  126. package/dist/result/match.d.mts +6 -7
  127. package/dist/result/misc.d.mts +3 -3
  128. package/dist/result/work/flow.d.mts +28 -29
  129. package/dist/result/work/pipe.d.mts +24 -25
  130. package/dist/sized/set.d.mts +2 -3
  131. package/dist/string/fuzzy.d.mts +21 -12
  132. package/dist/string/fuzzy.mjs +77 -49
  133. package/dist/string/index.d.mts +8 -8
  134. package/dist/string/match.d.mts +4 -5
  135. package/dist/string/normalize.d.mts +8 -9
  136. package/dist/string/normalize.mjs +9 -4
  137. package/dist/string/template.d.mts +9 -9
  138. package/dist/string/template.mjs +11 -4
  139. package/dist/value/clone.d.mts +21 -13
  140. package/dist/value/clone.mjs +22 -20
  141. package/dist/value/collection.d.mts +4 -5
  142. package/dist/value/diff.d.mts +5 -6
  143. package/dist/value/freeze.d.mts +18 -19
  144. package/dist/value/freeze.mjs +1 -1
  145. package/dist/value/merge.d.mts +13 -14
  146. package/dist/value/merge.mjs +21 -5
  147. package/dist/value/omit.d.mts +2 -3
  148. package/dist/value/pick.d.mts +2 -3
  149. package/dist/value/shake.d.mts +3 -4
  150. package/dist/value/smush.d.mts +3 -4
  151. package/dist/value/transform.d.mts +15 -10
  152. package/dist/value/transform.mjs +12 -7
  153. package/dist/value/unsmush.d.mts +3 -4
  154. package/package.json +1 -1
  155. package/dist/internal/function/timer.d.mts +0 -10
  156. package/dist/internal/function/timer.mjs +0 -87
@@ -1,7 +1,15 @@
1
1
  import { isArrayOrPlainObject, isTypedArray } from "../internal/is.mjs";
2
- import { createSelfHandlers } from "../internal/value/handlers.mjs";
2
+ import { createValueHandler } from "../internal/value/handlers.mjs";
3
3
  //#region src/value/clone.ts
4
4
  const CLONE_NAME = "clone";
5
+ function Cloner(options) {
6
+ Object.defineProperty(this, CLONE_SYMBOL, { value: options });
7
+ }
8
+ Object.defineProperties(Cloner.prototype, {
9
+ clone: { value: cloneFromCloner },
10
+ deregister: { value: deregisterCloner },
11
+ register: { value: registerCloner }
12
+ });
5
13
  function clone(value, options) {
6
14
  return cloneAny(value, { copy: false }, 0, options);
7
15
  }
@@ -45,6 +53,12 @@ function cloneDataView(value, parameters, depth) {
45
53
  parameters.references.set(value, cloned);
46
54
  return cloned;
47
55
  }
56
+ function cloneFromCloner(value) {
57
+ return cloneAny(value, {
58
+ copy: false,
59
+ options: this[CLONE_SYMBOL]
60
+ }, 0);
61
+ }
48
62
  function cloneMap(map, parameters, depth) {
49
63
  if (depth >= CLONE_MAX_DEPTH) return map;
50
64
  if (parameters.copy) return new Map(map);
@@ -116,7 +130,7 @@ function createCloneOptions(input) {
116
130
  * @param constructor Class constructor
117
131
  */
118
132
  function deregisterCloner(constructor) {
119
- clone.handlers.deregister(constructor);
133
+ cloneHandler.base.deregister(constructor);
120
134
  }
121
135
  /**
122
136
  * Create a cloner with predefined options
@@ -127,20 +141,7 @@ function deregisterCloner(constructor) {
127
141
  * @returns Cloner function
128
142
  */
129
143
  function initializeCloner(options) {
130
- const opts = createCloneOptions(options);
131
- function cloner(value) {
132
- return cloneAny(value, {
133
- copy: false,
134
- options: opts
135
- }, 0);
136
- }
137
- cloner.deregister = deregisterCloner;
138
- cloner.register = registerCloner;
139
- Object.defineProperties(cloner, {
140
- deregister: { value: deregisterCloner },
141
- register: { value: registerCloner }
142
- });
143
- return cloner;
144
+ return new Cloner(createCloneOptions(options));
144
145
  }
145
146
  /**
146
147
  * Register a clone handler for a specific class
@@ -151,7 +152,7 @@ function initializeCloner(options) {
151
152
  * @param handler Method name or clone function _(defaults to method name `clone`)_
152
153
  */
153
154
  function registerCloner(constructor, handler) {
154
- clone.handlers.register(constructor, handler);
155
+ cloneHandler.base.register(constructor, handler);
155
156
  }
156
157
  function tryStructuredClone(value, parameters, depth) {
157
158
  if (depth >= CLONE_MAX_DEPTH) return value;
@@ -173,7 +174,7 @@ const CLONE_DEFAULT_OPTIONS = {
173
174
  copySymbols: false
174
175
  };
175
176
  const CLONE_MAX_DEPTH = 100;
176
- const cloneHandlers = createSelfHandlers(clone, {
177
+ const cloneHandler = createValueHandler(clone, {
177
178
  callback: tryStructuredClone,
178
179
  method: CLONE_NAME
179
180
  });
@@ -187,13 +188,14 @@ const CLONE_PRIMITIVES = {
187
188
  symbol: false,
188
189
  undefined: true
189
190
  };
191
+ const CLONE_SYMBOL = Symbol(CLONE_NAME);
190
192
  clone.deregister = deregisterCloner;
191
- clone.handlers = cloneHandlers;
193
+ clone.handlers = cloneHandler;
192
194
  clone.initialize = initializeCloner;
193
195
  clone.register = registerCloner;
194
196
  Object.defineProperties(clone, {
195
197
  deregister: { value: deregisterCloner },
196
- handlers: { value: cloneHandlers },
198
+ handler: { value: cloneHandler },
197
199
  initialize: { value: initializeCloner },
198
200
  register: { value: registerCloner }
199
201
  });
@@ -6,7 +6,7 @@
6
6
  * @param value Value to check for
7
7
  * @returns `true` if the value exists, otherwise `false`
8
8
  */
9
- declare function inMap<Value>(map: Map<unknown, Value>, value: Value): boolean;
9
+ export declare function inMap<Value>(map: Map<unknown, Value>, value: Value): boolean;
10
10
  /**
11
11
  * Does the value exist for a key in a _Map_?
12
12
  *
@@ -15,7 +15,7 @@ declare function inMap<Value>(map: Map<unknown, Value>, value: Value): boolean;
15
15
  * @param key To return the key for the value
16
16
  * @returns The key for the value if it exists, otherwise `undefined`
17
17
  */
18
- declare function inMap<Key, Value>(map: Map<Key, Value>, value: Value, key: true): Key;
18
+ export declare function inMap<Key, Value>(map: Map<Key, Value>, value: Value, key: true): Key;
19
19
  /**
20
20
  * Does the value exist in a _Set_?
21
21
  *
@@ -23,6 +23,5 @@ declare function inMap<Key, Value>(map: Map<Key, Value>, value: Value, key: true
23
23
  * @param value Value to check for
24
24
  * @returns `true` if the value exists, otherwise `false`
25
25
  */
26
- declare function inSet<Value>(set: Set<Value>, value: Value): boolean;
27
- //#endregion
28
- export { inMap, inSet };
26
+ export declare function inSet<Value>(set: Set<Value>, value: Value): boolean;
27
+ //#endregion
@@ -2,7 +2,7 @@
2
2
  /**
3
3
  * Options for value comparison
4
4
  */
5
- type DiffOptions = {
5
+ export type DiffOptions = {
6
6
  /**
7
7
  * Should `null` and `undefined` be considered equal and ignored in results?
8
8
  */
@@ -11,7 +11,7 @@ type DiffOptions = {
11
11
  /**
12
12
  * The result of a comparison beteen two values
13
13
  */
14
- type DiffResult<First, Second = First> = {
14
+ export type DiffResult<First, Second = First> = {
15
15
  /**
16
16
  * The original values that were compared
17
17
  */
@@ -32,7 +32,7 @@ type DiffType = 'full' | 'none' | 'partial';
32
32
  /**
33
33
  * The difference between two values
34
34
  */
35
- type DiffValue<First = unknown, Second = First> = {
35
+ export type DiffValue<First = unknown, Second = First> = {
36
36
  /**
37
37
  * The value from the first value
38
38
  */
@@ -50,6 +50,5 @@ type DiffValue<First = unknown, Second = First> = {
50
50
  * @param options Comparison options
51
51
  * @returns Difference result
52
52
  */
53
- declare function diff<First, Second = First>(first: First, second: Second, options?: DiffOptions): DiffResult<First, Second>;
54
- //#endregion
55
- export { DiffOptions, DiffResult, DiffValue, diff };
53
+ export declare function diff<First, Second = First>(first: First, second: Second, options?: DiffOptions): DiffResult<First, Second>;
54
+ //#endregion
@@ -3,7 +3,7 @@ import { PlainObject } from "../models.mjs";
3
3
  /**
4
4
  * A frozen value with readonly properties _(going as deep as possible)_
5
5
  */
6
- type Frozen<Value> = Value extends unknown[] ? Readonly<Value> : Value extends PlainObject ? { readonly [Key in keyof Value]: Frozen<Value[Key]>; } : Value extends Map<infer Key, infer Value> ? ReadonlyMap<Key, Frozen<Value>> : Value extends Set<infer Item> ? ReadonlySet<Frozen<Item>> : Readonly<Value>;
6
+ export type Frozen<Value> = Value extends unknown[] ? Readonly<Value> : Value extends PlainObject ? { readonly [Key in keyof Value]: Frozen<Value[Key]>; } : Value extends Map<infer Key, infer Value> ? ReadonlyMap<Key, Frozen<Value>> : Value extends Set<infer Item> ? ReadonlySet<Frozen<Item>> : Readonly<Value>;
7
7
  /**
8
8
  * Freeze an array and its indiced values, but not any nested values
9
9
  *
@@ -12,7 +12,7 @@ type Frozen<Value> = Value extends unknown[] ? Readonly<Value> : Value extends P
12
12
  * @param array Array to freeze
13
13
  * @returns Frozen array
14
14
  */
15
- declare function flatFreeze<Item>(array: Item[]): ReadonlyArray<Item>;
15
+ export declare function flatFreeze<Item>(array: Item[]): ReadonlyArray<Item>;
16
16
  /**
17
17
  * Freeze a map and its values, but not any nested values
18
18
  *
@@ -21,7 +21,7 @@ declare function flatFreeze<Item>(array: Item[]): ReadonlyArray<Item>;
21
21
  * @param map Map to freeze
22
22
  * @returns Frozen map
23
23
  */
24
- declare function flatFreeze<Key, Value>(map: Map<Key, Value>): ReadonlyMap<Key, Value>;
24
+ export declare function flatFreeze<Key, Value>(map: Map<Key, Value>): ReadonlyMap<Key, Value>;
25
25
  /**
26
26
  * Freeze an object and its properties, but not any nested values
27
27
  *
@@ -30,7 +30,7 @@ declare function flatFreeze<Key, Value>(map: Map<Key, Value>): ReadonlyMap<Key,
30
30
  * @param object Object to freeze
31
31
  * @returns Frozen object
32
32
  */
33
- declare function flatFreeze<Value extends PlainObject>(object: Value): Readonly<Value>;
33
+ export declare function flatFreeze<Value extends PlainObject>(object: Value): Readonly<Value>;
34
34
  /**
35
35
  * Freeze a set and its values, but not any nested values
36
36
  *
@@ -39,7 +39,7 @@ declare function flatFreeze<Value extends PlainObject>(object: Value): Readonly<
39
39
  * @param set Set to freeze
40
40
  * @returns Frozen set
41
41
  */
42
- declare function flatFreeze<Item>(set: Set<Item>): ReadonlySet<Item>;
42
+ export declare function flatFreeze<Item>(set: Set<Item>): ReadonlySet<Item>;
43
43
  /**
44
44
  * Freeze any value, if possible
45
45
  *
@@ -50,7 +50,7 @@ declare function flatFreeze<Item>(set: Set<Item>): ReadonlySet<Item>;
50
50
  * @param value Value to freeze
51
51
  * @returns Frozen value
52
52
  */
53
- declare function flatFreeze<Value>(value: Value): Value;
53
+ export declare function flatFreeze<Value>(value: Value): Value;
54
54
  /**
55
55
  * Freeze an array and its values _(but not any nested values)_, preventing modifications
56
56
  *
@@ -58,7 +58,7 @@ declare function flatFreeze<Value>(value: Value): Value;
58
58
  * @param flat Freeze _only_ the array, not any nested values
59
59
  * @returns Frozen array
60
60
  */
61
- declare function freeze<Item>(array: Item[], flat: true): ReadonlyArray<Item>;
61
+ export declare function freeze<Item>(array: Item[], flat: true): ReadonlyArray<Item>;
62
62
  /**
63
63
  * Freeze a map and its values _(but not any nested values)_, preventing modifications
64
64
  *
@@ -66,7 +66,7 @@ declare function freeze<Item>(array: Item[], flat: true): ReadonlyArray<Item>;
66
66
  * @param flat Freeze _only_ the map, not any nested values
67
67
  * @returns Frozen map
68
68
  */
69
- declare function freeze<Key, Value>(map: Map<Key, Value>, flat: true): ReadonlyMap<Key, Value>;
69
+ export declare function freeze<Key, Value>(map: Map<Key, Value>, flat: true): ReadonlyMap<Key, Value>;
70
70
  /**
71
71
  * Freeze an object and its properties _(but not any nested values)_, preventing modifications
72
72
  *
@@ -74,7 +74,7 @@ declare function freeze<Key, Value>(map: Map<Key, Value>, flat: true): ReadonlyM
74
74
  * @param flat Freeze _only_ the object, not any nested values
75
75
  * @returns Frozen object
76
76
  */
77
- declare function freeze<Value extends PlainObject>(object: Value, flat: true): Readonly<Value>;
77
+ export declare function freeze<Value extends PlainObject>(object: Value, flat: true): Readonly<Value>;
78
78
  /**
79
79
  * Freeze a set and its values _(but not any nested values)_, preventing modifications
80
80
  *
@@ -82,7 +82,7 @@ declare function freeze<Value extends PlainObject>(object: Value, flat: true): R
82
82
  * @param flat Freeze _only_ the set, not any nested values
83
83
  * @returns Frozen set
84
84
  */
85
- declare function freeze<Item>(set: Set<Item>, flat: true): ReadonlySet<Item>;
85
+ export declare function freeze<Item>(set: Set<Item>, flat: true): ReadonlySet<Item>;
86
86
  /**
87
87
  * Freeze an array and its values recursively, preventing modifications
88
88
  *
@@ -91,7 +91,7 @@ declare function freeze<Item>(set: Set<Item>, flat: true): ReadonlySet<Item>;
91
91
  * @param array Array to freeze
92
92
  * @returns Frozen array
93
93
  */
94
- declare function freeze<Item>(array: Item[]): Frozen<Item[]>;
94
+ export declare function freeze<Item>(array: Item[]): Frozen<Item[]>;
95
95
  /**
96
96
  * Freeze a map and its values recursively, preventing modifications
97
97
  *
@@ -100,7 +100,7 @@ declare function freeze<Item>(array: Item[]): Frozen<Item[]>;
100
100
  * @param map Map to freeze
101
101
  * @returns Frozen map
102
102
  */
103
- declare function freeze<Key, Value>(map: Map<Key, Value>): Frozen<Map<Key, Value>>;
103
+ export declare function freeze<Key, Value>(map: Map<Key, Value>): Frozen<Map<Key, Value>>;
104
104
  /**
105
105
  * Freeze an object and all its properties recursively
106
106
  *
@@ -109,7 +109,7 @@ declare function freeze<Key, Value>(map: Map<Key, Value>): Frozen<Map<Key, Value
109
109
  * @param object Object to freeze
110
110
  * @returns Frozen object
111
111
  */
112
- declare function freeze<Value extends PlainObject>(object: Value): Frozen<Value>;
112
+ export declare function freeze<Value extends PlainObject>(object: Value): Frozen<Value>;
113
113
  /**
114
114
  * Freeze a set and its values recursively
115
115
  *
@@ -118,7 +118,7 @@ declare function freeze<Value extends PlainObject>(object: Value): Frozen<Value>
118
118
  * @param set Set to freeze
119
119
  * @returns Frozen set
120
120
  */
121
- declare function freeze<Item>(set: Set<Item>): Frozen<Set<Item>>;
121
+ export declare function freeze<Item>(set: Set<Item>): Frozen<Set<Item>>;
122
122
  /**
123
123
  * Freeze any value, if possible
124
124
  *
@@ -127,8 +127,8 @@ declare function freeze<Item>(set: Set<Item>): Frozen<Set<Item>>;
127
127
  * @param value Value to freeze
128
128
  * @returns Frozen value
129
129
  */
130
- declare function freeze<Value>(value: Value): Value;
131
- declare namespace freeze {
130
+ export declare function freeze<Value>(value: Value): Value;
131
+ export declare namespace freeze {
132
132
  var flat: typeof flatFreeze;
133
133
  var is: typeof isFrozen;
134
134
  }
@@ -140,6 +140,5 @@ declare namespace freeze {
140
140
  * @param value Value to check
141
141
  * @returns `true` if the value is frozen, otherwise `false`
142
142
  */
143
- declare function isFrozen(value: unknown): boolean;
144
- //#endregion
145
- export { Frozen, flatFreeze, freeze, isFrozen };
143
+ export declare function isFrozen(value: unknown): boolean;
144
+ //#endregion
@@ -65,7 +65,7 @@ function freezeValue(value, references, flat) {
65
65
  }
66
66
  /**
67
67
  * Is the value frozen?
68
- *
68
+ *
69
69
  * _Available as `isFrozen` and `freeze.is`_
70
70
  *
71
71
  * @param value Value to check
@@ -3,11 +3,11 @@ import { ArrayOrPlainObject, NestedPartial, PlainObject, UnionToIntersection } f
3
3
  /**
4
4
  * Options for assigning values
5
5
  */
6
- type AssignOptions = Omit<MergeOptions, 'assignValues'>;
6
+ export type AssignOptions = Omit<MergeOptions, 'assignValues'>;
7
7
  /**
8
8
  * An assigner function for assigning values from one or more objects to the first one
9
9
  */
10
- type Assigner = {
10
+ export type Assigner = {
11
11
  /**
12
12
  * Assign values from one or more objects to the first one
13
13
  *
@@ -15,12 +15,12 @@ type Assigner = {
15
15
  * @param from Values to assign
16
16
  * @returns Assigned value
17
17
  */
18
- <To extends PlainObject, From extends PlainObject[]>(to: To, from: [...From]): To & UnionToIntersection<From[number]>;
18
+ assign<To extends PlainObject, From extends PlainObject[]>(to: To, from: [...From]): To & UnionToIntersection<From[number]>;
19
19
  };
20
20
  /**
21
21
  * Options for merging values
22
22
  */
23
- type MergeOptions = {
23
+ export type MergeOptions = {
24
24
  /**
25
25
  * Assign values to the first array or object instead of creating a new one?
26
26
  */
@@ -53,14 +53,14 @@ type MergeOptions = {
53
53
  /**
54
54
  * A merger function for merging multiple arrays or objects into a single one
55
55
  */
56
- type Merger = {
56
+ export type Merger = {
57
57
  /**
58
58
  * Merge multiple arrays or objects into a single one
59
59
  *
60
60
  * @param values Values to merge
61
61
  * @returns Merged value
62
62
  */
63
- <Values extends ArrayOrPlainObject[]>(values: Array<NestedPartial<Values[number]>>): UnionToIntersection<Values[number]>;
63
+ merge<Values extends ArrayOrPlainObject[]>(values: Array<NestedPartial<Values[number]>>): UnionToIntersection<Values[number]>;
64
64
  };
65
65
  /**
66
66
  * Assign values from one or more objects to the first one
@@ -70,8 +70,8 @@ type Merger = {
70
70
  * @param options Assigning options
71
71
  * @returns Assigned value
72
72
  */
73
- declare function assign<To extends PlainObject, From extends PlainObject[]>(to: To, from: [...From], options?: AssignOptions): To & UnionToIntersection<From[number]>;
74
- declare namespace assign {
73
+ export declare function assign<To extends PlainObject, From extends PlainObject[]>(to: To, from: [...From], options?: AssignOptions): To & UnionToIntersection<From[number]>;
74
+ export declare namespace assign {
75
75
  var initialize: typeof initializeAssigner;
76
76
  }
77
77
  /**
@@ -82,7 +82,7 @@ declare namespace assign {
82
82
  * @param options Assigning options
83
83
  * @returns Assigner function
84
84
  */
85
- declare function initializeAssigner(options?: AssignOptions): Assigner;
85
+ export declare function initializeAssigner(options?: AssignOptions): Assigner;
86
86
  /**
87
87
  * Create a merger with predefined options
88
88
  *
@@ -91,7 +91,7 @@ declare function initializeAssigner(options?: AssignOptions): Assigner;
91
91
  * @param options Merging options
92
92
  * @returns Merger function
93
93
  */
94
- declare function initializeMerger(options?: MergeOptions): Merger;
94
+ export declare function initializeMerger(options?: MergeOptions): Merger;
95
95
  /**
96
96
  * Merge multiple arrays or objects into a single one
97
97
  *
@@ -99,9 +99,8 @@ declare function initializeMerger(options?: MergeOptions): Merger;
99
99
  * @param options Merging options
100
100
  * @returns Merged value
101
101
  */
102
- declare function merge<Values extends ArrayOrPlainObject[]>(values: [...Values], options?: MergeOptions): UnionToIntersection<Values[number]>;
103
- declare namespace merge {
102
+ export declare function merge<Values extends ArrayOrPlainObject[]>(values: [...Values], options?: MergeOptions): UnionToIntersection<Values[number]>;
103
+ export declare namespace merge {
104
104
  var initialize: typeof initializeMerger;
105
105
  }
106
- //#endregion
107
- export { AssignOptions, Assigner, MergeOptions, Merger, assign, initializeAssigner, initializeMerger, merge };
106
+ //#endregion
@@ -1,5 +1,16 @@
1
1
  import { isArrayOrPlainObject } from "../internal/is.mjs";
2
2
  //#region src/value/merge.ts
3
+ function Assigner(options) {
4
+ Object.defineProperty(this, MERGE_SYMBOL_ASSIGN, { value: {
5
+ ...options,
6
+ assignValues: true
7
+ } });
8
+ }
9
+ Object.defineProperties(Assigner.prototype, { assign: { value: assignFromAssigner } });
10
+ function Merger(options) {
11
+ Object.defineProperty(this, MERGE_SYMBOL_MERGE, { value: options });
12
+ }
13
+ Object.defineProperties(Merger.prototype, { merge: { value: mergeFromMerger } });
3
14
  /**
4
15
  * Assign values from one or more objects to the first one
5
16
  *
@@ -13,6 +24,9 @@ function assign(to, from, options) {
13
24
  actual.assignValues = true;
14
25
  return mergeValues([to, ...from], actual);
15
26
  }
27
+ function assignFromAssigner(to, from) {
28
+ return mergeValues([to, ...from], this[MERGE_SYMBOL_ASSIGN]);
29
+ }
16
30
  function createMergeOptions(options) {
17
31
  const actual = {
18
32
  assignValues: false,
@@ -41,9 +55,7 @@ function getReplaceableObjects(value) {
41
55
  * @returns Assigner function
42
56
  */
43
57
  function initializeAssigner(options) {
44
- const actual = createMergeOptions(options);
45
- actual.assignValues = true;
46
- return ((to, from) => mergeValues([to, ...from], actual));
58
+ return new Assigner(createMergeOptions(options));
47
59
  }
48
60
  /**
49
61
  * Create a merger with predefined options
@@ -54,8 +66,7 @@ function initializeAssigner(options) {
54
66
  * @returns Merger function
55
67
  */
56
68
  function initializeMerger(options) {
57
- const actual = createMergeOptions(options);
58
- return ((values) => mergeValues(values, actual));
69
+ return new Merger(createMergeOptions(options));
59
70
  }
60
71
  /**
61
72
  * Merge multiple arrays or objects into a single one
@@ -67,6 +78,9 @@ function initializeMerger(options) {
67
78
  function merge(values, options) {
68
79
  return mergeValues(values, createMergeOptions(options));
69
80
  }
81
+ function mergeFromMerger(values) {
82
+ return mergeValues(values, this[MERGE_SYMBOL_MERGE]);
83
+ }
70
84
  function mergeObjects(values, options, destination, prefix) {
71
85
  const { length } = values;
72
86
  const isArray = Array.isArray(destination ?? values[0]);
@@ -96,6 +110,8 @@ function mergeValues(values, options, prefix) {
96
110
  if (actual.length > 1) return mergeObjects(actual, options, options.assignValues ? actual[0] : void 0, prefix);
97
111
  return options.assignValues ? actual[0] : Array.isArray(actual[0]) ? actual[0].slice() : { ...actual[0] };
98
112
  }
113
+ const MERGE_SYMBOL_ASSIGN = Symbol("assign");
114
+ const MERGE_SYMBOL_MERGE = Symbol("merge");
99
115
  assign.initialize = initializeAssigner;
100
116
  merge.initialize = initializeMerger;
101
117
  Object.defineProperty(assign, "initialize", { value: initializeAssigner });
@@ -7,6 +7,5 @@ import { PlainObject } from "../models.mjs";
7
7
  * @param keys Keys to omit
8
8
  * @returns Partial object without the specified keys
9
9
  */
10
- declare function omit<Value extends PlainObject, ValueKey extends keyof Value>(value: Value, keys: ValueKey[]): Omit<Value, ValueKey>;
11
- //#endregion
12
- export { omit };
10
+ export declare function omit<Value extends PlainObject, ValueKey extends keyof Value>(value: Value, keys: ValueKey[]): Omit<Value, ValueKey>;
11
+ //#endregion
@@ -7,6 +7,5 @@ import { PlainObject } from "../models.mjs";
7
7
  * @param keys Keys to use
8
8
  * @returns Partial object with only the specified keys
9
9
  */
10
- declare function pick<Value extends PlainObject, ValueKey extends keyof Value>(value: Value, keys: ValueKey[]): Pick<Value, ValueKey>;
11
- //#endregion
12
- export { pick };
10
+ export declare function pick<Value extends PlainObject, ValueKey extends keyof Value>(value: Value, keys: ValueKey[]): Pick<Value, ValueKey>;
11
+ //#endregion
@@ -3,13 +3,12 @@ import { PlainObject } from "../models.mjs";
3
3
  /**
4
4
  * A shaken object, without any `undefined` values
5
5
  */
6
- type Shaken<Value extends PlainObject> = { [Key in keyof Value]: Value[Key] extends undefined ? never : Value[Key]; };
6
+ export type Shaken<Value extends PlainObject> = { [Key in keyof Value]: Value[Key] extends undefined ? never : Value[Key]; };
7
7
  /**
8
8
  * Shake an object, removing all keys with `undefined` values
9
9
  *
10
10
  * @param value Object to shake
11
11
  * @returns Shaken object
12
12
  */
13
- declare function shake<Value extends PlainObject>(value: Value): Shaken<Value>;
14
- //#endregion
15
- export { Shaken, shake };
13
+ export declare function shake<Value extends PlainObject>(value: Value): Shaken<Value>;
14
+ //#endregion
@@ -3,13 +3,12 @@ import { NestedKeys, NestedValue, PlainObject, Simplify, ToString } from "../mod
3
3
  /**
4
4
  * A smushed object, with all nested objects flattened into a single level, using dot notation keys
5
5
  */
6
- type Smushed<Value extends PlainObject> = Simplify<{ [NestedKey in NestedKeys<Value>]: NestedValue<Value, ToString<NestedKey>>; }>;
6
+ export type Smushed<Value extends PlainObject> = Simplify<{ [NestedKey in NestedKeys<Value>]: NestedValue<Value, ToString<NestedKey>>; }>;
7
7
  /**
8
8
  * Smush an object into a flat object that uses dot notation keys
9
9
  *
10
10
  * @param value Object to smush
11
11
  * @returns Smushed object with dot notation keys
12
12
  */
13
- declare function smush<Value extends PlainObject>(value: Value): Smushed<Value>;
14
- //#endregion
15
- export { Smushed, smush };
13
+ export declare function smush<Value extends PlainObject>(value: Value): Smushed<Value>;
14
+ //#endregion
@@ -9,10 +9,16 @@ type TransformCallback<Value extends PlainObject, Key extends keyof Value> = (ke
9
9
  */
10
10
  type TransformCallbacks<Value extends PlainObject> = Partial<{ [Key in keyof Value]: (value: Value[Key]) => Value[Key]; }>;
11
11
  /**
12
- * A transformer function for an object, with predefined callbacks for transforming its properties
12
+ * A transformer for an object, with predefined callbacks for transforming its properties
13
13
  */
14
- type Transformer<Value extends PlainObject> = {
15
- (value: Value): Value;
14
+ export type Transformer<Value extends PlainObject> = {
15
+ /**
16
+ * Transform an object's properties
17
+ *
18
+ * @param value Object to transform
19
+ * @returns Transformed object
20
+ */
21
+ transform(value: Value): Value;
16
22
  };
17
23
  /**
18
24
  * Initialize a transformer for an object with a transformer function
@@ -22,7 +28,7 @@ type Transformer<Value extends PlainObject> = {
22
28
  * @param transform Transformer function
23
29
  * @returns Transformer
24
30
  */
25
- declare function initializeTransformer<Value extends PlainObject>(transform: TransformCallback<Value, keyof Value>): Transformer<Value>;
31
+ export declare function initializeTransformer<Value extends PlainObject>(transform: TransformCallback<Value, keyof Value>): Transformer<Value>;
26
32
  /**
27
33
  * Initialize a transformer for an object with transformer functions
28
34
  *
@@ -31,7 +37,7 @@ declare function initializeTransformer<Value extends PlainObject>(transform: Tra
31
37
  * @param transformers Keyed transformer functions
32
38
  * @returns Transformer
33
39
  */
34
- declare function initializeTransformer<Value extends PlainObject>(transformers: TransformCallbacks<Value>): Transformer<Value>;
40
+ export declare function initializeTransformer<Value extends PlainObject>(transformers: TransformCallbacks<Value>): Transformer<Value>;
35
41
  /**
36
42
  * Transform and objects properties using a transformer function
37
43
  *
@@ -39,7 +45,7 @@ declare function initializeTransformer<Value extends PlainObject>(transformers:
39
45
  * @param transform Transformer function
40
46
  * @returns Transformed object
41
47
  */
42
- declare function transform<Value extends PlainObject, Key extends keyof Value>(value: Value, transform: TransformCallback<Value, Key>): Value;
48
+ export declare function transform<Value extends PlainObject, Key extends keyof Value>(value: Value, transform: TransformCallback<Value, Key>): Value;
43
49
  /**
44
50
  * Transform and objects properties using a transformer object
45
51
  *
@@ -47,9 +53,8 @@ declare function transform<Value extends PlainObject, Key extends keyof Value>(v
47
53
  * @param transformers Keyed transformer functions
48
54
  * @returns Transformed object
49
55
  */
50
- declare function transform<Value extends PlainObject>(value: Value, transformers: TransformCallbacks<Value>): Value;
51
- declare namespace transform {
56
+ export declare function transform<Value extends PlainObject>(value: Value, transformers: TransformCallbacks<Value>): Value;
57
+ export declare namespace transform {
52
58
  var initialize: typeof initializeTransformer;
53
59
  }
54
- //#endregion
55
- export { Transformer, initializeTransformer, transform };
60
+ //#endregion
@@ -1,6 +1,10 @@
1
1
  import { isNonPlainObject } from "../internal/is.mjs";
2
2
  //#region src/value/transform.ts
3
- function getTransformer(input) {
3
+ function Transformer(transformer) {
4
+ Object.defineProperty(this, TRANSFORM_SYMBOL, { value: transformer });
5
+ }
6
+ Object.defineProperties(Transformer.prototype, { transform: { value: transformValue } });
7
+ function getTransformHandler(input) {
4
8
  if (typeof input === "function") return input;
5
9
  if (isNonPlainObject(input)) return;
6
10
  const keys = Object.keys(input);
@@ -11,18 +15,18 @@ function getTransformer(input) {
11
15
  const value = input[key];
12
16
  if (typeof value === "function") transformer[key] = value;
13
17
  }
14
- if (Object.keys(transformer).length > 0) return transformer;
18
+ return Object.keys(transformer).length > 0 ? transformer : void 0;
15
19
  }
16
20
  function initializeTransformer(transform) {
17
- const transformer = getTransformer(transform);
18
- return (value) => transformValue(value, transformer);
21
+ return new Transformer(getTransformHandler(transform));
19
22
  }
20
23
  function transform(value, transform) {
21
- return transformValue(value, getTransformer(transform));
24
+ return transformValue.call(getTransformHandler(transform), value);
22
25
  }
23
- function transformValue(value, transformer) {
26
+ function transformValue(value) {
24
27
  if (isNonPlainObject(value)) return {};
25
- if (transformer == null) return value;
28
+ if (this == null) return value;
29
+ const transformer = TRANSFORM_SYMBOL in this ? this[TRANSFORM_SYMBOL] : this;
26
30
  const keys = Object.keys(value);
27
31
  const { length } = keys;
28
32
  for (let index = 0; index < length; index += 1) {
@@ -33,6 +37,7 @@ function transformValue(value, transformer) {
33
37
  }
34
38
  return value;
35
39
  }
40
+ const TRANSFORM_SYMBOL = Symbol("transform");
36
41
  transform.initialize = initializeTransformer;
37
42
  Object.defineProperty(transform, "initialize", { value: initializeTransformer });
38
43
  //#endregion
@@ -7,13 +7,12 @@ type KeysOfUnion<ObjectType> = keyof UnionToIntersection<ObjectType extends unkn
7
7
  /**
8
8
  * An unsmushed object, with all dot notation keys turned into nested keys
9
9
  */
10
- type Unsmushed<Value extends PlainObject> = Simplify<Omit<{ [UnionKey in KeysOfUnion<Value>]: Value[UnionKey]; }, `${string}.${string}`>>;
10
+ export type Unsmushed<Value extends PlainObject> = Simplify<Omit<{ [UnionKey in KeysOfUnion<Value>]: Value[UnionKey]; }, `${string}.${string}`>>;
11
11
  /**
12
12
  * Unsmush a smushed object _(turning dot notation keys into nested keys)_
13
13
  *
14
14
  * @param value Object to unsmush
15
15
  * @returns Unsmushed object with nested keys
16
16
  */
17
- declare function unsmush<Value extends PlainObject>(value: Value): Unsmushed<Value>;
18
- //#endregion
19
- export { Unsmushed, unsmush };
17
+ export declare function unsmush<Value extends PlainObject>(value: Value): Unsmushed<Value>;
18
+ //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oscarpalmer/atoms",
3
- "version": "0.201.0",
3
+ "version": "0.203.0",
4
4
  "description": "Atomic utilities for making your JavaScript better.",
5
5
  "keywords": [
6
6
  "array",
@@ -1,10 +0,0 @@
1
- import { AsyncCancelableCallback, CancelableCallback, GenericAsyncCallback, GenericCallback } from "../../models.mjs";
2
- //#region src/internal/function/timer.d.ts
3
- type TimerType = 'debounce' | 'throttle' | 'wait';
4
- declare function getAsyncTimer<Callback extends GenericAsyncCallback | GenericCallback>(type: TimerType, callback: Callback, time?: number): AsyncCancelableCallback<Callback>;
5
- declare function getTimer<Callback extends GenericCallback>(type: TimerType, callback: Callback, time?: number): CancelableCallback<Callback>;
6
- declare const TIMER_DEBOUNCE: TimerType;
7
- declare const TIMER_THROTTLE: TimerType;
8
- declare const TIMER_WAIT: TimerType;
9
- //#endregion
10
- export { TIMER_DEBOUNCE, TIMER_THROTTLE, TIMER_WAIT, getAsyncTimer, getTimer };