@oscarpalmer/atoms 0.179.1 → 0.181.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 (124) hide show
  1. package/dist/array/filter.d.mts +36 -28
  2. package/dist/array/filter.mjs +5 -5
  3. package/dist/array/find.d.mts +42 -1
  4. package/dist/array/find.mjs +5 -1
  5. package/dist/array/first.d.mts +13 -5
  6. package/dist/array/first.mjs +1 -1
  7. package/dist/array/get.mjs +2 -2
  8. package/dist/array/group-by.d.mts +13 -1
  9. package/dist/array/group-by.mjs +1 -1
  10. package/dist/array/index.d.mts +3 -3
  11. package/dist/array/index.mjs +3 -3
  12. package/dist/array/last.d.mts +9 -1
  13. package/dist/array/last.mjs +1 -1
  14. package/dist/array/move.d.mts +9 -1
  15. package/dist/array/move.mjs +3 -1
  16. package/dist/array/reverse.d.mts +5 -0
  17. package/dist/array/reverse.mjs +5 -0
  18. package/dist/array/select.d.mts +2 -2
  19. package/dist/array/sort.d.mts +23 -9
  20. package/dist/array/sort.mjs +22 -22
  21. package/dist/array/swap.d.mts +2 -0
  22. package/dist/array/swap.mjs +2 -0
  23. package/dist/array/to-map.d.mts +13 -1
  24. package/dist/array/to-map.mjs +1 -1
  25. package/dist/array/to-record.d.mts +13 -1
  26. package/dist/array/to-record.mjs +1 -1
  27. package/dist/function/assert.d.mts +9 -1
  28. package/dist/function/assert.mjs +9 -1
  29. package/dist/function/limit.d.mts +5 -1
  30. package/dist/function/limit.mjs +5 -1
  31. package/dist/function/once.d.mts +3 -1
  32. package/dist/function/once.mjs +3 -1
  33. package/dist/function/retry.d.mts +4 -0
  34. package/dist/function/retry.mjs +2 -0
  35. package/dist/function/work.d.mts +49 -1
  36. package/dist/function/work.mjs +1 -1
  37. package/dist/index.d.mts +540 -266
  38. package/dist/index.mjs +272 -178
  39. package/dist/internal/array/find.d.mts +4 -3
  40. package/dist/internal/array/find.mjs +5 -2
  41. package/dist/internal/array/index-of.d.mts +42 -1
  42. package/dist/internal/array/index-of.mjs +5 -1
  43. package/dist/internal/function/timer.mjs +3 -1
  44. package/dist/internal/math/aggregate.mjs +2 -2
  45. package/dist/internal/result.mjs +2 -2
  46. package/dist/internal/string.d.mts +5 -3
  47. package/dist/internal/string.mjs +14 -5
  48. package/dist/internal/value/compare.d.mts +13 -9
  49. package/dist/internal/value/compare.mjs +13 -9
  50. package/dist/internal/value/equal.d.mts +29 -15
  51. package/dist/internal/value/equal.mjs +43 -37
  52. package/dist/internal/value/handlers.d.mts +4 -4
  53. package/dist/internal/value/handlers.mjs +21 -13
  54. package/dist/internal/value/has.d.mts +9 -8
  55. package/dist/internal/value/has.mjs +3 -3
  56. package/dist/internal/value/misc.d.mts +4 -8
  57. package/dist/internal/value/misc.mjs +6 -17
  58. package/dist/promise/index.d.mts +11 -1
  59. package/dist/promise/index.mjs +1 -1
  60. package/dist/result/index.d.mts +9 -1
  61. package/dist/result/index.mjs +1 -1
  62. package/dist/result/match.d.mts +5 -1
  63. package/dist/result/match.mjs +1 -1
  64. package/dist/result/misc.d.mts +3 -3
  65. package/dist/result/work/flow.d.mts +49 -1
  66. package/dist/result/work/flow.mjs +1 -1
  67. package/dist/result/work/pipe.d.mts +67 -155
  68. package/dist/result/work/pipe.mjs +3 -3
  69. package/dist/string/fuzzy.d.mts +11 -1
  70. package/dist/string/fuzzy.mjs +22 -6
  71. package/dist/string/template.d.mts +3 -1
  72. package/dist/string/template.mjs +3 -1
  73. package/dist/value/clone.d.mts +13 -9
  74. package/dist/value/clone.mjs +21 -17
  75. package/dist/value/index.d.mts +2 -1
  76. package/dist/value/index.mjs +2 -1
  77. package/dist/value/merge.d.mts +22 -7
  78. package/dist/value/merge.mjs +10 -6
  79. package/dist/value/shake.d.mts +7 -0
  80. package/dist/value/shake.mjs +16 -0
  81. package/package.json +2 -2
  82. package/plugin/helpers.js +2 -2
  83. package/src/array/exists.ts +1 -1
  84. package/src/array/filter.ts +44 -36
  85. package/src/array/find.ts +58 -0
  86. package/src/array/first.ts +18 -9
  87. package/src/array/get.ts +2 -2
  88. package/src/array/group-by.ts +22 -10
  89. package/src/array/last.ts +17 -5
  90. package/src/array/move.ts +18 -5
  91. package/src/array/reverse.ts +5 -0
  92. package/src/array/select.ts +2 -2
  93. package/src/array/sort.ts +110 -86
  94. package/src/array/swap.ts +2 -0
  95. package/src/array/to-map.ts +22 -10
  96. package/src/array/to-record.ts +22 -10
  97. package/src/function/assert.ts +12 -4
  98. package/src/function/limit.ts +6 -2
  99. package/src/function/once.ts +3 -1
  100. package/src/function/retry.ts +8 -2
  101. package/src/function/work.ts +92 -26
  102. package/src/internal/array/find.ts +24 -4
  103. package/src/internal/array/index-of.ts +59 -1
  104. package/src/internal/function/timer.ts +4 -2
  105. package/src/internal/math/aggregate.ts +2 -2
  106. package/src/internal/result.ts +6 -3
  107. package/src/internal/string.ts +28 -8
  108. package/src/internal/value/compare.ts +14 -11
  109. package/src/internal/value/equal.ts +80 -68
  110. package/src/internal/value/handlers.ts +21 -13
  111. package/src/internal/value/has.ts +16 -16
  112. package/src/internal/value/misc.ts +10 -8
  113. package/src/promise/index.ts +14 -4
  114. package/src/result/index.ts +15 -5
  115. package/src/result/match.ts +7 -3
  116. package/src/result/misc.ts +3 -3
  117. package/src/result/work/flow.ts +68 -13
  118. package/src/result/work/pipe.ts +97 -392
  119. package/src/string/fuzzy.ts +34 -8
  120. package/src/string/template.ts +3 -1
  121. package/src/value/clone.ts +25 -22
  122. package/src/value/index.ts +1 -0
  123. package/src/value/merge.ts +31 -13
  124. package/src/value/shake.ts +36 -0
