@oscarpalmer/atoms 0.218.0 → 0.220.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 (54) hide show
  1. package/dist/array/filter.d.mts +38 -4
  2. package/dist/array/find.d.mts +34 -0
  3. package/dist/array/first.d.mts +40 -4
  4. package/dist/array/last.d.mts +46 -10
  5. package/dist/array/partition.d.mts +24 -8
  6. package/dist/array/reverse.d.mts +6 -0
  7. package/dist/array/reverse.mjs +6 -0
  8. package/dist/array/select.d.mts +97 -116
  9. package/dist/array/select.mjs +19 -15
  10. package/dist/array/single.d.mts +22 -0
  11. package/dist/array/single.mjs +1 -1
  12. package/dist/array/sort.d.mts +54 -0
  13. package/dist/color/space/hex.d.mts +8 -0
  14. package/dist/color/space/hex.mjs +8 -0
  15. package/dist/index.d.mts +764 -189
  16. package/dist/index.mjs +508 -207
  17. package/dist/internal/array/callbacks.mjs +1 -1
  18. package/dist/internal/array/find.d.mts +3 -3
  19. package/dist/internal/array/find.mjs +71 -52
  20. package/dist/internal/array/shuffle.d.mts +5 -0
  21. package/dist/internal/array/shuffle.mjs +5 -0
  22. package/dist/internal/math/aggregate.d.mts +69 -21
  23. package/dist/internal/math/misc.d.mts +14 -0
  24. package/dist/internal/math/misc.mjs +14 -0
  25. package/dist/internal/number.d.mts +18 -0
  26. package/dist/internal/number.mjs +18 -0
  27. package/dist/internal/string/case.d.mts +63 -0
  28. package/dist/internal/string/case.mjs +63 -0
  29. package/dist/internal/string/misc.d.mts +20 -0
  30. package/dist/internal/string/misc.mjs +20 -0
  31. package/dist/logger.d.mts +12 -0
  32. package/dist/logger.mjs +12 -0
  33. package/dist/math.d.mts +90 -0
  34. package/dist/math.mjs +7 -0
  35. package/dist/models/array/array.find.model.d.mts +26 -0
  36. package/dist/models/array/array.misc.model.d.mts +2 -4
  37. package/dist/models/index.d.mts +1 -1
  38. package/dist/models/string/string.fuzzy.model.d.mts +46 -18
  39. package/dist/models/string/string.fuzzy.model.mjs +3 -1
  40. package/dist/models/value/value.merge.model.d.mts +3 -3
  41. package/dist/promise/misc.d.mts +6 -0
  42. package/dist/promise/misc.mjs +6 -0
  43. package/dist/promise/timed.d.mts +3 -0
  44. package/dist/promise/timed.mjs +3 -0
  45. package/dist/queue.d.mts +0 -1
  46. package/dist/queue.mjs +1 -1
  47. package/dist/string/fuzzy.d.mts +3 -3
  48. package/dist/string/fuzzy.mjs +171 -97
  49. package/dist/string/index.d.mts +15 -1
  50. package/dist/string/index.mjs +15 -1
  51. package/dist/string/match.d.mts +24 -0
  52. package/dist/string/match.mjs +24 -0
  53. package/dist/string/template.d.mts +4 -0
  54. package/package.json +1 -1
@@ -1,190 +1,171 @@
1
- import { PlainObject } from "../models/index.mjs";
2
- import { ArrayMapKeyOrCallback, ArrayMapped, ArrayObjectKeysOf } from "../models/array/array.misc.model.mjs";
1
+ import { ArrayFlattened } from "../models/array/array.misc.model.mjs";
3
2
  //#region src/array/select.d.ts
