@oscarpalmer/atoms 0.184.2 → 0.186.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 +29 -0
  2. package/dist/array/exists.d.mts +35 -0
  3. package/dist/array/filter.d.mts +72 -2
  4. package/dist/array/find.d.mts +70 -0
  5. package/dist/array/first.d.mts +77 -2
  6. package/dist/array/flatten.d.mts +6 -0
  7. package/dist/array/flatten.mjs +6 -0
  8. package/dist/array/from.d.mts +36 -0
  9. package/dist/array/get.d.mts +21 -13
  10. package/dist/array/group-by.d.mts +142 -0
  11. package/dist/array/index.d.mts +2 -2
  12. package/dist/array/index.mjs +2 -2
  13. package/dist/array/insert.d.mts +16 -0
  14. package/dist/array/intersection.d.mts +29 -0
  15. package/dist/array/last.d.mts +75 -2
  16. package/dist/array/{position.d.mts → match.d.mts} +168 -36
  17. package/dist/array/{position.mjs → match.mjs} +16 -16
  18. package/dist/array/move.d.mts +78 -8
  19. package/dist/array/move.mjs +11 -1
  20. package/dist/array/partition.d.mts +35 -0
  21. package/dist/array/push.d.mts +8 -0
  22. package/dist/array/push.mjs +8 -0
  23. package/dist/array/reverse.d.mts +1 -0
  24. package/dist/array/reverse.mjs +1 -0
  25. package/dist/array/select.d.mts +94 -8
  26. package/dist/array/single.d.mts +29 -0
  27. package/dist/array/slice.d.mts +106 -16
  28. package/dist/array/sort.d.mts +30 -4
  29. package/dist/array/sort.mjs +1 -1
  30. package/dist/array/splice.d.mts +48 -0
  31. package/dist/array/splice.mjs +2 -1
  32. package/dist/array/swap.d.mts +113 -8
  33. package/dist/array/swap.mjs +2 -1
  34. package/dist/array/to-map.d.mts +124 -0
  35. package/dist/array/to-record.d.mts +124 -0
  36. package/dist/array/to-set.d.mts +24 -0
  37. package/dist/array/toggle.d.mts +38 -3
  38. package/dist/array/union.d.mts +29 -0
  39. package/dist/array/unique.d.mts +24 -0
  40. package/dist/array/update.d.mts +38 -3
  41. package/dist/beacon.d.mts +12 -0
  42. package/dist/beacon.mjs +9 -0
  43. package/dist/color/instance.d.mts +8 -0
  44. package/dist/color/instance.mjs +3 -0
  45. package/dist/color/models.d.mts +30 -0
  46. package/dist/function/assert.d.mts +29 -8
  47. package/dist/function/assert.mjs +29 -8
  48. package/dist/function/memoize.d.mts +3 -0
  49. package/dist/function/memoize.mjs +3 -0
  50. package/dist/function/retry.d.mts +3 -0
  51. package/dist/function/retry.mjs +3 -0
  52. package/dist/function/work.mjs +1 -1
  53. package/dist/index.d.mts +2158 -288
  54. package/dist/index.mjs +294 -181
  55. package/dist/internal/array/chunk.d.mts +6 -0
  56. package/dist/internal/array/chunk.mjs +6 -0
  57. package/dist/internal/array/compact.d.mts +12 -0
  58. package/dist/internal/array/index-of.d.mts +70 -0
  59. package/dist/internal/math/aggregate.d.mts +29 -0
  60. package/dist/internal/value/compare.d.mts +2 -1
  61. package/dist/internal/value/equal.d.mts +5 -0
  62. package/dist/internal/value/get.d.mts +27 -5
  63. package/dist/internal/value/has.d.mts +7 -7
  64. package/dist/internal/value/has.mjs +1 -1
  65. package/dist/internal/value/misc.d.mts +2 -2
  66. package/dist/internal/value/misc.mjs +10 -4
  67. package/dist/logger.d.mts +11 -0
  68. package/dist/logger.mjs +11 -0
  69. package/dist/models.d.mts +14 -1
  70. package/dist/promise/helpers.mjs +1 -1
  71. package/dist/promise/index.d.mts +0 -6
  72. package/dist/promise/models.d.mts +36 -0
  73. package/dist/promise/models.mjs +6 -0
  74. package/dist/queue.d.mts +13 -1
  75. package/dist/queue.mjs +9 -0
  76. package/dist/result/index.d.mts +0 -8
  77. package/dist/result/index.mjs +0 -8
  78. package/dist/result/match.d.mts +4 -4
  79. package/dist/result/work/flow.d.mts +12 -36
  80. package/dist/result/work/pipe.d.mts +11 -33
  81. package/dist/sized/set.d.mts +3 -2
  82. package/dist/sized/set.mjs +3 -2
  83. package/dist/value/collection.d.mts +1 -1
  84. package/dist/value/handle.mjs +1 -1
  85. package/dist/value/merge.d.mts +28 -25
  86. package/dist/value/merge.mjs +29 -18
  87. package/dist/value/shake.d.mts +3 -0
  88. package/dist/value/smush.d.mts +3 -0
  89. package/dist/value/transform.d.mts +10 -1
  90. package/dist/value/unsmush.d.mts +2 -3
  91. package/package.json +5 -5
  92. package/src/array/difference.ts +33 -0
  93. package/src/array/exists.ts +35 -0
  94. package/src/array/filter.ts +72 -2
  95. package/src/array/find.ts +70 -0
  96. package/src/array/first.ts +77 -3
  97. package/src/array/flatten.ts +6 -0
  98. package/src/array/from.ts +40 -0
  99. package/src/array/get.ts +21 -15
  100. package/src/array/group-by.ts +142 -0
  101. package/src/array/index.ts +1 -1
  102. package/src/array/insert.ts +16 -2
  103. package/src/array/intersection.ts +33 -0
  104. package/src/array/last.ts +75 -2
  105. package/src/array/{position.ts → match.ts} +197 -65
  106. package/src/array/move.ts +87 -13
  107. package/src/array/partition.ts +35 -0
  108. package/src/array/push.ts +8 -2
  109. package/src/array/reverse.ts +5 -0
  110. package/src/array/select.ts +96 -13
  111. package/src/array/single.ts +29 -0
  112. package/src/array/slice.ts +114 -24
  113. package/src/array/sort.ts +30 -4
  114. package/src/array/splice.ts +52 -4
  115. package/src/array/swap.ts +122 -13
  116. package/src/array/to-map.ts +124 -0
  117. package/src/array/to-record.ts +124 -0
  118. package/src/array/to-set.ts +24 -0
  119. package/src/array/toggle.ts +42 -3
  120. package/src/array/union.ts +33 -0
  121. package/src/array/unique.ts +24 -0
  122. package/src/array/update.ts +38 -3
  123. package/src/beacon.ts +12 -0
  124. package/src/color/index.ts +0 -3
  125. package/src/color/instance.ts +9 -1
  126. package/src/color/models.ts +30 -0
  127. package/src/function/assert.ts +66 -7
  128. package/src/function/memoize.ts +3 -0
  129. package/src/function/once.ts +5 -1
  130. package/src/function/retry.ts +3 -0
  131. package/src/internal/array/chunk.ts +6 -0
  132. package/src/internal/array/compact.ts +12 -0
  133. package/src/internal/array/index-of.ts +70 -0
  134. package/src/internal/math/aggregate.ts +29 -0
  135. package/src/internal/string.ts +0 -2
  136. package/src/internal/value/compare.ts +2 -1
  137. package/src/internal/value/equal.ts +5 -0
  138. package/src/internal/value/get.ts +27 -5
  139. package/src/internal/value/has.ts +10 -10
  140. package/src/internal/value/misc.ts +24 -13
  141. package/src/logger.ts +11 -0
  142. package/src/models.ts +18 -0
  143. package/src/promise/index.ts +0 -6
  144. package/src/promise/models.ts +36 -0
  145. package/src/queue.ts +13 -1
  146. package/src/result/index.ts +0 -8
  147. package/src/result/match.ts +4 -4
  148. package/src/result/work/flow.ts +12 -36
  149. package/src/result/work/pipe.ts +11 -33
  150. package/src/sized/set.ts +4 -3
  151. package/src/value/collection.ts +1 -1
  152. package/src/value/merge.ts +88 -66
  153. package/src/value/shake.ts +3 -0
  154. package/src/value/smush.ts +3 -0
  155. package/src/value/transform.ts +10 -1
  156. package/src/value/unsmush.ts +2 -8
