@oscarpalmer/atoms 0.192.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 (130) hide show
  1. package/dist/index.d.mts +25 -23
  2. package/dist/index.mjs +30 -31
  3. package/dist/queue.d.mts +25 -23
  4. package/dist/queue.mjs +27 -28
  5. package/package.json +3 -4
  6. package/src/array/difference.ts +0 -73
  7. package/src/array/exists.ts +0 -93
  8. package/src/array/filter.ts +0 -182
  9. package/src/array/find.ts +0 -183
  10. package/src/array/first.ts +0 -196
  11. package/src/array/flatten.ts +0 -20
  12. package/src/array/from.ts +0 -129
  13. package/src/array/get.ts +0 -131
  14. package/src/array/group-by.ts +0 -369
  15. package/src/array/index.ts +0 -26
  16. package/src/array/insert.ts +0 -52
  17. package/src/array/intersection.ts +0 -72
  18. package/src/array/last.ts +0 -194
  19. package/src/array/match.ts +0 -436
  20. package/src/array/move.ts +0 -315
  21. package/src/array/partition.ts +0 -91
  22. package/src/array/push.ts +0 -23
  23. package/src/array/reverse.ts +0 -33
  24. package/src/array/select.ts +0 -260
  25. package/src/array/single.ts +0 -93
  26. package/src/array/slice.ts +0 -335
  27. package/src/array/sort.ts +0 -607
  28. package/src/array/splice.ts +0 -106
  29. package/src/array/swap.ts +0 -322
  30. package/src/array/to-map.ts +0 -371
  31. package/src/array/to-record.ts +0 -351
  32. package/src/array/to-set.ts +0 -80
  33. package/src/array/toggle.ts +0 -79
  34. package/src/array/union.ts +0 -72
  35. package/src/array/unique.ts +0 -67
  36. package/src/array/update.ts +0 -75
  37. package/src/beacon.ts +0 -378
  38. package/src/color/constants.ts +0 -137
  39. package/src/color/index.ts +0 -83
  40. package/src/color/instance.ts +0 -162
  41. package/src/color/misc/alpha.ts +0 -56
  42. package/src/color/misc/format.ts +0 -29
  43. package/src/color/misc/get.ts +0 -210
  44. package/src/color/misc/is.ts +0 -221
  45. package/src/color/misc/state.ts +0 -243
  46. package/src/color/models.ts +0 -389
  47. package/src/color/space/hex.ts +0 -184
  48. package/src/color/space/hsl.ts +0 -174
  49. package/src/color/space/hwb.ts +0 -153
  50. package/src/color/space/rgb.ts +0 -240
  51. package/src/function/assert.ts +0 -174
  52. package/src/function/index.ts +0 -2
  53. package/src/function/limit.ts +0 -83
  54. package/src/function/memoize.ts +0 -202
  55. package/src/function/once.ts +0 -200
  56. package/src/function/retry.ts +0 -175
  57. package/src/function/work.ts +0 -1007
  58. package/src/herald.ts +0 -216
  59. package/src/index.ts +0 -68
  60. package/src/internal/array/callbacks.ts +0 -46
  61. package/src/internal/array/chunk.ts +0 -51
  62. package/src/internal/array/compact.ts +0 -56
  63. package/src/internal/array/find.ts +0 -200
  64. package/src/internal/array/group.ts +0 -42
  65. package/src/internal/array/index-of.ts +0 -182
  66. package/src/internal/array/insert.ts +0 -80
  67. package/src/internal/array/overlap.ts +0 -35
  68. package/src/internal/array/sets.ts +0 -74
  69. package/src/internal/array/shuffle.ts +0 -33
  70. package/src/internal/array/update.ts +0 -52
  71. package/src/internal/function/misc.ts +0 -8
  72. package/src/internal/function/timer.ts +0 -168
  73. package/src/internal/is.ts +0 -244
  74. package/src/internal/math/aggregate.ts +0 -164
  75. package/src/internal/math/misc.ts +0 -28
  76. package/src/internal/number.ts +0 -129
  77. package/src/internal/random.ts +0 -49
  78. package/src/internal/result.ts +0 -92
  79. package/src/internal/sized.ts +0 -25
  80. package/src/internal/string.ts +0 -128
  81. package/src/internal/subscription.ts +0 -264
  82. package/src/internal/value/compare.ts +0 -170
  83. package/src/internal/value/equal.ts +0 -465
  84. package/src/internal/value/get.ts +0 -57
  85. package/src/internal/value/handlers.ts +0 -95
  86. package/src/internal/value/has.ts +0 -118
  87. package/src/internal/value/misc.ts +0 -125
  88. package/src/internal/value/partial.ts +0 -46
  89. package/src/internal/value/set.ts +0 -132
  90. package/src/is.ts +0 -182
  91. package/src/logger.ts +0 -230
  92. package/src/math.ts +0 -281
  93. package/src/models.ts +0 -286
  94. package/src/number.ts +0 -1
  95. package/src/promise/delay.ts +0 -62
  96. package/src/promise/helpers.ts +0 -96
  97. package/src/promise/index.ts +0 -300
  98. package/src/promise/misc.ts +0 -96
  99. package/src/promise/models.ts +0 -195
  100. package/src/promise/timed.ts +0 -91
  101. package/src/query.ts +0 -147
  102. package/src/queue.ts +0 -814
  103. package/src/random.ts +0 -125
  104. package/src/result/index.ts +0 -105
  105. package/src/result/match.ts +0 -124
  106. package/src/result/misc.ts +0 -129
  107. package/src/result/models.ts +0 -83
  108. package/src/result/work/flow.ts +0 -488
  109. package/src/result/work/pipe.ts +0 -496
  110. package/src/sized/map.ts +0 -110
  111. package/src/sized/set.ts +0 -107
  112. package/src/string/case.ts +0 -236
  113. package/src/string/fuzzy.ts +0 -444
  114. package/src/string/index.ts +0 -199
  115. package/src/string/match.ts +0 -80
  116. package/src/string/normalize.ts +0 -205
  117. package/src/string/template.ts +0 -161
  118. package/src/value/clone.ts +0 -319
  119. package/src/value/collection.ts +0 -63
  120. package/src/value/diff.ts +0 -232
  121. package/src/value/freeze.ts +0 -322
  122. package/src/value/handle.ts +0 -3
  123. package/src/value/index.ts +0 -5
  124. package/src/value/merge.ts +0 -278
  125. package/src/value/omit.ts +0 -20
  126. package/src/value/pick.ts +0 -20
  127. package/src/value/shake.ts +0 -45
  128. package/src/value/smush.ts +0 -89
  129. package/src/value/transform.ts +0 -153
  130. package/src/value/unsmush.ts +0 -84