@@ -2,67 +2,75 @@ import { PlainObject } from "../models.mjs";
2
2
 
3
3
  //#region src/array/filter.d.ts
4
4
  /**
5
- * Get a filtered array of items
5
+ * Get a filtered array of items that do not match the filter
6
+ *
7
+ * Available as `exclude` and `filter.remove`
6
8
  * @param array Array to search in
7
9
  * @param callback Callback to get an item's value for matching
8
10
  * @param value Value to match against
9
- * @returns Filtered array of items
11
+ * @returns Filtered array of items that do not match the filter
10
12
  */
11
- declare function filter<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
13
+ declare function exclude<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): unknown[];
12
14
  /**
13
- * Get a filtered array of items
15
+ * Get a filtered array of items that do not match the filter
16
+ *
17
+ * Available as `exclude` and `filter.remove`
14
18
  * @param array Array to search in
15
19
  * @param key Key to get an item's value for matching
16
20
  * @param value Value to match against
17
- * @returns Filtered array of items
21
+ * @returns Filtered array of items that do not match the filter
18
22
  */
19
- declare function filter<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
23
+ declare function exclude<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): unknown[];
20
24
  /**
21
- * Get a filtered array of items matching the filter
25
+ * Get a filtered array of items that do not match the filter
26
+ *
27
+ * Available as `exclude` and `filter.remove`
22
28
  * @param array Array to search in
23
29
  * @param filter Filter callback to match items
24
- * @returns Filtered array of items
30
+ * @returns Filtered array of items that do not match the filter
25
31
  */
26
- declare function filter<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item[];
32
+ declare function exclude<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): unknown[];
27
33
  /**
28
- * Get a filtered array of items matching the given item
34
+ * Get a filtered array of items that do not match the given item
35
+ *
36
+ * Available as `exclude` and `filter.remove`
29
37
  * @param array Array to search in
30
38
  * @param item Item to match against
31
- * @returns Filtered array of items
39
+ * @returns Filtered array of items that do not match the given item
32
40
  */
33
- declare function filter<Item>(array: Item[], item: Item): Item[];
34
- declare namespace filter {
35
- var remove: typeof removeFiltered;
36
- }
41
+ declare function exclude<Item>(array: Item[], item: Item): unknown[];
37
42
  /**
38
- * Get a filtered array of items that do not match the filter
43
+ * Get a filtered array of items
39
44
  * @param array Array to search in
40
45
  * @param callback Callback to get an item's value for matching
41
46
  * @param value Value to match against
42
- * @returns Filtered array of items that do not match the filter
47
+ * @returns Filtered array of items
43
48
  */