4
3
  /**
5
- * Get a filtered and mapped array of items
4
+ * Get a narrowed, mapped, and flattened array of items
6
5
  *
7
- * @param array Array to search in
8
- * @param filterCallback Callback to get an item's value for matching
9
- * @param filterValue Value to match against
10
- * @param map Callback or key to map the matched items
11
- * @returns Filtered and mapped array of items
6
+ * _Available as `filterAndFlatMap`, `filterAndMap.flat`, and `select.flat`_
12
7
  *
13
- * @example
14
- * ```typescript
15
- * select(
16
- * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
17
- * item => item.id,
18
- * 2,
19
- * item => item.name,
20
- * ); // => ['Bob']
21
- * ```
22
- */
23
- export declare function filterAndMap<Item, FilterCallback extends (item: Item, index: number, array: Item[]) => unknown, Map extends ArrayMapKeyOrCallback<Item>>(array: Item[], filterCallback: FilterCallback, filterValue: ReturnType<FilterCallback>, map: Map): Array<ArrayMapped<Item, Map>>;
24
- /**
25
- * Get a filtered and mapped array of items
26
- *
27
- * @param array Array to search in
28
- * @param filterKey Key to get an item's value for matching
29
- * @param filterValue Value to match against
30
- * @param map Callback or key to map the matched items
31
- * @returns Filtered and mapped array of items
8
+ * @param array Array to select from
9
+ * @param filter Type guard to filter and narrow down the items
10
+ * @param mapper Callback to map and flatten the narrowed items
11
+ * @returns Narrowed, mapped, and flattened array of items
32
12
  *
33
13
  * @example
34
14
  * ```typescript
35
- * select(
36
- * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
37
- * 'id',
38
- * 2,
39
- * 'name',
40
- * ); // => ['Bob']
15
+ * filterAndFlatMap(
16
+ * [{id: 1, tags: ['a', 'b']}, {id: 2}, {id: 3, tags: ['c']}],
17
+ * (item): item is {id: number; tags: string[]} => item.tags != null,
18
+ * item => item.tags,
19
+ * ); // => ['a', 'b', 'c']
41
20
  * ```
42
21
  */
43
- export declare function filterAndMap<Item extends PlainObject, ItemKey extends keyof Item, Map extends ArrayMapKeyOrCallback<Item>>(array: Item[], filterKey: ItemKey, filterValue: Item[ItemKey], map: Map): Array<ArrayMapped<Item, Map>>;
22
+ export declare function filterAndFlatMap<Item, Narrowed extends Item, Mapped>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed, mapper: (item: Narrowed, index: number, array: Item[]) => Mapped): Array<ArrayFlattened<Mapped>>;
44
23
  /**
45
- * Get a filtered and mapped array of items
24
+ * Get a filtered, mapped, and flattened array of items
46
25
  *
47
- * @param array Array to search in
48
- * @param filter Filter callback to match items
49
- * @param map Callback or key to map the matched items
50
- * @returns Filtered and mapped array of items
26
+ * _Available as `filterAndFlatMap`, `filterAndMap.flat`, and `select.flat`_
27
+ *
28
+ * @param array Array to select from
29
+ * @param filter Callback to filter the items
30
+ * @param mapper Callback to map and flatten the filtered items
31
+ * @returns Filtered, mapped, and flattened array of items
51
32
  *
52
33
  * @example
53
34
  * ```typescript
54
- * select(
55
- * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
56
- * item => item.id === 2,
57
- * item => item.name,
58
- * ); // => ['Bob']
35
+ * filterAndFlatMap(
36
+ * [{id: 1, tags: ['a', 'b']}, {id: 2, tags: ['c']}, {id: 3, tags: ['d', 'e']}],
37
+ * item => item.id !== 2,
38
+ * item => item.tags,
39
+ * ); // => ['a', 'b', 'd', 'e']
59
40
  * ```
60
41
  */
61
- export declare function filterAndMap<Item, Map extends ArrayMapKeyOrCallback<Item>>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean, map: Map): Array<ArrayMapped<Item, Map>>;
42
+ export declare function filterAndFlatMap<Item, Mapped>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean, mapper: (item: Item, index: number, array: Item[]) => Mapped): Array<ArrayFlattened<Mapped>>;
62
43
  /**
63
- * Get a filtered and mapped array of items
44
+ * Get a narrowed and mapped array of items
64
45
  *
65
- * @param array Array to search in
66
- * @param item Item to match against
67
- * @param map Callback or key to map the matched items
68
- * @returns Filtered and mapped array of items
46
+ * _Available as `filterAndMap` and `select`_
47
+ *
48
+ * @param array Array to select from
49
+ * @param filter Type guard to filter and narrow down the items
50
+ * @param mapper Callback to map the narrowed items
51
+ * @returns Narrowed and mapped array of items
69
52
  *
70
53
  * @example
71
54
  * ```typescript
72
- * select(
73
- * [1, 2, 3, 2, 1],
74
- * 3,
75
- * value => value ** 2,
76
- * ); // => [9]
55
+ * filterAndMap(
56
+ * [{id: 1, name: 'Alice'}, {id: 2}, {id: 3, name: 'Charlie'}],
57
+ * (item): item is {id: number; name: string} => item.name != null,
58
+ * item => item.name.toUpperCase(),
59
+ * ); // => ['ALICE', 'CHARLIE']
77
60
  * ```
78
61
  */
