@augment-vir/common 31.33.1 → 31.34.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,32 @@
1
+ import { type MaybePromise } from '@augment-vir/core';
2
+ /**
3
+ * Performs
4
+ * [`[].find()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
5
+ * on an array but supports an async callback. The async callback is blocking. Meaning,
6
+ * `awaitedFind` will wait for a callback on array element 1 to finish before moving on to array
7
+ * element 2.
8
+ *
9
+ * @category Array
10
+ * @category Package : @augment-vir/common
11
+ * @example
12
+ *
13
+ * ```ts
14
+ * import {awaitedFind} from '@augment-vir/common';
15
+ *
16
+ * await awaitedFind(
17
+ * [
18
+ * 1,
19
+ * 2,
20
+ * 3,
21
+ * 4,
22
+ * 5,
23
+ * ],
24
+ * async (value) => {
25
+ * await Promise.resolve(value > 2);
26
+ * },
27
+ * );
28
+ * ```
29
+ *
30
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
31
+ */
32
+ export declare function awaitedFind<const T>(array: ReadonlyArray<T>, callback: (item: T, index: number, originalArray: ReadonlyArray<T>) => MaybePromise<boolean>): Promise<T | undefined>;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Performs
3
+ * [`[].find()`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/find)
4
+ * on an array but supports an async callback. The async callback is blocking. Meaning,
5
+ * `awaitedFind` will wait for a callback on array element 1 to finish before moving on to array
6
+ * element 2.
7
+ *
8
+ * @category Array
9
+ * @category Package : @augment-vir/common
10
+ * @example
11
+ *
12
+ * ```ts
13
+ * import {awaitedFind} from '@augment-vir/common';
14
+ *
15
+ * await awaitedFind(
16
+ * [
17
+ * 1,
18
+ * 2,
19
+ * 3,
20
+ * 4,
21
+ * 5,
22
+ * ],
23
+ * async (value) => {
24
+ * await Promise.resolve(value > 2);
25
+ * },
26
+ * );
27
+ * ```
28
+ *
29
+ * @package [`@augment-vir/common`](https://www.npmjs.com/package/@augment-vir/common)
30
+ */
31
+ export async function awaitedFind(array, callback) {
32
+ for (let index = 0; index < array.length; index++) {
33
+ const item = array[index];
34
+ if (await callback(item, index, array)) {
35
+ return item;
36
+ }
37
+ }
38
+ return undefined;
39
+ }
@@ -12,7 +12,6 @@ export function findSubstringIndexes({ searchIn, searchFor, caseSensitive, inclu
12
12
  const searchRegExp = addRegExpFlags(setRegExpCaseSensitivity(searchFor, { caseSensitive }), 'g');
13
13
  const indexes = [];
14
14
  const indexesAndLengths = [];
15
- // eslint-disable-next-line sonarjs/no-ignored-return
16
15
  searchIn.replace(searchRegExp, (...matchResults) => {
17
16
  /**
18
17
  * Grabbing the second to last entry in the array (rather than the second) takes capture
package/dist/index.d.ts CHANGED
@@ -2,6 +2,7 @@ export * from './augments/array/array-map.js';
2
2
  export * from './augments/array/array-pagination.js';
3
3
  export * from './augments/array/array-to-object.js';
4
4
  export * from './augments/array/awaited/awaited-filter.js';
5
+ export * from './augments/array/awaited/awaited-find.js';
5
6
  export * from './augments/array/awaited/awaited-for-each.js';
6
7
  export * from './augments/array/awaited/awaited-map.js';
7
8
  export * from './augments/array/create-array.js';
package/dist/index.js CHANGED
@@ -2,6 +2,7 @@ export * from './augments/array/array-map.js';
2
2
  export * from './augments/array/array-pagination.js';
3
3
  export * from './augments/array/array-to-object.js';
4
4
  export * from './augments/array/awaited/awaited-filter.js';
5
+ export * from './augments/array/awaited/awaited-find.js';
5
6
  export * from './augments/array/awaited/awaited-for-each.js';
6
7
  export * from './augments/array/awaited/awaited-map.js';
7
8
  export * from './augments/array/create-array.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@augment-vir/common",
3
- "version": "31.33.1",
3
+ "version": "31.34.1",
4
4
  "description": "A collection of augments, helpers types, functions, and classes for any JavaScript environment.",
5
5
  "keywords": [
6
6
  "augment",
@@ -40,8 +40,8 @@
40
40
  "test:web": "virmator --no-deps test web"
41
41
  },
42
42
  "dependencies": {
43
- "@augment-vir/assert": "^31.33.1",
44
- "@augment-vir/core": "^31.33.1",
43
+ "@augment-vir/assert": "^31.34.1",
44
+ "@augment-vir/core": "^31.34.1",
45
45
  "@date-vir/duration": "^7.4.2",
46
46
  "ansi-styles": "^6.2.1",
47
47
  "deepcopy-esm": "^2.1.1",