@@ -1,17 +1,20 @@
1
- import { ArrayOrPlainObject, NestedPartial } from "../models.mjs";
1
+ import { ArrayOrPlainObject, NestedPartial, PlainObject, UnionToIntersection } from "../models.mjs";
2
2
 
3
3
  //#region src/value/merge.d.ts
4
4
  /**
5
5
  * Options for assigning values
6
6
  */
7
7
  type AssignOptions = Omit<MergeOptions, 'assignValues'>;
8
- /**
9
- * Assign values from multiple arrays or objects to the first one
10
- * @param to Value to assign to
11
- * @param from Values to assign
12
- * @returns Assigned value
13
- */
14
- type Assigner<Model extends ArrayOrPlainObject = ArrayOrPlainObject> = (to: NestedPartial<Model>, from: NestedPartial<Model>[]) => Model;
8
+ type Assigner = {
9
+ /**
10
+ * Assign values from one or more objects to the first one
11
+ *
12
+ * @param to Value to assign to
13
+ * @param from Values to assign
14
+ * @returns Assigned value
15
+ */
16
+ <To extends PlainObject, From extends PlainObject[]>(to: To, from: [...From]): To & UnionToIntersection<From[number]>;
17
+ };
15
18
  /**
16
19
  * Options for merging values
17
20
  */