79
- export declare function filterAndMap<Item, Map extends ArrayMapKeyOrCallback<Item>>(array: Item[], item: Item, map: Map): Array<ArrayMapped<Item, Map>>;
62
+ export declare function filterAndMap<Item, Narrowed extends Item, Mapped>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed, mapper: (item: Narrowed, index: number, array: Item[]) => Mapped): Mapped[];
80
63
  /**
81
- * Get a mapped and filtered array of items
64
+ * Get a filtered and mapped array of items
82
65
  *
83
- * _Available as `reverseSelect`_ and `select.reverse`_
66
+ * _Available as `filterAndMap` and `select`_
84
67
  *
85
- * @param array Array to search in
86
- * @param map Callback or key to map the items
87
- * @param filterCallback Callback to get a mapped value's value for matching
88
- * @param filterValue Value to match against
89
- * @returns Mapped and filtered array of items
68
+ * @param array Array to select from
69
+ * @param filter Callback to filter the items
70
+ * @param mapper Callback to map the filtered items
71
+ * @returns Filtered and mapped array of items
90
72
  *
91
73
  * @example
92
74
  * ```typescript
93
- * reverseSelect(
75
+ * filterAndMap(
94
76
  * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
77
+ * item => item.id === 2,
95
78
  * item => item.name,
96
- * value => value.length,
97
- * 3,
98
79
  * ); // => ['Bob']
99
80
  * ```
100
81
  */
101
- export declare function mapAndFilter<Item, Map extends ArrayMapKeyOrCallback<Item>, FilterCallback extends (item: ArrayMapped<Item, Map>, index: number, array: Item[]) => unknown>(array: Item[], map: Map, filterCallback: FilterCallback, filterValue: ReturnType<FilterCallback>): Array<ArrayMapped<Item, Map>>;
82
+ export declare function filterAndMap<Item, Mapped>(array: Item[], filter: (item: Item, index: number, array: Item[]) => boolean, mapper: (item: Item, index: number, array: Item[]) => Mapped): Mapped[];
102
83
  /**
103
- * Get a mapped and filtered array of items
84
+ * Get a mapped, flattened, and narrowed array of items
104
85
  *
105
- * _Available as `reverseSelect`_ and `select.reverse`_
86
+ * _Available as `flatMapAndFilter`, `mapAndFilter.flat`, and `reverseSelect.flat`_
106
87
  *
107
- * @param array Array to search in
108
- * @param map Callback to map the items
109
- * @param filterKey Key to get a mapped value's value for matching
110
- * @param filterValue Value to match against
111
- * @returns Mapped and filtered array of items
88
+ * @param array Array to select from
89
+ * @param mapper Callback to map and flatten the items
90
+ * @param filter Type guard to filter and narrow down the flattened items
91
+ * @returns Mapped, flattened, and narrowed array of items
112
92
  *
113
93
  * @example
114
94
  * ```typescript
115
- * reverseSelect(
116
- * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
117
- * item => ({label: item.name}),
118
- * 'label',
119
- * 'Bob',
120
- * ); // => [{label: 'Bob'}]
95
+ * flatMapAndFilter(
96
+ * [{id: 1, values: [1, 'a']}, {id: 2, values: ['b', 2]}],
97
+ * item => item.values,
98
+ * (value): value is number => typeof value === 'number',
99
+ * ); // => [1, 2]
121
100
  * ```
122
101
  */