@@ -1,322 +0,0 @@
1
- import {noop} from '../function';
2
- import {isPlainObject} from '../internal/is';
3
- import type {PlainObject} from '../models';
4
-
5
- // #region Types
6
-
7
- /**
8
- * A frozen value with readonly properties _(going as deep as possible)_
9
- */
10
- export type Frozen<Value> = Value extends unknown[]
11
- ? Readonly<Value>
12
- : Value extends PlainObject
13
- ? {
14
- readonly [Key in keyof Value]: Frozen<Value[Key]>;
15
- }
16
- : Value extends Map<infer Key, infer Value>
17
- ? ReadonlyMap<Key, Frozen<Value>>
18
- : Value extends Set<infer Item>
19
- ? ReadonlySet<Frozen<Item>>
20
- : Readonly<Value>;
21
-
22
- // #endregion
23
-
24
- // #region Functions
25
-
26
- function fakeDelete(): boolean {
27
- return false;
28
- }
29
-
30
- /**
31
- * Freeze an array and its indiced values, but not any nested values
32
- *
33
- * _Available as `flatFreeze` and `freeze.flat`_
34
- *
35
- * @param array Array to freeze
36
- * @returns Frozen array
37
- */
38
- export function flatFreeze<Item>(array: Item[]): ReadonlyArray<Item>;
39
-
40
- /**
41
- * Freeze a map and its values, but not any nested values
42
- *
43
- * _Available as `flatFreeze` and `freeze.flat`_
44
- *
45
- * @param map Map to freeze
46
- * @returns Frozen map
47
- */
48
- export function flatFreeze<Key, Value>(map: Map<Key, Value>): ReadonlyMap<Key, Value>;
49
-
50
- /**
51
- * Freeze an object and its properties, but not any nested values
52
- *
53
- * _Available as `flatFreeze` and `freeze.flat`_
54
- *
55
- * @param object Object to freeze
56
- * @returns Frozen object
57
- */
58
- export function flatFreeze<Value extends PlainObject>(object: Value): Readonly<Value>;
59
-
60
- /**
61
- * Freeze a set and its values, but not any nested values
62
- *
63
- * _Available as `flatFreeze` and `freeze.flat`_
64
- *
65
- * @param set Set to freeze
66
- * @returns Frozen set
67
- */
68
- export function flatFreeze<Item>(set: Set<Item>): ReadonlySet<Item>;
69
-
70
- /**
71
- * Freeze any value, if possible
72
- *
73
- * _(Only arrays, maps, plain objects, and sets are freezable)_
74
- *
75
- * _Available as `flatFreeze` and `freeze.flat`_
76
- *
77
- * @param value Value to freeze
78
- * @returns Frozen value
79
- */
80
- export function flatFreeze<Value>(value: Value): Value;
81
-
82
- export function flatFreeze(value: unknown): unknown {
83
- return freezeValue(value, new WeakSet(), true);
84
- }
85
-
86
- /**
87
- * Freeze an array and its values _(but not any nested values)_, preventing modifications
88
- *
89
- * @param array Array to freeze
90
- * @param flat Freeze _only_ the array, not any nested values
91
- * @returns Frozen array
92
- */
93
- export function freeze<Item>(array: Item[], flat: true): ReadonlyArray<Item>;
94
-
95
- /**
96
- * Freeze a map and its values _(but not any nested values)_, preventing modifications
97
- *
98
- * @param map Map to freeze
99
- * @param flat Freeze _only_ the map, not any nested values
100
- * @returns Frozen map
101
- */
102
- export function freeze<Key, Value>(map: Map<Key, Value>, flat: true): ReadonlyMap<Key, Value>;
103
-
104
- /**
105
- * Freeze an object and its properties _(but not any nested values)_, preventing modifications
106
- *
107
- * @param object Object to freeze
108
- * @param flat Freeze _only_ the object, not any nested values
109
- * @returns Frozen object
110
- */
111
- export function freeze<Value extends PlainObject>(object: Value, flat: true): Readonly<Value>;
112
-
113
- /**
114
- * Freeze a set and its values _(but not any nested values)_, preventing modifications
115
- *
116
- * @param set Set to freeze
117
- * @param flat Freeze _only_ the set, not any nested values
118
- * @returns Frozen set
119
- */
120
- export function freeze<Item>(set: Set<Item>, flat: true): ReadonlySet<Item>;
121
-
122
- /**
123
- * Freeze an array and its values recursively, preventing modifications
124
- *
125
- * _(If you only want to freeze the array itself, but not any nested values, use `freeze(array, true)`, `freeze.flat(array)`, or `flatFreeze(array)` instead)_
126
- *
127
- * @param array Array to freeze
128
- * @returns Frozen array
129
- */
130
- export function freeze<Item>(array: Item[]): Frozen<Item[]>;
131
-
132
- /**
133
- * Freeze a map and its values recursively, preventing modifications
134
- *
135
- * _(If you only want to freeze the map itself, but not any nested values, use `freeze(map, true)`, `freeze.flat(map)`, or `flatFreeze(map)` instead)_
136
- *
137
- * @param map Map to freeze
138
- * @returns Frozen map
139
- */
140
- export function freeze<Key, Value>(map: Map<Key, Value>): Frozen<Map<Key, Value>>;
141
-
142
- /**
143
- * Freeze an object and all its properties recursively
144
- *
145
- * _(If you only want to freeze the object itself, but not any nested values, use `freeze(object, true)`, `freeze.flat(object)`, or `flatFreeze(object)` instead)_
146
- *
147
- * @param object Object to freeze
148
- * @returns Frozen object
149
- */
150
- export function freeze<Value extends PlainObject>(object: Value): Frozen<Value>;
151
-
152
- /**
153
- * Freeze a set and its values recursively
154
- *
155
- * _(If you only want to freeze the set itself, but not any nested values, use `freeze(set, true)`, `freeze.flat(set)`, or `flatFreeze(set)` instead)_
156
- *
157
- * @param set Set to freeze
158
- * @returns Frozen set
159
- */
160
- export function freeze<Item>(set: Set<Item>): Frozen<Set<Item>>;
161
-
162
- /**
163
- * Freeze any value, if possible
164
- *
165
- * _(Only arrays, maps, plain objects, and sets are freezable)_
166
- *
167
- * @param value Value to freeze
168
- * @returns Frozen value
169
- */
170
- export function freeze<Value>(value: Value): Value;
171
-
172
- export function freeze(value: unknown, flat?: unknown): unknown {
173
- return freezeValue(value, new WeakSet(), flat === true);
174
- }
175
-
176
- freeze.flat = flatFreeze;
177
- freeze.is = isFrozen;
178
-
179
- function freezeArray(array: unknown[], references: WeakSet<any>, flat: boolean): Frozen<unknown[]> {
180
- if (flat) {
181
- return Object.freeze(array) as Frozen<unknown[]>;
182
- }
183
-
184
- references.add(array);
185
-
186
- const {length} = array;
187
-
188
- for (let index = 0; index < length; index += 1) {
189
- const value = array[index];
190
-
191
- if (!references.has(value)) {
192
- array[index] = freezeValue(array[index], references, false);
193
- }
194
- }
195
-
196
- return Object.freeze(array) as Frozen<unknown[]>;
197
- }
198
-
199
- function freezeMap(
200
- map: Map<unknown, unknown>,
201
- references: WeakSet<any>,
202
- flat: boolean,
203
- ): ReadonlyMap<unknown, unknown> {
204
- frozenValues.add(map);
205
-
206
- map.clear = noop;
207
- map.delete = fakeDelete;
208
- map.set = () => map;
209
-
210
- if (flat) {
211
- return map as ReadonlyMap<unknown, unknown>;
212
- }
213
-
214
- references.add(map);
215
-
216
- const entries = map.entries();
217
-
218
- for (const [key, value] of entries) {
219
- if (!references.has(value)) {
220
- map.set(key, freezeValue(value, references, false));
221
- }
222
- }
223
-
224
- return map as ReadonlyMap<unknown, unknown>;
225
- }
226
-
227
- function freezeObject(
228
- object: PlainObject,
229
- references: WeakSet<any>,
230
- flat: boolean,
231
- ): Frozen<PlainObject> {
232
- if (flat) {
233
- return Object.freeze(object) as Frozen<PlainObject>;
234
- }
235
-
236
- references.add(object);
237
-
238
- const keys = Object.keys(object);
239
- const {length} = keys;
240
-
241
- for (let index = 0; index < length; index += 1) {
242
- const key = keys[index];
243
-
244
- if (!references.has(object[key])) {
245
- object[key] = freezeValue(object[key], references, false);
246
- }
247
- }
248
-
249
- return Object.freeze(object) as Frozen<PlainObject>;
250
- }
251
-
252
- function freezeSet(
253
- set: Set<unknown>,
254
- references: WeakSet<any>,
255
- flat: boolean,
256
- ): ReadonlySet<unknown> {
257
- frozenValues.add(set);
258
-
259
- set.clear = noop;
260
- set.delete = fakeDelete;
261
- set.add = () => set;
262
-
263
- if (flat) {
264
- return set as ReadonlySet<unknown>;
265
- }
266
-
267
- references.add(set);
268
-
269
- const values = set.values();
270
-
271
- for (const value of values) {
272
- if (!references.has(value)) {
273
- set.add(freezeValue(value, references, false));
274
- }
275
- }
276
-
277
- return set as ReadonlySet<unknown>;
278
- }
279
-
280
- function freezeValue(value: unknown, references: WeakSet<any>, flat: boolean): unknown {
281
- switch (true) {
282
- case isFrozen(value):
283
- return value;
284
-
285
- case value instanceof Map:
286
- return freezeMap(value, references, flat);
287
-
288
- case value instanceof Set:
289
- return freezeSet(value, references, flat);
290
-
291
- case Array.isArray(value):
292
- return freezeArray(value, references, flat);
293
-
294
- case isPlainObject(value):
295
- return freezeObject(value, references, flat);
296
-
297
- default:
298
- return value;
299
- }
300
- }
301
-
302
- /**
303
- * Is the value frozen?
304
- *
305
- * @param value Value to check
306
- * @returns `true` if the value is frozen, otherwise `false`
307
- */
308
- export function isFrozen(value: unknown): boolean {
309
- if (value instanceof Map || value instanceof Set) {
310
- return frozenValues.has(value);
311
- }
312
-
313
- return typeof value === 'object' && value !== null && Object.isFrozen(value);
314
- }
315
-
316
- // #endregion
317
-
318
- // #region Variables
319
-
320
- const frozenValues = new WeakSet();
321
-
322
- // #endregion
@@ -1,3 +0,0 @@
1
- export {getValue} from '../internal/value/get';
2
- export {hasValue} from '../internal/value/has';
3
- export {setValue} from '../internal/value/set';
@@ -1,5 +0,0 @@
1
- export {omit} from './omit';
2
- export {pick} from './pick';
3
- export {shake, type Shaken} from './shake';
4
- export {smush, type Smushed} from './smush';
5
- export {unsmush, type Unsmushed} from './unsmush';
@@ -1,278 +0,0 @@
1
- import {isArrayOrPlainObject} from '../internal/is';
2
- import type {ArrayOrPlainObject, NestedPartial, PlainObject, UnionToIntersection} from '../models';
3
-
4
- // #region Types
5
-
6
- /**
7
- * Options for assigning values
8
- */
9
- export type AssignOptions = Omit<MergeOptions, 'assignValues'>;
10
-
11
- /**
12
- * An assigner function for assigning values from one or more objects to the first one
13
- */
14
- export type Assigner = {
15
- /**
16
- * Assign values from one or more objects to the first one
17
- *
18
- * @param to Value to assign to
19
- * @param from Values to assign
20
- * @returns Assigned value
21
- */
22
- <To extends PlainObject, From extends PlainObject[]>(
23
- to: To,
24
- from: [...From],
25
- ): To & UnionToIntersection<From[number]>;
26
- };
27
-
28
- /**
29
- * Options for merging values
30
- */
31
- export type MergeOptions = {
32
- /**
33
- * Assign values to the first array or object instead of creating a new one?
34
- */
35
- assignValues?: boolean;
36
- /**
37
- * Key _(or key epxressions)_ for values that should be replaced
38
- *
39
- * ```ts
40
- * merge([{items: [1, 2, 3]}, {items: [99]}]); // => {items: [99]}
41
- * ```
42
- */
43
- replaceableObjects?: string | RegExp | Array<string | RegExp>;
44
- /**
45
- * Skip nullable values when merging objects?
46
- *
47
- * ```ts
48
- * merge({a: 1, b: 2}, {b: null, c: 3}, {d: null}); // => {a: 1, b: 2, c: 3}
49
- * ```
50
- */
51
- skipNullableAny?: boolean;
52
- /**
53
- * Skip nullable values when merging arrays?
54
- *
55
- * ```ts
56
- * merge([1, 2, 3], [null, null, 99]); // => [1, 2, 99]
57
- * ```
58
- */
59
- skipNullableInArrays?: boolean;
60
- };
61
-
62
- /**
63
- * A merger function for merging multiple arrays or objects into a single one
64
- */
65
- export type Merger = {
66
- /**
67
- * Merge multiple arrays or objects into a single one
68
- *
69
- * @param values Values to merge
70
- * @returns Merged value
71
- */
72
- <Values extends ArrayOrPlainObject[]>(
73
- values: NestedPartial<Values[number]>[],
74
- ): UnionToIntersection<Values[number]>;
75
- };
76
-
77
- type Options = {
78
- assignValues: boolean;
79
- replaceableObjects: ReplaceableObjectsCallback | undefined;
80
- skipNullableAny: boolean;
81
- skipNullableInArrays: boolean;
82
- };
83
-
84
- type ReplaceableObjectsCallback = (name: string) => boolean;
85
-
86
- // #endregion
87
-
88
- // #region Functions
89
-
90
- /**
91
- * Assign values from one or more objects to the first one
92
- *
93
- * @param to Value to assign to
94
- * @param from Values to assign
95
- * @param options Assigning options
96
- * @returns Assigned value
97
- */
98
- export function assign<To extends PlainObject, From extends PlainObject[]>(
99
- to: To,
100
- from: [...From],
101
- options?: AssignOptions,
102
- ): To & UnionToIntersection<From[number]> {
103
- const actual = getMergeOptions(options);
104
-
105
- actual.assignValues = true;
106
-
107
- return mergeValues([to, ...from], actual) as To & UnionToIntersection<From[number]>;
108
- }
109
-
110
- assign.initialize = initializeAssigner;
111
-
112
- function getMergeOptions(options?: MergeOptions): Options {
113
- const actual: Options = {
114
- assignValues: false,
115
- replaceableObjects: undefined,
116
- skipNullableAny: false,
117
- skipNullableInArrays: false,
118
- };
119
-
120
- if (typeof options !== 'object' || options == null) {
121
- return actual;
122
- }
123
-
124
- actual.replaceableObjects = getReplaceableObjects(options.replaceableObjects);
125
-
126
- actual.assignValues = options.assignValues === true;
127
- actual.skipNullableAny = options.skipNullableAny === true;
128
- actual.skipNullableInArrays = options.skipNullableInArrays === true;
129
-
130
- return actual;
131
- }
132
-
133
- function getReplaceableObjects(value: unknown): ReplaceableObjectsCallback | undefined {
134
- const items = (Array.isArray(value) ? value : [value]).filter(
135
- item => typeof item === 'string' || item instanceof RegExp,
136
- );
137
-
138
- if (items.length > 0) {
139
- return (name: string) =>
140
- items.some(item => (typeof item === 'string' ? item === name : item.test(name)));
141
- }
142
- }
143
-
144
- /**
145
- * Create an assigner with predefined options
146
- *
147
- * _Available as `initializeAssigner` and `assign.initialize`_
148
- *
149
- * @param options Assigning options
150
- * @returns Assigner function
151
- */
152
- export function initializeAssigner(options?: AssignOptions): Assigner {
153
- const actual = getMergeOptions(options);
154
-
155
- actual.assignValues = true;
156
-
157
- return ((to: PlainObject, from: PlainObject[]): PlainObject =>
158
- mergeValues([to, ...from], actual) as PlainObject) as Assigner;
159
- }
160
-
161
- /**
162
- * Create a merger with predefined options
163
- *
164
- * _Available as `initializeMerger` and `merge.initialize`_
165
- *
166
- * @param options Merging options
167
- * @returns Merger function
168
- */
169
- export function initializeMerger(options?: MergeOptions): Merger {
170
- const actual = getMergeOptions(options);
171
-
172
- return ((values: NestedPartial<ArrayOrPlainObject>[]): ArrayOrPlainObject =>
173
- mergeValues(values, actual)) as Merger;
174
- }
175
-
176
- /**
177
- * Merge multiple arrays or objects into a single one
178
- *
179
- * @param values Values to merge
180
- * @param options Merging options
181
- * @returns Merged value
182
- */
183
- export function merge<Values extends ArrayOrPlainObject[]>(
184
- values: [...Values],
185
- options?: MergeOptions,
186
- ): UnionToIntersection<Values[number]> {
187
- return mergeValues(values, getMergeOptions(options)) as UnionToIntersection<Values[number]>;
188
- }
189
-
190
- merge.initialize = initializeMerger;
191
-
192
- function mergeObjects(
193
- values: ArrayOrPlainObject[],
194
- options: Options,
195
- destination?: ArrayOrPlainObject,
196
- prefix?: string,
197
- ): ArrayOrPlainObject {
198
- const {length} = values;
199
-
200
- const isArray = Array.isArray(destination ?? values[0]);
201
- const merged = (destination ?? (isArray ? [] : {})) as PlainObject;
202
-
203
- const offset = destination == null ? 0 : 1;
204
-
205
- for (let outerIndex = offset; outerIndex < length; outerIndex += 1) {
206
- const item = values[outerIndex] as PlainObject;
207
- const keys = Object.keys(item);
208
- const size = keys.length;
209
-
210
- for (let innerIndex = 0; innerIndex < size; innerIndex += 1) {
211
- const key = keys[innerIndex];
212
-
213
- const next = item[key];
214
- const previous = merged[key];
215
-
216
- if (next == null && (options.skipNullableAny || (isArray && options.skipNullableInArrays))) {
217
- continue;
218
- }
219
-
220
- const full =
221
- options.replaceableObjects == null ? undefined : prefix == null ? key : `${prefix}.${key}`;
222
-
223
- if (
224
- isArrayOrPlainObject(next) &&
225
- isArrayOrPlainObject(previous) &&
226
- !(options.replaceableObjects?.(full!) ?? false)
227
- ) {
228
- merged[key] = mergeObjects(
229
- [previous, next],
230
- options,
231
- (destination == null ? undefined : merged[key]) as ArrayOrPlainObject,
232
- full,
233
- );
234
- } else {
235
- merged[key] = next;
236
- }
237
- }
238
- }
239
-
240
- return merged;
241
- }
242
-
243
- function mergeValues(
244
- values: ArrayOrPlainObject[],
245
- options: Options,
246
- prefix?: string,
247
- ): ArrayOrPlainObject {
248
- if (!Array.isArray(values)) {
249
- return {};
250
- }
251
-
252
- const actual = values.filter(isArrayOrPlainObject);
253
-
254
- if (actual.length === 0) {
255
- return {};
256
- }
257
-
258
- if (
259
- options.assignValues &&
260
- actual.length === 2 &&
261
- !Array.isArray(actual[0]) &&
262
- Object.keys(actual[0]).length === 0
263
- ) {
264
- return Object.assign(actual[0], actual[1]);
265
- }
266
-
267
- if (actual.length > 1) {
268
- return mergeObjects(actual, options, options.assignValues ? actual[0] : undefined, prefix);
269
- }
270
-
271
- return options.assignValues
272
- ? actual[0]
273
- : Array.isArray(actual[0])
274
- ? actual[0].slice()
275
- : {...actual[0]};
276
- }
277
-
278
- // #endregion
package/src/value/omit.ts DELETED
@@ -1,20 +0,0 @@
1
- import {partial} from '../internal/value/partial';
2
- import type {PlainObject} from '../models';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Create a new object without the specified keys
8
- *
9
- * @param value Original object
10
- * @param keys Keys to omit
11
- * @returns Partial object without the specified keys
12
- */
13
- export function omit<Value extends PlainObject, ValueKey extends keyof Value>(
14
- value: Value,
15
- keys: ValueKey[],
16
- ): Omit<Value, ValueKey> {
17
- return partial(value, keys, true);
18
- }
19
-
20
- // #endregion
package/src/value/pick.ts DELETED
@@ -1,20 +0,0 @@
1
- import {partial} from '../internal/value/partial';
2
- import type {PlainObject} from '../models';
3
-
4
- // #region Functions
5
-
6
- /**
7
- * Create a new object with only the specified keys
8
- *
9
- * @param value Original object
10
- * @param keys Keys to use
11
- * @returns Partial object with only the specified keys
12
- */
13
- export function pick<Value extends PlainObject, ValueKey extends keyof Value>(
14
- value: Value,
15
- keys: ValueKey[],
16
- ): Pick<Value, ValueKey> {
17
- return partial(value, keys, false);
18
- }
19
-
20
- // #endregion
@@ -1,45 +0,0 @@
1
- import {isNonPlainObject} from '../internal/is';
2
- import type {PlainObject} from '../models';
3
-
4
- // #region Types
5
-
6
- /**
7
- * A shaken object, without any `undefined` values
8
- */
9
- export type Shaken<Value extends PlainObject> = {
10
- [Key in keyof Value]: Value[Key] extends undefined ? never : Value[Key];
11
- };
12
-
13
- // #endregion
14
-
15
- // #region Functions
16
-
17
- /**
18
- * Shake an object, removing all keys with `undefined` values
19
- *
20
- * @param value Object to shake
21
- * @returns Shaken object
22
- */
23
- export function shake<Value extends PlainObject>(value: Value): Shaken<Value> {
24
- const shaken: PlainObject = {};
25
-
26
- if (isNonPlainObject(value)) {
27
- return shaken as Shaken<Value>;
28
- }
29
-
30
- const keys = Object.keys(value) as (keyof Value)[];
31
- const {length} = keys;
32
-
33
- for (let index = 0; index < length; index += 1) {
34
- const key = keys[index];
35
- const val = value[key];
36
-
37
- if (val !== undefined) {
38
- shaken[key] = val;
39
- }
40
- }
41
-
42
- return shaken as Shaken<Value>;
43
- }
44
-
45
- // #endregion