44
- declare function removeFiltered<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): unknown[];
49
+ declare function filter<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item[];
45
50
  /**
46
- * Get a filtered array of items that do not match the filter
51
+ * Get a filtered array of items
47
52
  * @param array Array to search in
48
53
  * @param key Key to get an item's value for matching
49
54
  * @param value Value to match against
50
- * @returns Filtered array of items that do not match the filter
55
+ * @returns Filtered array of items
51
56
  */
52
- declare function removeFiltered<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): unknown[];
57
+ declare function filter<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item[];
53
58
  /**
54
- * Get a filtered array of items that do not match the filter
59
+ * Get a filtered array of items matching the filter
55
60
  * @param array Array to search in
56
61
  * @param filter Filter callback to match items
57
- * @returns Filtered array of items that do not match the filter
62
+ * @returns Filtered array of items
58
63
  */
59
- declare function removeFiltered<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): unknown[];
64
+ declare function filter<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item[];
60
65
  /**
61
- * Get a filtered array of items that do not match the given item
66
+ * Get a filtered array of items matching the given item
62
67
  * @param array Array to search in
63
68
  * @param item Item to match against
64
- * @returns Filtered array of items that do not match the given item
69
+ * @returns Filtered array of items
65
70
  */
66
- declare function removeFiltered<Item>(array: Item[], item: Item): unknown[];
71
+ declare function filter<Item>(array: Item[], item: Item): Item[];
72
+ declare namespace filter {
73
+ var remove: typeof exclude;
74
+ }
67
75
  //#endregion
68
- export { filter };
76
+ export { exclude, filter };
@@ -1,11 +1,11 @@
1
1
  import { findValues } from "../internal/array/find.mjs";
2
2
  //#region src/array/filter.ts
3
+ function exclude(array, ...parameters) {
4
+ return findValues("all", array, parameters).notMatched;
5
+ }
3
6
  function filter(array, ...parameters) {
4
7
  return findValues("all", array, parameters).matched;
5
8
  }
6
- filter.remove = removeFiltered;
7
- function removeFiltered(array, ...parameters) {
8
- return findValues("all", array, parameters).notMatched;
9
- }
9
+ filter.remove = exclude;
10
10
  //#endregion
11
- export { filter };
11
+ export { exclude, filter };
@@ -31,5 +31,46 @@ declare function find<Item>(array: Item[], filter: (item: Item, index: number, a
31
31
  * @returns First item that matches the value, or `undefined` if no match is found
32
32
  */
33
33
  declare function find<Item>(array: Item[], value: Item): Item | undefined;
34
+ declare namespace find {
35
+ var last: typeof findLast;
36
+ }
37
+ /**
38
+ * Get the last item matching the given value
39
+ *
40
+ * Available as `findLast` and `find.last`
41
+ * @param array Array to search in
42
+ * @param callback Callback to get an item's value for matching
43
+ * @param value Value to match against
44
+ * @returns Last item that matches the value, or `undefined` if no match is found
45
+ */
46
+ declare function findLast<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], callback: Callback, value: ReturnType<Callback>): Item | undefined;
47
+ /**
48
+ * Get the last item matching the given value by key
49
+ *
50
+ * Available as `findLast` and `find.last`
51
+ * @param array Array to search in
52
+ * @param key Key to get an item's value for matching
53
+ * @param value Value to match against
54
+ * @returns Last item that matches the value, or `undefined` if no match is found
55
+ */
56
+ declare function findLast<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
57
+ /**
58
+ * Get the last item matching the filter
59
+ *
60
+ * Available as `findLast` and `find.last`
61
+ * @param array Array to search in
62
+ * @param filter Filter callback to match items
63
+ * @returns Last item that matches the filter, or `undefined` if no match is found
64
+ */
65
+ declare function findLast<Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean): Item | undefined;
66
+ /**
67
+ * Get the last item matching the given value
68
+ *
69
+ * Available as `findLast` and `find.last`
70
+ * @param array Array to search in
71
+ * @param value Value to match against
72
+ * @returns Last item that matches the value, or `undefined` if no match is found
73
+ */
74
+ declare function findLast<Item>(array: Item[], value: Item): Item | undefined;
34
75
  //#endregion
35
- export { find };
76
+ export { find, findLast };
@@ -3,5 +3,9 @@ import { FIND_VALUE_ITEM, findValue } from "../internal/array/find.mjs";
3
3
  function find(array, ...parameters) {
4
4
  return findValue(FIND_VALUE_ITEM, array, parameters, false);
5
5
  }