123
- export declare function mapAndFilter<Item, MapCallback extends (item: Item, index: number, array: Item[]) => PlainObject, ItemKey extends keyof ReturnType<MapCallback>>(array: Item[], map: MapCallback, filterKey: ItemKey, filterValue: ReturnType<MapCallback>[ItemKey]): Array<ReturnType<MapCallback>>;
102
+ export declare function flatMapAndFilter<Item, Mapped, Narrowed extends ArrayFlattened<Mapped>>(array: Item[], mapper: (item: Item, index: number, array: Item[]) => Mapped, filter: (item: ArrayFlattened<Mapped>, index: number, array: Item[]) => item is Narrowed): Narrowed[];
124
103
  /**
125
- * Get a mapped and filtered array of items
104
+ * Get a mapped, flattened, and filtered array of items
126
105
  *
127
- * _Available as `reverseSelect`_ and `select.reverse`_
106
+ * _Available as `flatMapAndFilter`, `mapAndFilter.flat`, and `reverseSelect.flat`_
128
107
  *
129
- * @param array Array to search in
130
- * @param map Key to map the items
131
- * @param filterKey Key to get a mapped value's value for matching
132
- * @param filterValue Value to match against
133
- * @returns Mapped and filtered array of items
108
+ * @param array Array to select from
109
+ * @param mapper Callback to map and flatten the items
110
+ * @param filter Callback to filter the flattened items
111
+ * @returns Mapped, flattened, and filtered array of items
134
112
  *
135
113
  * @example
136
114
  * ```typescript
137
- * reverseSelect(
138
- * [{meta: {tag: 'a'}}, {meta: {tag: 'b'}}],
139
- * 'meta',
140
- * 'tag',
141
- * 'b',
142
- * ); // => [{tag: 'b'}]
115
+ * flatMapAndFilter(
116
+ * [{id: 1, tags: ['a', 'b']}, {id: 2, tags: ['c']}, {id: 3, tags: ['b', 'd']}],
117
+ * item => item.tags,
118
+ * tag => tag !== 'b',
119
+ * ); // => ['a', 'c', 'd']
143
120
  * ```
144
121
  */
145
- export declare function mapAndFilter<Item, MapKey extends ArrayObjectKeysOf<Item>, ItemKey extends keyof Item[MapKey]>(array: Item[], map: MapKey, filterKey: ItemKey, filterValue: Item[MapKey][ItemKey]): Array<Item[MapKey]>;
122
+ export declare function flatMapAndFilter<Item, Mapped>(array: Item[], mapper: (item: Item, index: number, array: Item[]) => Mapped, filter: (item: ArrayFlattened<Mapped>, index: number, array: Item[]) => boolean): Array<ArrayFlattened<Mapped>>;
146
123
  /**
147
- * Get a mapped and filtered array of items
124
+ * Get a mapped and narrowed array of items
148
125
  *
149
- * _Available as `reverseSelect`_ and `select.reverse`_
126
+ * _Available as `mapAndFilter`, `reverseSelect`, `filterAndMap.reverse`, and `select.reverse`_
150
127
  *
151
- * @param array Array to search in
152
- * @param map Callback or key to map the items
153
- * @param filter Filter callback to match mapped values
154
- * @returns Mapped and filtered array of items
128
+ * @param array Array to select from
129
+ * @param mapper Callback to map the items
130
+ * @param filter Type guard to filter and narrow down the mapped items
131
+ * @returns Mapped and narrowed array of items
155
132
  *
156
133
  * @example
157
134
  * ```typescript
158
- * reverseSelect(
159
- * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
135
+ * mapAndFilter(
136
+ * [{id: 1, name: 'Alice'}, {id: 2}, {id: 3, name: 'Charlie'}],
160
137
  * item => item.name,
161
- * value => value.startsWith('B'),
162
- * ); // => ['Bob']
138
+ * (name): name is string => name != null,
139
+ * ); // => ['Alice', 'Charlie']
163
140
  * ```
164
141
  */
