@wener/utils 1.1.19 → 1.1.20

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,13 @@
1
+ import { isPromise } from './isPromise.js';
2
+ import { nextOfAsyncIterator } from './nextOfAsyncIterator.js';
3
+
4
+ function firstOfAsyncIterator(it) {
5
+ const next = nextOfAsyncIterator(it);
6
+ if (isPromise(next)) {
7
+ return next.then((v) => v[0]);
8
+ }
9
+ return next[0];
10
+ }
11
+
12
+ export { firstOfAsyncIterator };
13
+ //# sourceMappingURL=firstOfAsyncIterator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firstOfAsyncIterator.js","sources":["../../src/asyncs/firstOfAsyncIterator.ts"],"sourcesContent":["import { MaybePromise } from './MaybePromise';\nimport { isPromise } from './isPromise';\nimport { nextOfAsyncIterator } from './nextOfAsyncIterator';\n\nexport function firstOfAsyncIterator<T>(it: MaybePromise<AsyncIterator<T> | Iterator<T> | T>): MaybePromise<T> {\n const next = nextOfAsyncIterator(it);\n if (isPromise(next)) {\n return next.then((v) => v[0]);\n }\n return next[0];\n}\n"],"names":[],"mappings":";;;AAIO,SAAS,qBAAwB,EAAuE,EAAA;AAC7G,EAAM,MAAA,IAAA,GAAO,oBAAoB,EAAE,CAAA,CAAA;AACnC,EAAI,IAAA,SAAA,CAAU,IAAI,CAAG,EAAA;AACnB,IAAA,OAAO,KAAK,IAAK,CAAA,CAAC,CAAM,KAAA,CAAA,CAAE,CAAC,CAAC,CAAA,CAAA;AAAA,GAC9B;AACA,EAAA,OAAO,KAAK,CAAC,CAAA,CAAA;AACf;;;;"}
@@ -0,0 +1,6 @@
1
+ function isIterator(it) {
2
+ return typeof (it == null ? void 0 : it.next) === "function";
3
+ }
4
+
5
+ export { isIterator };
6
+ //# sourceMappingURL=isIterator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"isIterator.js","sources":["../../src/asyncs/isIterator.ts"],"sourcesContent":["export function isIterator<T>(it: any): it is Iterator<T> | AsyncIterator<T> {\n return typeof it?.next === 'function';\n}\n"],"names":[],"mappings":"AAAO,SAAS,WAAc,EAA+C,EAAA;AAC3E,EAAO,OAAA,QAAO,yBAAI,IAAS,CAAA,KAAA,UAAA,CAAA;AAC7B;;;;"}
@@ -0,0 +1,19 @@
1
+ import { isIterator } from './isIterator.js';
2
+ import { isPromise } from './isPromise.js';
3
+
4
+ function nextOfAsyncIterator(it) {
5
+ if (isPromise(it)) {
6
+ return it.then((v) => nextOfAsyncIterator(v));
7
+ }
8
+ if (isIterator(it)) {
9
+ let next = it.next();
10
+ if (isPromise(next)) {
11
+ return next.then((v) => [v.value, v.done]);
12
+ }
13
+ return [next.value, next.done];
14
+ }
15
+ return [it];
16
+ }
17
+
18
+ export { nextOfAsyncIterator };
19
+ //# sourceMappingURL=nextOfAsyncIterator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nextOfAsyncIterator.js","sources":["../../src/asyncs/nextOfAsyncIterator.ts"],"sourcesContent":["import { MaybePromise } from './MaybePromise';\nimport { isIterator } from './isIterator';\nimport { isPromise } from './isPromise';\n\nexport function nextOfAsyncIterator<T>(\n it: MaybePromise<AsyncIterator<T> | Iterator<T> | T>,\n): MaybePromise<[value: T, done?: boolean]> {\n if (isPromise(it)) {\n return it.then((v) => nextOfAsyncIterator(v));\n }\n if (isIterator(it)) {\n let next = it.next();\n if (isPromise(next)) {\n return next.then((v) => [v.value, v.done]);\n }\n return [next.value, next.done];\n }\n return [it];\n}\n"],"names":[],"mappings":";;;AAIO,SAAS,oBACd,EAC0C,EAAA;AAC1C,EAAI,IAAA,SAAA,CAAU,EAAE,CAAG,EAAA;AACjB,IAAA,OAAO,GAAG,IAAK,CAAA,CAAC,CAAM,KAAA,mBAAA,CAAoB,CAAC,CAAC,CAAA,CAAA;AAAA,GAC9C;AACA,EAAI,IAAA,UAAA,CAAW,EAAE,CAAG,EAAA;AAClB,IAAI,IAAA,IAAA,GAAO,GAAG,IAAK,EAAA,CAAA;AACnB,IAAI,IAAA,SAAA,CAAU,IAAI,CAAG,EAAA;AACnB,MAAO,OAAA,IAAA,CAAK,KAAK,CAAC,CAAA,KAAM,CAAC,CAAE,CAAA,KAAA,EAAO,CAAE,CAAA,IAAI,CAAC,CAAA,CAAA;AAAA,KAC3C;AACA,IAAA,OAAO,CAAC,IAAA,CAAK,KAAO,EAAA,IAAA,CAAK,IAAI,CAAA,CAAA;AAAA,GAC/B;AACA,EAAA,OAAO,CAAC,EAAE,CAAA,CAAA;AACZ;;;;"}
package/lib/index.js CHANGED
@@ -7,6 +7,8 @@ export { merge } from './objects/merge/merge.js';
7
7
  export { createLazyPromise } from './asyncs/createLazyPromise.js';