6
+ find.last = findLast;
7
+ function findLast(array, ...parameters) {
8
+ return findValue(FIND_VALUE_ITEM, array, parameters, true);
9
+ }
6
10
  //#endregion
7
- export { find };
11
+ export { find, findLast };
@@ -35,7 +35,9 @@ declare namespace first {
35
35
  export { _a as default };
36
36
  }
37
37
  /**
38
- * Get the first item matching the given value
38
+ * Get the first item matching the given value, or a default value if no match is found
39
+ *
40
+ * Available as `firstOrDefault` and `first.default`
39
41
  * @param array Array to search in
40
42
  * @param defaultValue Default value to return if no match is found
41
43
  * @param callback Callback to get an item's value for matching
@@ -44,7 +46,9 @@ declare namespace first {
44
46
  */
45
47
  declare function firstOrDefault<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType<Callback>): Item;
46
48
  /**
47
- * Get the first item matching the given value by key
49
+ * Get the first item matching the given value by key, or a default value if no match is found
50
+ *
51
+ * Available as `firstOrDefault` and `first.default`
48
52
  * @param array Array to search in
49
53
  * @param defaultValue Default value to return if no match is found
50
54
  * @param key Key to get an item's value for matching
@@ -53,7 +57,9 @@ declare function firstOrDefault<Item, Callback extends (item: Item, index: numbe
53
57
  */
54
58
  declare function firstOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item;
55
59
  /**
56
- * Get the first item matching the filter
60
+ * Get the first item matching the filter, or a default value if no match is found
61
+ *
62
+ * Available as `firstOrDefault` and `first.default`
57
63
  * @param array Array to search in
58
64
  * @param defaultValue Default value to return if no match is found
59
65
  * @param filter Filter callback to match items
@@ -61,11 +67,13 @@ declare function firstOrDefault<Item extends PlainObject, ItemKey extends keyof
61
67
  */
62
68
  declare function firstOrDefault<Item>(array: Item[], defaultValue: Item, filter: (item: Item, index: number, array: Item[]) => boolean): Item;
63
69
  /**
64
- * Get the first item from an array
70
+ * Get the first item from an array, or a default value if the array is empty
71
+ *
72
+ * Available as `firstOrDefault` and `first.default`
65
73
  * @param array Array to get from
66
74
  * @param defaultValue Default value to return if the array is empty
67
75
  * @return First item from the array, or the default value if the array is empty
68
76
  */
69
77
  declare function firstOrDefault<Item>(array: Item[], defaultValue: Item): Item;
70
78
  //#endregion
71
- export { first };
79
+ export { first, firstOrDefault };
@@ -8,4 +8,4 @@ function firstOrDefault(array, defaultValue, ...parameters) {
8
8
  return findAbsoluteValueOrDefault(array, parameters, defaultValue, true, false);
9
9
  }
10
10
  //#endregion
11
- export { first };
11
+ export { first, firstOrDefault };
@@ -1,9 +1,9 @@
1
- import { isPlainObject } from "../internal/is.mjs";
1
+ import { isNonPlainObject } from "../internal/is.mjs";
2
2
  //#region src/array/get.ts