@@ -45,20 +48,24 @@ type MergeOptions = {
45
48
  */
46
49
  skipNullableInArrays?: boolean;
47
50
  };
51
+ type Merger = {
52
+ /**
53
+ * Merge multiple arrays or objects into a single one
54
+ *
55
+ * @param values Values to merge
56
+ * @returns Merged value
57
+ */
58
+ <Values extends ArrayOrPlainObject[]>(values: NestedPartial<Values[number]>[]): UnionToIntersection<Values[number]>;
59
+ };
48
60
  /**
49
- * Merge multiple arrays or objects into a single one
50
- * @param values Values to merge
51
- * @returns Merged value
52
- */
53
- type Merger<Model extends ArrayOrPlainObject = ArrayOrPlainObject> = (values: NestedPartial<Model>[]) => Model;
54
- /**
55
- * Assign values from multiple arrays or objects to the first one
61
+ * Assign values from one or more objects to the first one
62
+ *
56
63
  * @param to Value to assign to
57
64
  * @param from Values to assign
58
65
  * @param options Assigning options
59
66
  * @returns Assigned value
60
67
  */
61
- declare function assign<Model extends ArrayOrPlainObject>(to: NestedPartial<Model>, from: NestedPartial<Model>[], options?: AssignOptions): Model;
68
+ declare function assign<To extends PlainObject, From extends PlainObject[]>(to: To, from: [...From], options?: AssignOptions): To & UnionToIntersection<From[number]>;
62
69
  declare namespace assign {
63
70
  var initialize: typeof initializeAssigner;
64
71
  }