8
8
  export { clearAsyncInterval, setAsyncInterval } from './asyncs/AsyncInterval.js';
9
9
  export { createAsyncIterator } from './asyncs/createAsyncIterator.js';
10
+ export { firstOfAsyncIterator } from './asyncs/firstOfAsyncIterator.js';
11
+ export { isIterator } from './asyncs/isIterator.js';
10
12
  export { sleep } from './asyncs/sleep.js';
11
13
  export { TimeoutError, timeout } from './asyncs/timeout.js';
12
14
  export { isPromise } from './asyncs/isPromise.js';
@@ -54,4 +56,5 @@ export { createFetchWithLogging } from './fetch/createFetchWithLogging.js';
54
56
  export { dumpRequest } from './fetch/dumpRequest.js';
55
57
  export { dumpResponse } from './fetch/dumpResponse.js';
56
58
  export { default as ms } from './libs/ms.js';
59
+ export { nextOfAsyncIterator } from './asyncs/nextOfAsyncIterator.js';
57
60
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wener/utils",
3
- "version": "1.1.19",
3
+ "version": "1.1.20",
4
4
  "type": "module",
5
5
  "description": "Utils for daily use",
6
6
  "repository": {
@@ -0,0 +1,11 @@
1
+ import { MaybePromise } from './MaybePromise';
2
+ import { isPromise } from './isPromise';
3
+ import { nextOfAsyncIterator } from './nextOfAsyncIterator';
4
+
5
+ export function firstOfAsyncIterator<T>(it: MaybePromise<AsyncIterator<T> | Iterator<T> | T>): MaybePromise<T> {
6
+ const next = nextOfAsyncIterator(it);
7
+ if (isPromise(next)) {
8
+ return next.then((v) => v[0]);
9
+ }
10
+ return next[0];
11
+ }
@@ -0,0 +1,3 @@
1
+ export function isIterator<T>(it: any): it is Iterator<T> | AsyncIterator<T> {
2
+ return typeof it?.next === 'function';
3
+ }
@@ -0,0 +1,19 @@
1
+ import { MaybePromise } from './MaybePromise';
2
+ import { isIterator } from './isIterator';
3
+ import { isPromise } from './isPromise';
4
+
5
+ export function nextOfAsyncIterator<T>(
6
+ it: MaybePromise<AsyncIterator<T> | Iterator<T> | T>,
7
+ ): MaybePromise<[value: T, done?: boolean]> {
8
+ if (isPromise(it)) {
9
+ return it.then((v) => nextOfAsyncIterator(v));
10
+ }
11
+ if (isIterator(it)) {
12
+ let next = it.next();
13
+ if (isPromise(next)) {
14
+ return next.then((v) => [v.value, v.done]);
15
+ }
16
+ return [next.value, next.done];
17
+ }
18
+ return [it];
19
+ }
package/src/index.ts CHANGED
@@ -19,6 +19,8 @@ export { createLazyPromise, type LazyPromise } from './asyncs/createLazyPromise'
19
19
  export { setAsyncInterval, clearAsyncInterval } from './asyncs/AsyncInterval';
20
20
  export { type MaybePromise } from './asyncs/MaybePromise';
21
21
  export { createAsyncIterator } from './asyncs/createAsyncIterator';
22
+ export { firstOfAsyncIterator } from './asyncs/firstOfAsyncIterator';
23
+ export { isIterator } from './asyncs/isIterator';
22
24
 
23
25
  export { sleep } from './asyncs/sleep';
24
26
  export { timeout, TimeoutError } from './asyncs/timeout';
@@ -94,3 +96,4 @@ export { type FetchLike, createFetchWith, createFetchWithLogging, dumpResponse,
94
96
 
95
97
  // bundled
96
98
  export { default as ms } from './libs/ms';
99
+ export { nextOfAsyncIterator } from './asyncs/nextOfAsyncIterator';