3
3
  function getArray(value, indiced) {
4
4
  if (Array.isArray(value)) return value;
5
5
  if (value instanceof Map || value instanceof Set) return [...value.values()];
6
- if (!isPlainObject(value)) return [value];
6
+ if (isNonPlainObject(value)) return [value];
7
7
  if (indiced !== true) return Object.values(value);
8
8
  const keys = Object.keys(value);
9
9
  const { length } = keys;
@@ -70,6 +70,8 @@ declare namespace groupBy {
70
70
  }
71
71
  /**
72
72
  * Create a record from an array of items using a specific key and value, grouping values into arrays
73
+ *
74
+ * Available as `groupArraysBy` and `groupBy.arrays`
73
75
  * @param array Array to group
74
76
  * @param key Callback to get an item's grouping key
75
77
  * @param value Callback to get an item's value
@@ -78,6 +80,8 @@ declare namespace groupBy {
78
80
  declare function groupArraysBy<Item, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: KeyCallback, value: ValueCallback): Record<ReturnType<KeyCallback>, ReturnType<ValueCallback>[]>;
79
81
  /**
80
82
  * Create a record from an array of items using a specific key and value, grouping values into arrays
83
+ *
84
+ * Available as `groupArraysBy` and `groupBy.arrays`
81
85
  * @param array Array to group
82
86
  * @param key Callback to get an item's grouping key
83
87
  * @param value Key to use for value
@@ -86,6 +90,8 @@ declare function groupArraysBy<Item, KeyCallback extends (item: Item, index: num
86
90
  declare function groupArraysBy<Item extends PlainObject, KeyCallback extends (item: Item, index: number, array: Item[]) => Key, ItemValue extends keyof Item>(array: Item[], key: KeyCallback, value: ItemValue): Record<ReturnType<KeyCallback>, Item[ItemValue][]>;
87
91
  /**
88
92
  * Create a record from an array of items using a specific key and value, grouping values into arrays
93
+ *
94
+ * Available as `groupArraysBy` and `groupBy.arrays`
89
95
  * @param array Array to group
90
96
  * @param key Key to use for grouping
91
97
  * @param value Callback to get an item's value
@@ -94,6 +100,8 @@ declare function groupArraysBy<Item extends PlainObject, KeyCallback extends (it
94
100
  declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item, ValueCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], key: ItemKey, value: ValueCallback): Simplify<Record<KeyedValue<Item, ItemKey>, ReturnType<ValueCallback>[]>>;
95
101
  /**
96
102
  * Create a record from an array of items using a specific key and value, grouping values into arrays
103
+ *
104
+ * Available as `groupArraysBy` and `groupBy.arrays`
97
105
  * @param array Array to group
98
106
  * @param key Key to use for grouping
99
107
  * @param value Key to use for value
@@ -102,6 +110,8 @@ declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof I
102
110
  declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item, ItemValue extends keyof Item>(array: Item[], key: ItemKey, value: ItemValue): Simplify<Record<KeyedValue<Item, ItemKey>, Item[ItemValue][]>>;
103
111
  /**
104
112
  * Create a record from an array of items using a specific key, grouping items into arrays
113
+ *
114
+ * Available as `groupArraysBy` and `groupBy.arrays`
105
115
  * @param array Array to group
106
116
  * @param callback Callback to get an item's grouping key
107
117
  * @returns Record of keyed items
@@ -109,10 +119,12 @@ declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof I
109
119
  declare function groupArraysBy<Item, Callback extends (item: Item, index: number, array: Item[]) => Key>(array: Item[], callback: Callback): Record<ReturnType<Callback>, Item[]>;
110
120
  /**
111
121
  * Create a record from an array of items using a specific key, grouping items into arrays
122
+ *
123
+ * Available as `groupArraysBy` and `groupBy.arrays`
112
124
  * @param array Array to group
113
125
  * @param key Key to use for grouping
114
126
  * @returns Record of keyed items
115
127
  */
116
128
  declare function groupArraysBy<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey): Simplify<Record<KeyedValue<Item, ItemKey>, Item[]>>;
117
129
  //#endregion
118
- export { groupBy };
130
+ export { groupArraysBy, groupBy };
@@ -8,4 +8,4 @@ function groupArraysBy(array, first, second) {
8
8
  return groupValues(array, first, second, true);
9
9
  }
10
10
  //#endregion
11
- export { groupBy };
11
+ export { groupArraysBy, groupBy };
@@ -1,12 +1,12 @@
1
1
  import { difference } from "./difference.mjs";
2
2
  import { exists } from "./exists.mjs";
3
- import { find } from "./find.mjs";
3
+ import { find, findLast } from "./find.mjs";
4
4
  import { flatten } from "./flatten.mjs";
5
5
  import { range, times } from "./from.mjs";
6
6
  import { getArray } from "./get.mjs";
7
7
  import { chunk } from "../internal/array/chunk.mjs";
8
8
  import { compact } from "../internal/array/compact.mjs";
9
- import { indexOf } from "../internal/array/index-of.mjs";
9
+ import { indexOf, lastIndexOf } from "../internal/array/index-of.mjs";
10
10
  import { shuffle } from "../internal/array/shuffle.mjs";
11
11
  import { insert } from "./insert.mjs";
12
12
  import { intersection } from "./intersection.mjs";
@@ -23,4 +23,4 @@ import { toggle } from "./toggle.mjs";
23
23
  import { union } from "./union.mjs";
24
24
  import { unique } from "./unique.mjs";
25
25
  import { update } from "./update.mjs";