@@ -66,32 +73,28 @@ declare namespace assign {
66
73
  * Create an assigner with predefined options
67
74
  *
68
75
  * Available as `initializeAssigner` and `assign.initialize`
76
+ *
69
77
  * @param options Assigning options
70
78
  * @returns Assigner function
71
79
  */
72
- declare function initializeAssigner<Model extends ArrayOrPlainObject>(options?: AssignOptions): Assigner<Model>;
80
+ declare function initializeAssigner(options?: AssignOptions): Assigner;
73
81
  /**
74
82
  * Create a merger with predefined options
75
83
  *
76
84
  * Available as `initializeMerger` and `merge.initialize`
85
+ *
77
86
  * @param options Merging options
78
87
  * @returns Merger function
79
88
  */
80
89
  declare function initializeMerger(options?: MergeOptions): Merger;
81
90
  /**
82
91
  * Merge multiple arrays or objects into a single one
92
+ *
83
93
  * @param values Values to merge
84
94
  * @param options Merging options
85
95
  * @returns Merged value
86
96
  */
87
- declare function merge<Model extends ArrayOrPlainObject>(values: NestedPartial<Model>[], options?: MergeOptions): Model;
88
- /**
89
- * Merge multiple arrays or objects into a single one
90
- * @param values Values to merge
91
- * @param options Merging options
92
- * @returns Merged value
93
- */
94
- declare function merge(values: NestedPartial<ArrayOrPlainObject>[], options?: MergeOptions): ArrayOrPlainObject;
97
+ declare function merge<Values extends ArrayOrPlainObject[]>(values: [...Values], options?: MergeOptions): UnionToIntersection<Values[number]>;
95
98
  declare namespace merge {
96
99
  var initialize: typeof initializeMerger;
97
100
  }
@@ -1,8 +1,8 @@
1
1
  import { isArrayOrPlainObject } from "../internal/is.mjs";
2
- import { join } from "../internal/string.mjs";
3
2
  //#region src/value/merge.ts
4
3
  /**
5
- * Assign values from multiple arrays or objects to the first one
4
+ * Assign values from one or more objects to the first one
5
+ *
6
6
  * @param to Value to assign to
7
7
  * @param from Values to assign
8
8
  * @param options Assigning options
@@ -11,7 +11,7 @@ import { join } from "../internal/string.mjs";
11
11
  function assign(to, from, options) {
12
12
  const actual = getMergeOptions(options);
13
13
  actual.assignValues = true;
14
- return mergeValues([to, ...from], actual, true);
14
+ return mergeValues([to, ...from], actual);
15
15
  }
16
16
  assign.initialize = initializeAssigner;
17
17
  function getMergeOptions(options) {
@@ -32,59 +32,70 @@ function getReplaceableObjects(value) {
32
32
  const items = (Array.isArray(value) ? value : [value]).filter((item) => typeof item === "string" || item instanceof RegExp);
33
33
  if (items.length > 0) return (name) => items.some((item) => typeof item === "string" ? item === name : item.test(name));
34
34
  }
35
- function handleMerge(values, options) {
36
- return !Array.isArray(values) || values.length === 0 ? {} : mergeValues(values, options, true);
37
- }
38
35
  /**
39
36
  * Create an assigner with predefined options
40
37
  *
41
38
  * Available as `initializeAssigner` and `assign.initialize`
39
+ *
42
40
  * @param options Assigning options
43
41
  * @returns Assigner function
44
42
  */
45
43
  function initializeAssigner(options) {
46
44
  const actual = getMergeOptions(options);
47
45
  actual.assignValues = true;
48
- return ((to, from) => mergeValues([to, ...from], actual, true));
46
+ return ((to, from) => mergeValues([to, ...from], actual));
49
47
  }
50
48
  /**
51
49
  * Create a merger with predefined options
52
50
  *
53
51
  * Available as `initializeMerger` and `merge.initialize`
52
+ *
54
53
  * @param options Merging options
55
54
  * @returns Merger function
56
55
  */
57
56
  function initializeMerger(options) {
58
57
  const actual = getMergeOptions(options);
59
- return (values) => handleMerge(values, actual);
58
+ return ((values) => mergeValues(values, actual));
60
59
  }
60
+ /**
61
+ * Merge multiple arrays or objects into a single one
62
+ *
63
+ * @param values Values to merge
64
+ * @param options Merging options
65
+ * @returns Merged value
66
+ */
61
67
  function merge(values, options) {
62
- return handleMerge(values, getMergeOptions(options));
68
+ return mergeValues(values, getMergeOptions(options));
63
69
  }
64
70
  merge.initialize = initializeMerger;
65
- function mergeObjects(values, options, prefix) {
71
+ function mergeObjects(values, options, destination, prefix) {
66
72
  const { length } = values;
67
- const isArray = values.every(Array.isArray);
68
- const merged = options.assignValues ? values[0] : isArray ? [] : {};
69
- for (let outerIndex = 0; outerIndex < length; outerIndex += 1) {
73
+ const isArray = Array.isArray(destination ?? values[0]);
74
+ const merged = destination ?? (isArray ? [] : {});
75
+ const offset = destination == null ? 0 : 1;
76
+ for (let outerIndex = offset; outerIndex < length; outerIndex += 1) {
70
77
  const item = values[outerIndex];
71
78
  const keys = Object.keys(item);
72
79
  const size = keys.length;
73
80
  for (let innerIndex = 0; innerIndex < size; innerIndex += 1) {
74
81
  const key = keys[innerIndex];
75
- const full = join([prefix, key], ".");
76
82
  const next = item[key];
77
83
  const previous = merged[key];
78
84
  if (next == null && (options.skipNullableAny || isArray && options.skipNullableInArrays)) continue;
79
- if (isArrayOrPlainObject(next) && isArrayOrPlainObject(previous) && !(options.replaceableObjects?.(full) ?? false)) merged[key] = mergeValues([previous, next], options, false, full);
85
+ const full = options.replaceableObjects == null ? void 0 : prefix == null ? key : `${prefix}.${key}`;
86
+ if (isArrayOrPlainObject(next) && isArrayOrPlainObject(previous) && !(options.replaceableObjects?.(full) ?? false)) merged[key] = mergeObjects([previous, next], options, destination == null ? void 0 : merged[key], full);
80
87
  else merged[key] = next;
81
88
  }
82
89
  }
83
90
  return merged;
84
91
  }
85
- function mergeValues(values, options, validate, prefix) {
86
- const actual = validate ? values.filter(isArrayOrPlainObject) : values;
87
- return actual.length > 1 ? mergeObjects(actual, options, prefix) : actual[0] ?? {};
92
+ function mergeValues(values, options, prefix) {
93
+ if (!Array.isArray(values)) return {};
94
+ const actual = values.filter(isArrayOrPlainObject);
95
+ if (actual.length === 0) return {};
96
+ if (options.assignValues && actual.length === 2 && !Array.isArray(actual[0]) && Object.keys(actual[0]).length === 0) return Object.assign(actual[0], actual[1]);
97
+ if (actual.length > 1) return mergeObjects(actual, options, options.assignValues ? actual[0] : void 0, prefix);
98
+ return options.assignValues ? actual[0] : Array.isArray(actual[0]) ? actual[0].slice() : { ...actual[0] };
88
99
  }
89
100
  //#endregion
90
101
  export { assign, initializeAssigner, initializeMerger, merge };
@@ -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
  };
@@ -19,7 +28,7 @@ declare function initializeTransformer<Value extends PlainObject>(transform: Tra
19
28
  *
20
29
  * Available as `initializeTransformer` and `transform.initialize`
21
30
  * @param transformers Keyed transformer functions
22
- * @return Transformer
31
+ * @returns Transformer
23
32
  */
24
33
  declare function initializeTransformer<Value extends PlainObject>(transformers: TransformCallbacks<Value>): Transformer<Value>;
25
34
  /**
@@ -1,4 +1,4 @@
1
- import { PlainObject, Simplify } from "../models.mjs";
1
+ import { PlainObject, Simplify, UnionToIntersection } from "../models.mjs";
2
2
 
3
3
  //#region src/value/unsmush.d.ts
4
4
  /**
@@ -6,9 +6,8 @@ import { PlainObject, Simplify } from "../models.mjs";
6
6
  */
7
7
  type KeysOfUnion<ObjectType> = keyof UnionToIntersection<ObjectType extends unknown ? Record<keyof ObjectType, never> : never>;
8
8
  /**
9
- * Thanks, type-fest!
9
+ * An unsmushed object, with all dot notation keys turned into nested keys
10
10
  */
11
- type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
12
11
  type Unsmushed<Value extends PlainObject> = Simplify<Omit<{ [UnionKey in KeysOfUnion<Value>]: Value[UnionKey] }, `${string}.${string}`>>;
13
12
  /**
14
13
  * 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.186.0",
4
4
  "description": "Atomic utilities for making your JavaScript better.",
5
5
  "keywords": [
6
6
  "helper",
@@ -253,13 +253,13 @@
253
253
  "watch": "npx vite build --watch"
254
254
  },
255
255
  "devDependencies": {
256
- "@oxlint/plugins": "^1.61",
256
+ "@oxlint/plugins": "^1.63",
257
257
  "@types/node": "^25.6",
258
258
  "@vitest/coverage-istanbul": "^4.1",
259
- "eslint": "^10.2",
259
+ "eslint": "^10.3",
260
260
  "jsdom": "^29.1",
261
- "tsdown": "^0.21",
262
- "typescript": "^5.9",
261
+ "tsdown": "^0.22",
262
+ "typescript": "^6",
263
263
  "vite": "npm:@voidzero-dev/vite-plus-core@latest",
264
264
  "vite-plus": "latest",
265
265
  "vitest": "npm:@voidzero-dev/vite-plus-test@latest"
@@ -1,12 +1,24 @@
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
8
+ *
6
9
  * @param first First array
7
10
  * @param second Second array
8
11
  * @param callback Callback to get an item's value for comparison
9
12
  * @returns Unique values from the first array
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * difference(
17
+ * [{id: 1}, {id: 2}, {id: 3}],
18
+ * [{id: 2}, {id: 4}],
19
+ * item => item.id,
20
+ * ); // => [{id: 1}, {id: 3}]
21
+ * ```
10
22
  */
11
23
  export function difference<First, Second>(
12
24
  first: First[],
@@ -16,10 +28,20 @@ export function difference<First, Second>(
16
28
 
17
29
  /**
18
30
  * Get the items from the first array that are not in the second array
31
+ *
19
32
  * @param first First array
20
33
  * @param second Second array
21
34
  * @param key Key to get an item's value for comparison
22
35
  * @returns Unique values from the first array
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * difference(
40
+ * [{id: 1}, {id: 2}, {id: 3}],
41
+ * [{id: 2}, {id: 4}],
42
+ * 'id',
43
+ * ); // => [{id: 1}, {id: 3}]
44
+ * ```
23
45
  */
24
46
  export function difference<
25
47
  First extends PlainObject,
@@ -29,12 +51,23 @@ export function difference<
29
51
 
30
52
  /**
31
53
  * Get the items from the first array that are not in the second array
54
+ *
32
55
  * @param first First array
33
56
  * @param second Second array
34
57
  * @returns Unique values from the first array
58
+ *
59
+ * @example
60
+ * ```typescript
61
+ * difference(
62
+ * [1, 2, 3],
63
+ * [2, 4],
64
+ * ); // => [1, 3]
65
+ * ```
35
66
  */
36
67
  export function difference<First, Second>(first: First[], second: Second[]): First[];
37
68
 
38
69
  export function difference(first: unknown[], second: unknown[], key?: unknown): unknown[] {
39
70
  return compareSets(COMPARE_SETS_DIFFERENCE, first, second, key);
40
71
  }
72
+
73
+ // #endregion
@@ -5,10 +5,20 @@ import type {PlainObject} from '../models';
5
5
 
6
6
  /**
7
7
  * Does an item with a specific value exist in the array?
8
+ *
8
9
  * @param array Array to search in
9
10
  * @param callback Callback to get an item's value for matching
10
11
  * @param value Value to match against
11
12
  * @returns `true` if the item exists in the array, otherwise `false`
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * exists(
17
+ * [{id: 1}, {id: 2}, {id: 3}],
18
+ * item => item.id,
19
+ * 2,
20
+ * ); // => true
21
+ * ```
12
22
  */
13
23
  export function exists<
14
24
  Item,
@@ -17,10 +27,20 @@ export function exists<
17
27
 
18
28
  /**
19
29
  * Does an item with a specific value exist in the array?
30
+ *
20
31
  * @param array Array to search in
21
32
  * @param key Key to get an item's value for matching
22
33
  * @param value Value to match against
23
34
  * @returns `true` if the item exists in the array, otherwise `false`
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * exists(
39
+ * [{id: 1}, {id: 2}, {id: 3}],
40
+ * 'id',
41
+ * 2,
42
+ * ); // => true
43
+ * ```
24
44
  */
25
45
  export function exists<Item extends PlainObject, ItemKey extends keyof Item>(
26
46
  array: Item[],
@@ -30,9 +50,18 @@ export function exists<Item extends PlainObject, ItemKey extends keyof Item>(
30
50
 
31
51
  /**
32
52
  * Does an item in the array match the filter?
53
+ *
33
54
  * @param array Array to search in
34
55
  * @param filter Filter callback to match items
35
56
  * @returns `true` if a matching item exists, otherwise `false`
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * exists(
61
+ * [{id: 1}, {id: 2}, {id: 3}],
62
+ * item => item.id === 2,
63
+ * ); // => true
64
+ * ```
36
65
  */
37
66
  export function exists<Item>(
38
67
  array: Item[],
@@ -41,9 +70,15 @@ export function exists<Item>(
41
70
 
42
71
  /**
43
72
  * Does the item exist in the array?
73
+ *
44
74
  * @param array Array to search in
45
75
  * @param item Item to search for
46
76
  * @returns `true` if the item exists in the array, otherwise `false`
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * exists([1, 2, 3], 2); // => true
81
+ * ```
47
82
  */
48
83
  export function exists<Item>(array: Item[], item: Item): boolean;
49
84
 
@@ -4,13 +4,23 @@ import type {PlainObject} from '../models';
4
4
  // #region Functions
5
5
 
6
6
  /**
7
- * Get a filtered array of items that do not match the filter
7
+ * Get a filtered array of items that do not match the value
8
8
  *
9
9
  * Available as `exclude` and `filter.remove`
10
+ *
10
11
  * @param array Array to search in
11
12
  * @param callback Callback to get an item's value for matching
12
13
  * @param value Value to match against
13
14
  * @returns Filtered array of items that do not match the filter
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * exclude(
19
+ * [{id: 1}, {id: 2}, {id: 3}],
20
+ * item => item.id,
21
+ * 2,
22
+ * ); // => [{id: 1}, {id: 3}]
23
+ * ```
14
24
  */
15
25
  export function exclude<
16
26
  Item,
@@ -18,13 +28,23 @@ export function exclude<
18
28
  >(array: Item[], callback: Callback, value: ReturnType<Callback>): unknown[];
19
29
 
20
30
  /**
21
- * Get a filtered array of items that do not match the filter
31
+ * Get a filtered array of items that do not match the value
22
32
  *
23
33
  * Available as `exclude` and `filter.remove`
34
+ *
24
35
  * @param array Array to search in
25
36
  * @param key Key to get an item's value for matching
26
37
  * @param value Value to match against
27
38
  * @returns Filtered array of items that do not match the filter
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * exclude(
43
+ * [{id: 1}, {id: 2}, {id: 3}],
44
+ * 'id',
45
+ * 2,
46
+ * ); // => [{id: 1}, {id: 3}]
47
+ * ```
28
48
  */
29
49
  export function exclude<Item extends PlainObject, ItemKey extends keyof Item>(
30
50
  array: Item[],
@@ -36,9 +56,18 @@ export function exclude<Item extends PlainObject, ItemKey extends keyof Item>(
36
56
  * Get a filtered array of items that do not match the filter
37
57
  *
38
58
  * Available as `exclude` and `filter.remove`
59
+ *
39
60
  * @param array Array to search in
40
61
  * @param filter Filter callback to match items
41
62
  * @returns Filtered array of items that do not match the filter
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * exclude(
67
+ * [{id: 1}, {id: 2}, {id: 3}],
68
+ * item => item.id === 2,
69
+ * ); // => [{id: 1}, {id: 3}]
70
+ * ```
42
71
  */
43
72
  export function exclude<Item>(
44
73
  array: Item[],
@@ -49,9 +78,15 @@ export function exclude<Item>(
49
78
  * Get a filtered array of items that do not match the given item
50
79
  *
51
80
  * Available as `exclude` and `filter.remove`
81
+ *
52
82
  * @param array Array to search in
53
83
  * @param item Item to match against
54
84
  * @returns Filtered array of items that do not match the given item
85
+ *
86
+ * @example
87
+ * ```typescript
88
+ * exclude([1, 2, 3], 2); // => [1, 3]
89
+ * ```
55
90
  */
56
91
  export function exclude<Item>(array: Item[], item: Item): unknown[];
57
92
 
@@ -61,10 +96,20 @@ export function exclude(array: unknown[], ...parameters: unknown[]): unknown[] {
61
96
 
62
97
  /**
63
98
  * Get a filtered array of items
99
+ *
64
100
  * @param array Array to search in
65
101
  * @param callback Callback to get an item's value for matching
66
102
  * @param value Value to match against
67
103
  * @returns Filtered array of items
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * filter(
108
+ * [{id: 1}, {id: 2}, {id: 3}],
109
+ * item => item.id,
110
+ * 2,
111
+ * ); // => [{id: 2}]
112
+ * ```
68
113
  */
69
114
  export function filter<
70
115
  Item,
@@ -73,10 +118,20 @@ export function filter<
73
118
 
74
119
  /**
75
120
  * Get a filtered array of items
121
+ *
76
122
  * @param array Array to search in
77
123
  * @param key Key to get an item's value for matching
78
124
  * @param value Value to match against
79
125
  * @returns Filtered array of items
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * filter(
130
+ * [{id: 1}, {id: 2}, {id: 3}],
131
+ * 'id',
132
+ * 2,
133
+ * ); // => [{id: 2}]
134
+ * ```
80
135
  */
81
136
  export function filter<Item extends PlainObject, ItemKey extends keyof Item>(
82
137
  array: Item[],
@@ -86,9 +141,18 @@ export function filter<Item extends PlainObject, ItemKey extends keyof Item>(
86
141
 
87
142
  /**
88
143
  * Get a filtered array of items matching the filter
144
+ *
89
145
  * @param array Array to search in
90
146
  * @param filter Filter callback to match items
91
147
  * @returns Filtered array of items
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * filter(
152
+ * [{id: 1}, {id: 2}, {id: 3}],
153
+ * item => item.id === 2,
154
+ * ); // => [{id: 2}]
155
+ * ```
92
156
  */
93
157
  export function filter<Item>(
94
158
  array: Item[],
@@ -97,9 +161,15 @@ export function filter<Item>(
97
161
 
98
162
  /**
99
163
  * Get a filtered array of items matching the given item
164
+ *
100
165
  * @param array Array to search in
101
166
  * @param item Item to match against
102
167
  * @returns Filtered array of items
168
+ *
169
+ * @example
170
+ * ```typescript
171
+ * filter([1, 2, 3], 2); // => [2]
172
+ * ```
103
173
  */
104
174
  export function filter<Item>(array: Item[], item: Item): Item[];
105
175