165
- export declare function mapAndFilter<Item, Map extends ArrayMapKeyOrCallback<Item>>(array: Item[], map: Map, filter: (item: ArrayMapped<Item, Map>, index: number, array: Item[]) => boolean): Array<ArrayMapped<Item, Map>>;
142
+ export declare function mapAndFilter<Item, Mapped, Narrowed extends Mapped>(array: Item[], mapper: (item: Item, index: number, array: Item[]) => Mapped, filter: (item: Mapped, index: number, array: Item[]) => item is Narrowed): Narrowed[];
166
143
  /**
167
144
  * Get a mapped and filtered array of items
168
145
  *
169
- * _Available as `reverseSelect`_ and `select.reverse`_
146
+ * _Available as `mapAndFilter`, `reverseSelect`, `filterAndMap.reverse`, and `select.reverse`_
170
147
  *
171
- * @param array Array to search in
172
- * @param map Callback or key to map the items
173
- * @param value Mapped value to match against
148
+ * @param array Array to select from
149
+ * @param mapper Callback to map the items
150
+ * @param filter Callback to filter the mapped items
174
151
  * @returns Mapped and filtered array of items
175
152
  *
176
153
  * @example
177
154
  * ```typescript
178
- * reverseSelect(
179
- * [1, 2, 3, 2, 1],
180
- * value => value ** 2,
181
- * 4,
182
- * ); // => [4, 4]
155
+ * mapAndFilter(
156
+ * [{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}, {id: 3, name: 'Charlie'}],
157
+ * item => item.name,
158
+ * name => name.length > 3,
159
+ * ); // => ['Alice', 'Charlie']
183
160
  * ```
184
161
  */
185
- export declare function mapAndFilter<Item, Map extends ArrayMapKeyOrCallback<Item>>(array: Item[], map: Map, value: ArrayMapped<Item, Map>): Array<ArrayMapped<Item, Map>>;
162
+ export declare function mapAndFilter<Item, Mapped>(array: Item[], mapper: (item: Item, index: number, array: Item[]) => Mapped, filter: (item: Mapped, index: number, array: Item[]) => boolean): Mapped[];
186
163
  export declare namespace filterAndMap {
164
+ export var flat: typeof filterAndFlatMap;
187
165
  export var reverse: typeof mapAndFilter;
188
166
  }
167
+ export declare namespace mapAndFilter {
168
+ export var flat: typeof flatMapAndFilter;
169
+ }
189
170
  //#endregion
190
171
  export { filterAndMap as select, mapAndFilter as reverseSelect };
@@ -1,23 +1,27 @@
1
1
  import "../models/array/array.find.model.mjs";
2
2
  import { findValues } from "../internal/array/find.mjs";
3
3
  //#region src/array/select.ts