26
- export { ArrayPosition, chunk, compact, difference, drop, endsWithArray, exists, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, reverse, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
26
+ export { ArrayPosition, chunk, compact, difference, drop, endsWithArray, exists, find, findLast, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, lastIndexOf, partition, push, range, reverse, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
@@ -1,10 +1,10 @@
1
1
  import { chunk } from "../internal/array/chunk.mjs";
2
2
  import { compact } from "../internal/array/compact.mjs";
3
- import { indexOf } from "../internal/array/index-of.mjs";
3
+ import { indexOf, lastIndexOf } from "../internal/array/index-of.mjs";
4
4
  import { shuffle } from "../internal/array/shuffle.mjs";
5
5
  import { difference } from "./difference.mjs";
6
6
  import { exists } from "./exists.mjs";
7
- import { find } from "./find.mjs";
7
+ import { find, findLast } from "./find.mjs";
8
8
  import { flatten } from "./flatten.mjs";
9
9
  import { range, times } from "./from.mjs";
10
10
  import { getArray } from "./get.mjs";
@@ -23,4 +23,4 @@ import { toggle } from "./toggle.mjs";
23
23
  import { union } from "./union.mjs";
24
24
  import { unique } from "./unique.mjs";
25
25
  import { update } from "./update.mjs";
26
- export { chunk, compact, difference, drop, endsWithArray, exists, find, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, partition, push, range, reverse, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
26
+ export { chunk, compact, difference, drop, endsWithArray, exists, find, findLast, flatten, getArray, getArrayPosition, includesArray, indexOf, indexOfArray, insert, intersection, lastIndexOf, partition, push, range, reverse, select, shuffle, single, slice, splice, startsWithArray, take, times, toSet, toggle, union, unique, update };
@@ -36,6 +36,8 @@ declare namespace last {
36
36
  }
37
37
  /**
38
38
  * Get the last item matching the given value
39
+ *
40
+ * Available as `lastOrDefault` and `last.default`
39
41
  * @param array Array to search in
40
42
  * @param defaultValue Default value to return if no match is found
41
43
  * @param callback Callback to get an item's value for matching
@@ -45,6 +47,8 @@ declare namespace last {
45
47
  declare function lastOrDefault<Item, Callback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], defaultValue: Item, callback: Callback, value: ReturnType<Callback>): Item;
46
48
  /**
47
49
  * Get the last item matching the given value by key
50
+ *
51
+ * Available as `lastOrDefault` and `last.default`
48
52
  * @param array Array to search in
49
53
  * @param defaultValue Default value to return if no match is found
50
54
  * @param key Key to get an item's value for matching
@@ -54,6 +58,8 @@ declare function lastOrDefault<Item, Callback extends (item: Item, index: number
54
58
  declare function lastOrDefault<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], defaultValue: Item, key: ItemKey, value: Item[ItemKey]): Item;
55
59
  /**
56
60
  * Get the last item matching the filter
61
+ *
62
+ * Available as `lastOrDefault` and `last.default`
57
63
  * @param array Array to search in
58
64
  * @param defaultValue Default value to return if no match is found
59
65
  * @param filter Filter callback to match items
@@ -62,10 +68,12 @@ declare function lastOrDefault<Item extends PlainObject, ItemKey extends keyof I
62
68
  declare function lastOrDefault<Item>(array: Item[], defaultValue: Item, filter: (item: Item, index: number, array: Item[]) => boolean): Item;
63
69
  /**
64
70
  * Get the last item from an array
71
+ *
72
+ * Available as `lastOrDefault` and `last.default`
65
73
  * @param array Array to get from
66
74
  * @param defaultValue Default value to return if the array is empty
67
75
  * @return Last item from the array, or the default value if the array is empty
68
76
  */
69
77
  declare function lastOrDefault<Item>(array: Item[], defaultValue: Item): Item;
70
78
  //#endregion
71
- export { last };
79
+ export { last, lastOrDefault };
@@ -8,4 +8,4 @@ function lastOrDefault(array, defaultValue, ...parameters) {
8
8
  return findAbsoluteValueOrDefault(array, parameters, defaultValue, true, true);
9
9
  }
10
10
  //#endregion
11
- export { last };
11
+ export { last, lastOrDefault };
@@ -47,6 +47,8 @@ declare namespace move {
47
47
  * Move an item from one index to another within an array
48
48
  *
49
49
  * If the from index is out of bounds, the array will be returned unchanged
50
+ *
51
+ * Available as `moveIndices` and `move.indices`
50
52
  * @param array Array to move within
51
53
  * @param from Index to move from
52
54
  * @param to Index to move to
@@ -57,6 +59,8 @@ declare function moveIndices<Item>(array: Item[], from: number, to: number): Ite
57
59
  * Move an item _(or array of items)_ to an index within an array
58
60
  *
59
61
  * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
62
+ *
63
+ * Available as `moveToIndex` and `move.toIndex`
60
64
  * @param array Array to move within
61
65
  * @param value Item or items to move
62
66
  * @param index Index to move to
@@ -68,6 +72,8 @@ declare function moveToIndex<Item extends PlainObject, ItemKey extends keyof Ite
68
72
  * Move an item _(or array of items)_ to an index within an array
69
73
  *
70
74
  * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
75
+ *
76
+ * Available as `moveToIndex` and `move.toIndex`
71
77
  * @param array Array to move within
72
78
  * @param value Item or items to move
73
79
  * @param index Index to move to
@@ -79,6 +85,8 @@ declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: n
79
85
  * Move an item _(or array of items)_ to an index within an array
80
86
  *
81
87
  * If the value is not present in the array, or if the index is out of bounds, the array will be returned unchanged
88
+ *
89
+ * Available as `moveToIndex` and `move.toIndex`
82
90
  * @param array Array to move within
83
91
  * @param value Item or items to move
84
92
  * @param index Index to move to
@@ -86,4 +94,4 @@ declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: n
86
94
  */
87
95
  declare function moveToIndex<Item>(array: Item[], value: Item | Item[], index: number): Item[];
88
96
  //#endregion
89
- export { move };
97
+ export { move, moveIndices, moveToIndex };
@@ -29,6 +29,8 @@ move.toIndex = moveToIndex;
29
29
  * Move an item from one index to another within an array
30
30
  *
31
31
  * If the from index is out of bounds, the array will be returned unchanged
32
+ *
33
+ * Available as `moveIndices` and `move.indices`
32
34
  * @param array Array to move within
33
35
  * @param from Index to move from
34
36
  * @param to Index to move to
@@ -61,4 +63,4 @@ function moveToIndex(array, value, index, key) {
61
63
  return array;
62
64
  }
63
65
  //#endregion
64
- export { move };
66
+ export { move, moveIndices, moveToIndex };
@@ -1,4 +1,9 @@
1
1
  //#region src/array/reverse.d.ts
2
+ /**
3
+ * Reverse the order of items in an array
4
+ * @param array Array to reverse
5
+ * @returns Reversed array
6
+ */
2
7
  declare function reverse<Item>(array: Item[]): Item[];
3
8
  //#endregion
4
9
  export { reverse };
@@ -1,4 +1,9 @@
1
1
  //#region src/array/reverse.ts
2
+ /**
3
+ * Reverse the order of items in an array
4
+ * @param array Array to reverse
5
+ * @returns Reversed array
6
+ */
2
7
  function reverse(array) {
3
8
  if (!Array.isArray(array)) return [];
4
9
  const { length } = array;
@@ -76,7 +76,7 @@ declare function select<Item extends PlainObject, MapKey extends keyof Item>(arr
76
76
  * @param map Callback to map the matched items
77
77
  * @returns Filtered and mapped array of items
78
78
  */
79
- declare function select<Item, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], filter: Item, map: MapCallback): Array<ReturnType<MapCallback>>;
79
+ declare function select<Item, MapCallback extends (item: Item, index: number, array: Item[]) => unknown>(array: Item[], item: Item, map: MapCallback): Array<ReturnType<MapCallback>>;
80
80
  /**
81
81
  * Get a filtered and mapped array of items
82
82
  * @param array Array to search in
@@ -84,6 +84,6 @@ declare function select<Item, MapCallback extends (item: Item, index: number, ar
84
84
  * @param map Key to get an item's value for mapping
85
85
  * @returns Filtered and mapped array of items
86
86
  */
87
- declare function select<Item extends PlainObject, MapKey extends keyof Item>(array: Item[], filter: Item, map: MapKey): Array<Item[MapKey]>;
87
+ declare function select<Item extends PlainObject, MapKey extends keyof Item>(array: Item[], item: Item, map: MapKey): Array<Item[MapKey]>;
88
88
  //#endregion
89
89
  export { select };
@@ -92,54 +92,66 @@ type Sorter<Item> = {
92
92
  * Get the index for an item _(to be inserted into an array of items)_ based on sorters _(and an optional default direction)_
93
93
  *
94
94
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
95
+ *
96
+ * Available as `getSortedIndex` and `sort.index`
95
97
  * @param array Array to get the index from
96
98
  * @param item Item to get the index for
97
99
  * @param sorters Sorters to use to determine sorting
98
100
  * @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
99
101
  * @returns Index for item
100
102
  */
101
- declare function getIndex<Item>(array: Item[], item: Item, sorters: Array<ArraySorter<Item>>, descending?: boolean): number;
103
+ declare function getSortedIndex<Item>(array: Item[], item: Item, sorters: Array<ArraySorter<Item>>, descending?: boolean): number;
102
104
  /**
103
105
  * Get the index for an item _(to be inserted into an array of items)_ based on a sorter _(and an optional default direction)_
104
106
  *
105
107
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
108
+ *
109
+ * Available as `getSortedIndex` and `sort.index`
106
110
  * @param array Array to get the index from
107
111
  * @param item Item to get the index for
108
112
  * @param sorter Sorter to use to determine sorting
109
113
  * @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
110
114
  * @returns Index for item
111
115
  */
112
- declare function getIndex<Item>(array: Item[], item: Item, sorter: ArraySorter<Item>, descending?: boolean): number;
116
+ declare function getSortedIndex<Item>(array: Item[], item: Item, sorter: ArraySorter<Item>, descending?: boolean): number;
113
117
  /**
114
118
  * Get the index for an item _(to be inserted into an array of items)_ based on an optional default direction_
115
119
  *
116
120
  * _(If the array is not sorted, it will be treated as sorted, and the result may be inaccurate)_
121
+ *
122
+ * Available as `getSortedIndex` and `sort.index`
117
123
  * @param array Array to get the index from
118
124
  * @param item Item to get the index for
119
125
  * @param descending Sorted in descending order? _(defaults to `false`)_
120
126
  * @returns Index for item
121
127
  */
122
- declare function getIndex<Item>(array: Item[], item: Item, descending?: boolean): number;
128
+ declare function getSortedIndex<Item>(array: Item[], item: Item, descending?: boolean): number;
123
129
  /**
124
130
  * Initialize a sort handler with sorters _(and an optional default direction)_
131
+ *
132
+ * Available as `initializeSorter` and `sort.initialize`
125
133
  * @param sorters Sorters to use for sorting
126
134
  * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
127
135
  * @returns Sort handler
128
136
  */
129
- declare function initializeSort<Item>(sorters: Array<ArraySorter<Item>>, descending?: boolean): Sorter<Item>;
137
+ declare function initializeSorter<Item>(sorters: Array<ArraySorter<Item>>, descending?: boolean): Sorter<Item>;
130
138
  /**
131
139
  * Initialize a sort handler with a sorter _(and an optional default direction)_
140
+ *
141
+ * Available as `initializeSorter` and `sort.initialize`
132
142
  * @param sorter Sorter to use for sorting
133
143
  * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
134
144
  * @returns Sort handler
135
145
  */
136
- declare function initializeSort<Item>(sorter: ArraySorter<Item>, descending?: boolean): Sorter<Item>;
146
+ declare function initializeSorter<Item>(sorter: ArraySorter<Item>, descending?: boolean): Sorter<Item>;
137
147
  /**
138
148
  * Initialize a sort handler _(with an optional default direction)_
149
+ *
150
+ * Available as `initializeSorter` and `sort.initialize`
139
151
  * @param descending Sort in descending order? _(defaults to `false`)_
140
152
  * @returns Sort handler
141
153
  */
142
- declare function initializeSort<Item>(descending?: boolean): Sorter<Item>;
154
+ declare function initializeSorter<Item>(descending?: boolean): Sorter<Item>;
143
155
  /**
144
156
  * Is the array sorted according to the sorters _(and the optional default direction)_?
145
157
  * @param array Array to check
@@ -158,6 +170,8 @@ declare function isSorted<Item>(array: Item[], sorters: Array<ArraySorter<Item>>
158
170
  declare function isSorted<Item>(array: Item[], sorter: ArraySorter<Item>, descending?: boolean): boolean;
159
171
  /**
160
172
  * Is the array sorted?
173
+ *
174
+ * Available as `isSorted` and `sort.is`
161
175
  * @param array Array to check
162
176
  * @param descending Sorted in descending order? _(defaults to `false`)_
163
177
  * @returns `true` if sorted, otherwise `false`
@@ -187,11 +201,11 @@ declare function sort<Item>(array: Item[], sorter: ArraySorter<Item>, descending
187
201
  */
188
202
  declare function sort<Item>(array: Item[], descending?: boolean): Item[];
189
203
  declare namespace sort {
190
- var index: typeof getIndex;
191
- var initialize: typeof initializeSort;
204
+ var index: typeof getSortedIndex;
205
+ var initialize: typeof initializeSorter;
192
206
  var is: typeof isSorted;
193
207
  }
194
208
  declare const SORT_DIRECTION_ASCENDING: SortDirection;
195
209
  declare const SORT_DIRECTION_DESCENDING: SortDirection;
196
210
  //#endregion
197
- export { ArrayComparisonSorter, ArrayKeySorter, ArrayValueSorter, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SortDirection, Sorter, sort };
211
+ export { ArrayComparisonSorter, ArrayKeySorter, ArrayValueSorter, SORT_DIRECTION_ASCENDING, SORT_DIRECTION_DESCENDING, SortDirection, Sorter, getSortedIndex, initializeSorter, isSorted, sort };