@tstdl/base 0.87.0 → 0.87.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.
package/package.json
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { AnyIterable } from '../any-iterable-iterator.js';
|
|
2
2
|
import type { IterableItemMetadata } from '../iterable-helpers/types.js';
|
|
3
3
|
export declare function metadataAsync<T>(iterable: AnyIterable<T>): AsyncIterableIterator<IterableItemMetadata<T>>;
|
|
4
|
-
export declare function sync<T>(iterable: Iterable<T>): AsyncIterableIterator<IterableItemMetadata<T>>;
|
|
5
|
-
export declare function async<T>(iterable: AnyIterable<T>): AsyncIterableIterator<IterableItemMetadata<T>>;
|
|
@@ -18,9 +18,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
var metadata_exports = {};
|
|
20
20
|
__export(metadata_exports, {
|
|
21
|
-
|
|
22
|
-
metadataAsync: () => metadataAsync,
|
|
23
|
-
sync: () => sync
|
|
21
|
+
metadataAsync: () => metadataAsync
|
|
24
22
|
});
|
|
25
23
|
module.exports = __toCommonJS(metadata_exports);
|
|
26
24
|
var import_is_async_iterable = require("./is-async-iterable.js");
|
|
@@ -21,7 +21,7 @@ __export(skip_exports, {
|
|
|
21
21
|
skipAsync: () => skipAsync
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(skip_exports);
|
|
24
|
-
var
|
|
24
|
+
var import_filter = require("./filter.js");
|
|
25
25
|
function skipAsync(iterable, count) {
|
|
26
|
-
return (0,
|
|
26
|
+
return (0, import_filter.filterAsync)(iterable, (_item, index) => index >= count);
|
|
27
27
|
}
|
|
@@ -21,7 +21,23 @@ __export(take_exports, {
|
|
|
21
21
|
takeAsync: () => takeAsync
|
|
22
22
|
});
|
|
23
23
|
module.exports = __toCommonJS(take_exports);
|
|
24
|
-
|
|
24
|
+
var import_is_async_iterable = require("./is-async-iterable.js");
|
|
25
|
+
function takeAsync(iterable, count) {
|
|
26
|
+
return (0, import_is_async_iterable.isAsyncIterable)(iterable) ? async(iterable, count) : sync(iterable, count);
|
|
27
|
+
}
|
|
28
|
+
async function* sync(iterable, count) {
|
|
29
|
+
if (count <= 0) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
let counter = 0;
|
|
33
|
+
for (const item of iterable) {
|
|
34
|
+
yield item;
|
|
35
|
+
if (++counter >= count) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
async function* async(iterable, count) {
|
|
25
41
|
if (count <= 0) {
|
|
26
42
|
return;
|
|
27
43
|
}
|