4
- function filterAndMap(array, ...parameters) {
5
- return selectValues(array, parameters);
4
+ function filterAndFlatMap(array, filter, mapper) {
5
+ return selectValues(array, filter, mapper, true, false);
6
6
  }
7
- function mapAndFilter(array, ...parameters) {
8
- const mapper = parameters.shift();
9
- return findValues("all", array, parameters, {
10
- callback: mapper,
11
- reverse: true
12
- }).matched;
7
+ function filterAndMap(array, filter, mapper) {
8
+ return selectValues(array, filter, mapper, false, false);
13
9
  }
14
- function selectValues(array, parameters) {
15
- const mapper = parameters.pop();
16
- return findValues("all", array, parameters, {
17
- callback: mapper,
18
- reverse: false
19
- }).matched;
10
+ function flatMapAndFilter(array, mapper, filter) {
11
+ return selectValues(array, filter, mapper, true, true);
20
12
  }
13
+ function mapAndFilter(array, mapper, filter) {
14
+ return selectValues(array, filter, mapper, false, true);
15
+ }
16
+ function selectValues(array, filter, mapper, flat, reverse) {
17
+ return findValues("all", array, [filter], { map: {
18
+ flat,
19
+ reverse,
20
+ callback: mapper
21
+ } }).matched;
22
+ }
23
+ filterAndMap.flat = filterAndFlatMap;
21
24
  filterAndMap.reverse = mapAndFilter;
25
+ mapAndFilter.flat = flatMapAndFilter;
22
26
  //#endregion
23
- export { filterAndMap, filterAndMap as select, mapAndFilter, mapAndFilter as reverseSelect };
27
+ export { filterAndFlatMap, filterAndMap, filterAndMap as select, flatMapAndFilter, mapAndFilter, mapAndFilter as reverseSelect };
@@ -40,6 +40,28 @@ export declare function single<Item, Callback extends (item: Item, index: number
40
40
  * ```
41
41
  */
42
42
  export declare function single<Item extends PlainObject, ItemKey extends keyof Item>(array: Item[], key: ItemKey, value: Item[ItemKey]): Item | undefined;
43
+ /**
44
+ * Get the _only_ narrowed item matching the filter
45
+ *
46
+ * _Throws an error if multiple items match the filter_
47
+ *
48
+ * @param array Array to search in
49
+ * @param filter Type guard to match and narrow down the items
50
+ * @returns Only narrowed item that matches the filter, or `undefined` if no match is found
51
+ *
52
+ * @example
53
+ * ```typescript
54
+ * single(
55
+ * [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
56
+ * (item): item is {id: number; value: number} => typeof item.value === 'number',
57
+ * ); // => {id: 1, value: 10}
58
+ * single(
59
+ * [{id: 1, value: 10}, {id: 2, value: 'a'}, {id: 3, value: 'b'}],
60
+ * (item): item is {id: number; value: string} => typeof item.value === 'string',
61
+ * ); // => throws an error as there are two matches
62
+ * ```
63
+ */
64
+ export declare function single<Item, Narrowed extends Item>(array: Item[], filter: (item: Item, index: number, array: Item[]) => item is Narrowed): Narrowed | undefined;
43
65
  /**
44
66
  * Get the _only_ item matching the filter
45
67
  *
@@ -2,7 +2,7 @@ import "../models/array/array.find.model.mjs";
2
2
  import { findValues } from "../internal/array/find.mjs";
3
3
  //#region src/array/single.ts
4
4
  function single(array, ...parameters) {
5
- const { matched } = findValues("all", array, parameters);
5
+ const { matched } = findValues("all", array, parameters, { limit: 2 });
6
6
  if (matched.length > 1) throw new Error(SINGLE_MESSAGE);
7
7
  return matched[0];
8
8
  }
@@ -13,6 +13,11 @@ declare function Sorter(this: any, sorters: SortHandler[]): void;
13
13
  * @param sorters Sorters to use to determine sorting
14
14
  * @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
15
15
  * @returns Index for item
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * getSortedIndex([1, 3, 2], 2, [{key: 'value', direction: 'asc'}]); // => 1
20
+ * ```
16
21
  */
17
22
  export declare function getSortedIndex<Item>(array: Item[], item: Item, sorters: Array<ArraySorter<Item>>, descending?: boolean): number;
18
23
  /**
@@ -27,6 +32,11 @@ export declare function getSortedIndex<Item>(array: Item[], item: Item, sorters:
27
32
  * @param sorter Sorter to use to determine sorting
28
33
  * @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
29
34
  * @returns Index for item
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * getSortedIndex([1, 3, 2], 2, {key: 'value', direction: 'asc'}); // => 1
39
+ * ```
30
40
  */
31
41
  export declare function getSortedIndex<Item>(array: Item[], item: Item, sorter: ArraySorter<Item>, descending?: boolean): number;
32
42
  /**
@@ -40,6 +50,11 @@ export declare function getSortedIndex<Item>(array: Item[], item: Item, sorter:
40
50
  * @param item Item to get the index for
41
51
  * @param descending Sorted in descending order? _(defaults to `false`)_
42
52
  * @returns Index for item
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * getSortedIndex([1, 3, 2], 2); // => 1
57
+ * ```
43
58
  */
44
59
  export declare function getSortedIndex<Item>(array: Item[], item: Item, descending?: boolean): number;
45
60
  /**
@@ -80,6 +95,12 @@ export declare function initializeSorter<Item>(descending?: boolean): Sorter<Ite
80
95
  * @param sorters Sorters to determine sorting
81
96
  * @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
82
97
  * @returns `true` if sorted, otherwise `false`
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * isSorted([1, 2, 3], [{key: 'value', direction: 'asc'}]); // => true
102
+ * isSorted([3, 2, 1], [{key: 'value', direction: 'asc'}]); // => false
103
+ * ```
83
104
  */
84
105
  export declare function isSorted<Item>(array: Item[], sorters: Array<ArraySorter<Item>>, descending?: boolean): boolean;
85
106
  /**
@@ -91,6 +112,12 @@ export declare function isSorted<Item>(array: Item[], sorters: Array<ArraySorter
91
112
  * @param sorter Sorter to determine sorting
92
113
  * @param descending Sorted in descending order? _(defaults to `false`; overridden by individual sorters)_
93
114
  * @returns `true` if sorted, otherwise `false`
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * isSorted([1, 2, 3], {key: 'value', direction: 'asc'}); // => true
119
+ * isSorted([3, 2, 1], {key: 'value', direction: 'asc'}); // => false
120
+ * ```
94
121
  */
95
122
  export declare function isSorted<Item>(array: Item[], sorter: ArraySorter<Item>, descending?: boolean): boolean;
96
123
  /**
@@ -101,6 +128,12 @@ export declare function isSorted<Item>(array: Item[], sorter: ArraySorter<Item>,
101
128
  * @param array Array to check
102
129
  * @param descending Sorted in descending order? _(defaults to `false`)_
103
130
  * @returns `true` if sorted, otherwise `false`
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * isSorted([1, 2, 3]); // => true
135
+ * isSorted([3, 2, 1]); // => false
136
+ * ```
104
137
  */
105
138
  export declare function isSorted<Item>(array: Item[], descending?: boolean): boolean;
106
139
  /**
@@ -127,6 +160,14 @@ export declare function sort<Item>(array: Item[], comparator: (first: Item, seco
127
160
  * @param sorters Sorters to use for sorting
128
161
  * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
129
162
  * @returns Sorted array
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * sort(
167
+ * [{id: 3}, {id: 1}, {id: 2}],
168
+ * [{key: 'id', direction: 'asc'}],
169
+ * ); // => [{id: 1}, {id: 2}, {id: 3}]
170
+ * ```
130
171
  */
131
172
  export declare function sort<Item>(array: Item[], sorters: Array<ArraySorter<Item>>, descending?: boolean): Item[];
132
173
  /**
@@ -136,6 +177,14 @@ export declare function sort<Item>(array: Item[], sorters: Array<ArraySorter<Ite
136
177
  * @param sorter Sorter to use for sorting
137
178
  * @param descending Sort in descending order? _(defaults to `false`; overridden by individual sorters)_
138
179
  * @returns Sorted array
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * sort(
184
+ * [{id: 3}, {id: 1}, {id: 2}],
185
+ * {key: 'id', direction: 'asc'},
186
+ * ); // => [{id: 1}, {id: 2}, {id: 3}]
187
+ * ```
139
188
  */
140
189
  export declare function sort<Item>(array: Item[], sorter: ArraySorter<Item>, descending?: boolean): Item[];
141
190
  /**
@@ -144,6 +193,11 @@ export declare function sort<Item>(array: Item[], sorter: ArraySorter<Item>, des
144
193
  * @param array Array to sort
145
194
  * @param descending Sort in descending order? _(defaults to `false`)_
146
195
  * @returns Sorted array
196
+ *
197
+ * @example
198
+ * ```typescript
199
+ * sort([3, 1, 2]); // => [1, 2, 3]
200
+ * ```
147
201
  */
148
202
  export declare function sort<Item>(array: Item[], descending?: boolean): Item[];
149
203
  export declare namespace sort {
@@ -11,6 +11,14 @@ export declare function getHexaColor(this: InternalColor): string;
11
11
  * @param value Value to normalize
12
12
  * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
13
13
  * @returns Normalized hex color
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * getNormalizedHex('#abc'); // => '#aabbcc'
18
+ * getNormalizedHex('#abc', true); // => '#aabbccff'
19
+ * getNormalizedHex(123); // => '#000000'
20
+ * getNormalizedHex(123, true); // => '#000000ff'
21
+ * ```
14
22
  */
15
23
  export declare function getNormalizedHex(value: unknown, alpha?: boolean): string;
16
24
  /**
@@ -44,6 +44,14 @@ function getHexaColor() {
44
44
  * @param value Value to normalize
45
45
  * @param alpha Include alpha channel _(opacity)_? _(defaults to `false`)_
46
46
  * @returns Normalized hex color
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * getNormalizedHex('#abc'); // => '#aabbcc'
51
+ * getNormalizedHex('#abc', true); // => '#aabbccff'
52
+ * getNormalizedHex(123); // => '#000000'
53
+ * getNormalizedHex(123, true); // => '#000000ff'
54
+ * ```
47
55
  */
48
56
  function getNormalizedHex(value, alpha) {
49
57
  const includeAlpha = alpha === true;