iter-fest 0.0.0-main.9e231bf
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/LICENSE +21 -0
- package/README.md +137 -0
- package/dist/chunk-27NJVC7K.mjs +26 -0
- package/dist/chunk-27NJVC7K.mjs.map +1 -0
- package/dist/chunk-44W7OTNE.mjs +12 -0
- package/dist/chunk-44W7OTNE.mjs.map +1 -0
- package/dist/chunk-5CHMNKXJ.mjs +20 -0
- package/dist/chunk-5CHMNKXJ.mjs.map +1 -0
- package/dist/chunk-5CRMPYKD.mjs +19 -0
- package/dist/chunk-5CRMPYKD.mjs.map +1 -0
- package/dist/chunk-6C3P4TNK.mjs +19 -0
- package/dist/chunk-6C3P4TNK.mjs.map +1 -0
- package/dist/chunk-EZC33HE6.mjs +15 -0
- package/dist/chunk-EZC33HE6.mjs.map +1 -0
- package/dist/chunk-GWZF5BB7.mjs +16 -0
- package/dist/chunk-GWZF5BB7.mjs.map +1 -0
- package/dist/chunk-HYU4EN7J.mjs +20 -0
- package/dist/chunk-HYU4EN7J.mjs.map +1 -0
- package/dist/chunk-JU353VSE.mjs +16 -0
- package/dist/chunk-JU353VSE.mjs.map +1 -0
- package/dist/chunk-KONB7TV6.mjs +35 -0
- package/dist/chunk-KONB7TV6.mjs.map +1 -0
- package/dist/chunk-MDBK7ND5.mjs +26 -0
- package/dist/chunk-MDBK7ND5.mjs.map +1 -0
- package/dist/chunk-MNDAEMYM.mjs +15 -0
- package/dist/chunk-MNDAEMYM.mjs.map +1 -0
- package/dist/chunk-MNLOWKTC.mjs +19 -0
- package/dist/chunk-MNLOWKTC.mjs.map +1 -0
- package/dist/chunk-TEI3K6GT.mjs +21 -0
- package/dist/chunk-TEI3K6GT.mjs.map +1 -0
- package/dist/chunk-UIEKIMLW.mjs +27 -0
- package/dist/chunk-UIEKIMLW.mjs.map +1 -0
- package/dist/chunk-V6OWQQ3Q.mjs +20 -0
- package/dist/chunk-V6OWQQ3Q.mjs.map +1 -0
- package/dist/chunk-W5NEOEVE.mjs +12 -0
- package/dist/chunk-W5NEOEVE.mjs.map +1 -0
- package/dist/chunk-WKIRSZXX.mjs +32 -0
- package/dist/chunk-WKIRSZXX.mjs.map +1 -0
- package/dist/chunk-XKBVB2JN.mjs +12 -0
- package/dist/chunk-XKBVB2JN.mjs.map +1 -0
- package/dist/chunk-XW34KZRY.mjs +17 -0
- package/dist/chunk-XW34KZRY.mjs.map +1 -0
- package/dist/chunk-Y5M2C7NQ.mjs +13 -0
- package/dist/chunk-Y5M2C7NQ.mjs.map +1 -0
- package/dist/chunk-ZUBHGSCW.mjs +18 -0
- package/dist/chunk-ZUBHGSCW.mjs.map +1 -0
- package/dist/iter-fest.d.mts +21 -0
- package/dist/iter-fest.d.ts +21 -0
- package/dist/iter-fest.iterableAt.d.mts +8 -0
- package/dist/iter-fest.iterableAt.d.ts +8 -0
- package/dist/iter-fest.iterableAt.js +56 -0
- package/dist/iter-fest.iterableAt.js.map +1 -0
- package/dist/iter-fest.iterableAt.mjs +8 -0
- package/dist/iter-fest.iterableAt.mjs.map +1 -0
- package/dist/iter-fest.iterableConcat.d.mts +16 -0
- package/dist/iter-fest.iterableConcat.d.ts +16 -0
- package/dist/iter-fest.iterableConcat.js +40 -0
- package/dist/iter-fest.iterableConcat.js.map +1 -0
- package/dist/iter-fest.iterableConcat.mjs +7 -0
- package/dist/iter-fest.iterableConcat.mjs.map +1 -0
- package/dist/iter-fest.iterableEntries.d.mts +6 -0
- package/dist/iter-fest.iterableEntries.d.ts +6 -0
- package/dist/iter-fest.iterableEntries.js +36 -0
- package/dist/iter-fest.iterableEntries.js.map +1 -0
- package/dist/iter-fest.iterableEntries.mjs +7 -0
- package/dist/iter-fest.iterableEntries.mjs.map +1 -0
- package/dist/iter-fest.iterableEvery.d.mts +24 -0
- package/dist/iter-fest.iterableEvery.d.ts +24 -0
- package/dist/iter-fest.iterableEvery.js +43 -0
- package/dist/iter-fest.iterableEvery.js.map +1 -0
- package/dist/iter-fest.iterableEvery.mjs +7 -0
- package/dist/iter-fest.iterableEvery.mjs.map +1 -0
- package/dist/iter-fest.iterableFilter.d.mts +16 -0
- package/dist/iter-fest.iterableFilter.d.ts +16 -0
- package/dist/iter-fest.iterableFilter.js +42 -0
- package/dist/iter-fest.iterableFilter.js.map +1 -0
- package/dist/iter-fest.iterableFilter.mjs +7 -0
- package/dist/iter-fest.iterableFilter.mjs.map +1 -0
- package/dist/iter-fest.iterableFind.d.mts +15 -0
- package/dist/iter-fest.iterableFind.d.ts +15 -0
- package/dist/iter-fest.iterableFind.js +43 -0
- package/dist/iter-fest.iterableFind.js.map +1 -0
- package/dist/iter-fest.iterableFind.mjs +7 -0
- package/dist/iter-fest.iterableFind.mjs.map +1 -0
- package/dist/iter-fest.iterableFindIndex.d.mts +14 -0
- package/dist/iter-fest.iterableFindIndex.d.ts +14 -0
- package/dist/iter-fest.iterableFindIndex.js +44 -0
- package/dist/iter-fest.iterableFindIndex.js.map +1 -0
- package/dist/iter-fest.iterableFindIndex.mjs +7 -0
- package/dist/iter-fest.iterableFindIndex.mjs.map +1 -0
- package/dist/iter-fest.iterableFindLast.d.mts +15 -0
- package/dist/iter-fest.iterableFindLast.d.ts +15 -0
- package/dist/iter-fest.iterableFindLast.js +44 -0
- package/dist/iter-fest.iterableFindLast.js.map +1 -0
- package/dist/iter-fest.iterableFindLast.mjs +7 -0
- package/dist/iter-fest.iterableFindLast.mjs.map +1 -0
- package/dist/iter-fest.iterableFindLastIndex.d.mts +14 -0
- package/dist/iter-fest.iterableFindLastIndex.d.ts +14 -0
- package/dist/iter-fest.iterableFindLastIndex.js +45 -0
- package/dist/iter-fest.iterableFindLastIndex.js.map +1 -0
- package/dist/iter-fest.iterableFindLastIndex.mjs +7 -0
- package/dist/iter-fest.iterableFindLastIndex.mjs.map +1 -0
- package/dist/iter-fest.iterableForEach.d.mts +10 -0
- package/dist/iter-fest.iterableForEach.d.ts +10 -0
- package/dist/iter-fest.iterableForEach.js +40 -0
- package/dist/iter-fest.iterableForEach.js.map +1 -0
- package/dist/iter-fest.iterableForEach.mjs +7 -0
- package/dist/iter-fest.iterableForEach.mjs.map +1 -0
- package/dist/iter-fest.iterableIncludes.d.mts +9 -0
- package/dist/iter-fest.iterableIncludes.d.ts +9 -0
- package/dist/iter-fest.iterableIncludes.js +56 -0
- package/dist/iter-fest.iterableIncludes.js.map +1 -0
- package/dist/iter-fest.iterableIncludes.mjs +8 -0
- package/dist/iter-fest.iterableIncludes.mjs.map +1 -0
- package/dist/iter-fest.iterableIndexOf.d.mts +9 -0
- package/dist/iter-fest.iterableIndexOf.d.ts +9 -0
- package/dist/iter-fest.iterableIndexOf.js +57 -0
- package/dist/iter-fest.iterableIndexOf.js.map +1 -0
- package/dist/iter-fest.iterableIndexOf.mjs +8 -0
- package/dist/iter-fest.iterableIndexOf.mjs.map +1 -0
- package/dist/iter-fest.iterableJoin.d.mts +8 -0
- package/dist/iter-fest.iterableJoin.d.ts +8 -0
- package/dist/iter-fest.iterableJoin.js +44 -0
- package/dist/iter-fest.iterableJoin.js.map +1 -0
- package/dist/iter-fest.iterableJoin.mjs +7 -0
- package/dist/iter-fest.iterableJoin.mjs.map +1 -0
- package/dist/iter-fest.iterableKeys.d.mts +6 -0
- package/dist/iter-fest.iterableKeys.d.ts +6 -0
- package/dist/iter-fest.iterableKeys.js +36 -0
- package/dist/iter-fest.iterableKeys.js.map +1 -0
- package/dist/iter-fest.iterableKeys.mjs +7 -0
- package/dist/iter-fest.iterableKeys.mjs.map +1 -0
- package/dist/iter-fest.iterableMap.d.mts +8 -0
- package/dist/iter-fest.iterableMap.d.ts +8 -0
- package/dist/iter-fest.iterableMap.js +39 -0
- package/dist/iter-fest.iterableMap.js.map +1 -0
- package/dist/iter-fest.iterableMap.mjs +7 -0
- package/dist/iter-fest.iterableMap.mjs.map +1 -0
- package/dist/iter-fest.iterableReduce.d.mts +19 -0
- package/dist/iter-fest.iterableReduce.d.ts +19 -0
- package/dist/iter-fest.iterableReduce.js +41 -0
- package/dist/iter-fest.iterableReduce.js.map +1 -0
- package/dist/iter-fest.iterableReduce.mjs +7 -0
- package/dist/iter-fest.iterableReduce.mjs.map +1 -0
- package/dist/iter-fest.iterableSlice.d.mts +14 -0
- package/dist/iter-fest.iterableSlice.d.ts +14 -0
- package/dist/iter-fest.iterableSlice.js +65 -0
- package/dist/iter-fest.iterableSlice.js.map +1 -0
- package/dist/iter-fest.iterableSlice.mjs +8 -0
- package/dist/iter-fest.iterableSlice.mjs.map +1 -0
- package/dist/iter-fest.iterableSome.d.mts +12 -0
- package/dist/iter-fest.iterableSome.d.ts +12 -0
- package/dist/iter-fest.iterableSome.js +43 -0
- package/dist/iter-fest.iterableSome.js.map +1 -0
- package/dist/iter-fest.iterableSome.mjs +7 -0
- package/dist/iter-fest.iterableSome.mjs.map +1 -0
- package/dist/iter-fest.iterableToSpliced.d.mts +17 -0
- package/dist/iter-fest.iterableToSpliced.d.ts +17 -0
- package/dist/iter-fest.iterableToSpliced.js +62 -0
- package/dist/iter-fest.iterableToSpliced.js.map +1 -0
- package/dist/iter-fest.iterableToSpliced.mjs +8 -0
- package/dist/iter-fest.iterableToSpliced.mjs.map +1 -0
- package/dist/iter-fest.iterableToString.d.mts +6 -0
- package/dist/iter-fest.iterableToString.d.ts +6 -0
- package/dist/iter-fest.iterableToString.js +51 -0
- package/dist/iter-fest.iterableToString.js.map +1 -0
- package/dist/iter-fest.iterableToString.mjs +8 -0
- package/dist/iter-fest.iterableToString.mjs.map +1 -0
- package/dist/iter-fest.iteratorToIterable.d.mts +3 -0
- package/dist/iter-fest.iteratorToIterable.d.ts +3 -0
- package/dist/iter-fest.iteratorToIterable.js +39 -0
- package/dist/iter-fest.iteratorToIterable.js.map +1 -0
- package/dist/iter-fest.iteratorToIterable.mjs +7 -0
- package/dist/iter-fest.iteratorToIterable.mjs.map +1 -0
- package/dist/iter-fest.js +388 -0
- package/dist/iter-fest.js.map +1 -0
- package/dist/iter-fest.mjs +88 -0
- package/dist/iter-fest.mjs.map +1 -0
- package/package.json +279 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 William Wong
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# `iter-fest`
|
|
2
|
+
|
|
3
|
+
A collection of utilities for iterations.
|
|
4
|
+
|
|
5
|
+
## Background
|
|
6
|
+
|
|
7
|
+
Iterators become mainstream. However, traversing iterables are not as trivial as array.
|
|
8
|
+
|
|
9
|
+
In this package, we are porting majority of `Array.prototype.*` functions to work with iterables. We also added some utility functions to assist iterable, iterator, and generator.
|
|
10
|
+
|
|
11
|
+
Iterables can contains infinite number of items, please use this package responsibly.
|
|
12
|
+
|
|
13
|
+
## How to use
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install iter-fest
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
### `Array.prototype` ports
|
|
20
|
+
|
|
21
|
+
We ported majority of functions from `Array.prototype.*` to `iterable*`.
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { iterableIncludes, iterableReduce } from 'iter-fest'; // Via default exports.
|
|
25
|
+
import { iterableSome } from 'iter-fest/iterableSome'; // Via named exports.
|
|
26
|
+
|
|
27
|
+
const iterable: Iterable<number> = [1, 2, 3, 4, 5].values();
|
|
28
|
+
|
|
29
|
+
console.log(iterableIncludes(iterable, 3)); // Prints "true".
|
|
30
|
+
console.log(iterableReduce(iterable, (sum, value) => sum + value, 0)); // Prints "15".
|
|
31
|
+
console.log(iterableSome(iterable, value => value % 2)); // Prints "true".
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
List of ported functions: [`at`](https://tc39.es/ecma262/#sec-array.prototype.at), [`concat`](https://tc39.es/ecma262/#sec-array.prototype.concat), [`entries`](https://tc39.es/ecma262/#sec-array.prototype.entries), [`every`](https://tc39.es/ecma262/#sec-array.prototype.every), [`filter`](https://tc39.es/ecma262/#sec-array.prototype.filter), [`find`](https://tc39.es/ecma262/#sec-array.prototype.find), [`findIndex`](https://tc39.es/ecma262/#sec-array.prototype.findindex), [`findLast`](https://tc39.es/ecma262/#sec-array.prototype.findlast), [`findLastIndex`](https://tc39.es/ecma262/#sec-array.prototype.findlastindex), [`forEach`](https://tc39.es/ecma262/#sec-array.prototype.foreach), [`includes`](https://tc39.es/ecma262/#sec-array.prototype.includes), [`indexOf`](https://tc39.es/ecma262/#sec-array.prototype.indexof), [`join`](https://tc39.es/ecma262/#sec-array.prototype.join), [`keys`](https://tc39.es/ecma262/#sec-array.prototype.keys), [`map`](https://tc39.es/ecma262/#sec-array.prototype.map), [`reduce`](https://tc39.es/ecma262/#sec-array.prototype.reduce), [`slice`](https://tc39.es/ecma262/#sec-array.prototype.slice), [`some`](https://tc39.es/ecma262/#sec-array.prototype.some), [`toSpliced`](https://tc39.es/ecma262/#sec-array.prototype.tospliced), and [`toString`](https://tc39.es/ecma262/#sec-array.prototype.tostring).
|
|
35
|
+
|
|
36
|
+
### Converting an iterator to iterable
|
|
37
|
+
|
|
38
|
+
`iteratorToIterable` converts a pure iterator to `IterableIterator` and enable for-loop iteration.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
const iterate = (): Iterator<number> => {
|
|
42
|
+
let value = 0;
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
next: () => {
|
|
46
|
+
if (++value <= 3) {
|
|
47
|
+
return { done: false, value };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return { done: true, value: undefined };
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
for (const value of iteratorToIterable(iterate())) {
|
|
56
|
+
console.log(value); // Prints "1", "2", "3".
|
|
57
|
+
}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Behaviors
|
|
61
|
+
|
|
62
|
+
### How this compares to the TC39 proposals?
|
|
63
|
+
|
|
64
|
+
Always use the [TC39](https://github.com/tc39/proposal-iterator-helpers) [version](https://github.com/tc39/proposal-async-iterator-helpers) when they are available in your environment. We will deprecate duplicated features when the proposal is shipped.
|
|
65
|
+
|
|
66
|
+
`iter-fest` also works with siblings of iterators such as `Generator`, [Streams](https://streams.spec.whatwg.org/) and `Observable`. `iter-fest` will evolve more around the whole iteration universe than focusing on `Iterator` alone.
|
|
67
|
+
|
|
68
|
+
### What are the differences between `Array.prototype` and their ports?
|
|
69
|
+
|
|
70
|
+
Majority of functions should work the same way with same complexity and performance characteristics. If they return an array, in the port, they will be returning iterables instead.
|
|
71
|
+
|
|
72
|
+
There are minor differences on some functions:
|
|
73
|
+
|
|
74
|
+
- `findLast` and `findLastIndex`
|
|
75
|
+
- Instead of iterating from the right side, iterables must start from left side
|
|
76
|
+
- Thus, with an iterable of 5 items, `predicate` will be called exactly 5 times with `O(N)` complexity
|
|
77
|
+
- In contrast, its counterpart in `Array` will be called between 1 and 5 times with `O(log N)` complexity
|
|
78
|
+
- `at`, `includes`, `indexOf`, `slice`, and `toSpliced`
|
|
79
|
+
- Index arguments cannot be negative finite number
|
|
80
|
+
- Negative finite number means traversing from right side, which an iterator/iterable may not have an end
|
|
81
|
+
- Infinites, zeroes, and positive numbers are supported
|
|
82
|
+
|
|
83
|
+
### Why `Array.prototype.push` is not ported?
|
|
84
|
+
|
|
85
|
+
Some functions that modify the array are not ported, such as, `copyWithin`, `fill`, `pop`, `push`, `reverse`, `shift`, `splice`, `unshift`, etc. Iterables are read-only and we prefer to keep it that way.
|
|
86
|
+
|
|
87
|
+
Some functions that do not have actual functionality in the iterable world are not ported, such as, `values`, etc.
|
|
88
|
+
|
|
89
|
+
Some functions that cannot not retains their complexity or performance characteristics are not ported. These functions usually iterate from the other end or requires random access, such as, `lastIndexOf`, `reduceRight`, `sort`, `toReversed`, `toSorted`, etc.
|
|
90
|
+
|
|
91
|
+
If you think a specific function should be ported, please submit a pull request to us.
|
|
92
|
+
|
|
93
|
+
### How about asynchronous iterables?
|
|
94
|
+
|
|
95
|
+
Yes, this is on our roadmap. This will enable traverse iterables [across domains/workers via `MessagePort`](https://npmjs.com/package/message-port-rpc). We welcome pull requests.
|
|
96
|
+
|
|
97
|
+
### How about functions outside of `Array.prototype`?
|
|
98
|
+
|
|
99
|
+
Possibly. Please submit an issue and discuss with us.
|
|
100
|
+
|
|
101
|
+
### Does this work on generator?
|
|
102
|
+
|
|
103
|
+
Generator has more functionalities than iterator and array. It is not recommended to iterate a generator for some reasons:
|
|
104
|
+
|
|
105
|
+
- Generator can define the return value
|
|
106
|
+
- `return { done: true, value: 'the very last value' }`
|
|
107
|
+
- Iterating generator using for-loop will not get any values from `{ done: true }`
|
|
108
|
+
- Generator can receive feedback values from its iterator
|
|
109
|
+
- `generator.next('something')`, the feedback can be assigned to variable via `const feedback = yield;`
|
|
110
|
+
- For-loop cannot send feedbacks to generator
|
|
111
|
+
|
|
112
|
+
### When should I use `Iterable`, `IterableIterator` and `Iterator`?
|
|
113
|
+
|
|
114
|
+
For best compatibility, you should generally follow this API signature: use `Iterable` for inputs, and use `IterableIterator` for outputs. You should avoid exporting pure `Iterator`.
|
|
115
|
+
|
|
116
|
+
```ts
|
|
117
|
+
function transform<T>(iterable: Iterable<T>): IterableIterator<T>;
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### What is on the roadmap?
|
|
121
|
+
|
|
122
|
+
We are planning to bring iterables and its siblings together, including:
|
|
123
|
+
|
|
124
|
+
- `Iterable` and `AsyncIterable`
|
|
125
|
+
- `Iterator` and `AsyncIterator`
|
|
126
|
+
- `IterableIterator` and `AsyncIterableIterator`
|
|
127
|
+
- `Generator` and `AsyncGenerator`
|
|
128
|
+
- `ReadableStream`
|
|
129
|
+
- `Observable`
|
|
130
|
+
|
|
131
|
+
## Contributions
|
|
132
|
+
|
|
133
|
+
Like us? [Star](https://github.com/compulim/iter-fest/stargazers) us.
|
|
134
|
+
|
|
135
|
+
Want to make it better? [File](https://github.com/compulim/iter-fest/issues) us an issue.
|
|
136
|
+
|
|
137
|
+
Don't like something you see? [Submit](https://github.com/compulim/iter-fest/pulls) a pull request.
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toIntegerOrInfinity
|
|
3
|
+
} from "./chunk-W5NEOEVE.mjs";
|
|
4
|
+
|
|
5
|
+
// src/iterableIncludes.ts
|
|
6
|
+
function iterableIncludes(iterable, searchElement, fromIndex = 0) {
|
|
7
|
+
let index = 0;
|
|
8
|
+
fromIndex = toIntegerOrInfinity(fromIndex);
|
|
9
|
+
if (fromIndex !== Infinity) {
|
|
10
|
+
fromIndex = fromIndex === -Infinity ? 0 : fromIndex;
|
|
11
|
+
if (fromIndex < 0) {
|
|
12
|
+
throw new TypeError("fromIndex cannot be a negative finite number");
|
|
13
|
+
}
|
|
14
|
+
for (const item of iterable) {
|
|
15
|
+
if (index++ >= fromIndex && Object.is(item, searchElement)) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
iterableIncludes
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=chunk-27NJVC7K.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableIncludes.ts"],"sourcesContent":["import toIntegerOrInfinity from './private/toIntegerOrInfinity';\n\n/**\n * Determines whether an iterable includes a certain element, returning true or false as appropriate.\n *\n * @param searchElement The element to search for.\n * @param fromIndex The position in this iterable at which to begin searching for searchElement.\n */\nexport function iterableIncludes<T>(iterable: Iterable<T>, searchElement: T, fromIndex: number = 0): boolean {\n let index = 0;\n\n fromIndex = toIntegerOrInfinity(fromIndex);\n\n if (fromIndex !== Infinity) {\n fromIndex = fromIndex === -Infinity ? 0 : fromIndex;\n\n if (fromIndex < 0) {\n // TODO: Support negative fromIndex.\n throw new TypeError('fromIndex cannot be a negative finite number');\n }\n\n for (const item of iterable) {\n if (index++ >= fromIndex && Object.is(item, searchElement)) {\n return true;\n }\n }\n }\n\n return false;\n}\n"],"mappings":";;;;;AAQO,SAAS,iBAAoB,UAAuB,eAAkB,YAAoB,GAAY;AAC3G,MAAI,QAAQ;AAEZ,cAAY,oBAAoB,SAAS;AAEzC,MAAI,cAAc,UAAU;AAC1B,gBAAY,cAAc,YAAY,IAAI;AAE1C,QAAI,YAAY,GAAG;AAEjB,YAAM,IAAI,UAAU,8CAA8C;AAAA,IACpE;AAEA,eAAW,QAAQ,UAAU;AAC3B,UAAI,WAAW,aAAa,OAAO,GAAG,MAAM,aAAa,GAAG;AAC1D,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableEntries.ts"],"sourcesContent":["/**\n * Returns an iterable of key, value pairs for every entry in the iterable\n */\nexport function* iterableEntries<T>(iterable: Iterable<T>): IterableIterator<[number, T]> {\n let index = 0;\n\n for (const value of iterable) {\n yield [index++, value];\n }\n}\n"],"mappings":";AAGO,UAAU,gBAAmB,UAAsD;AACxF,MAAI,QAAQ;AAEZ,aAAW,SAAS,UAAU;AAC5B,UAAM,CAAC,SAAS,KAAK;AAAA,EACvB;AACF;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/iterableJoin.ts
|
|
2
|
+
function iterableJoin(iterable, separator = ",") {
|
|
3
|
+
let index = 0;
|
|
4
|
+
let result = "";
|
|
5
|
+
for (const item of iterable) {
|
|
6
|
+
if (index) {
|
|
7
|
+
result += separator;
|
|
8
|
+
}
|
|
9
|
+
if (typeof item !== "undefined" && item !== null) {
|
|
10
|
+
result += item;
|
|
11
|
+
}
|
|
12
|
+
index++;
|
|
13
|
+
}
|
|
14
|
+
return result;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
iterableJoin
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=chunk-5CHMNKXJ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableJoin.ts"],"sourcesContent":["/**\n * Adds all the elements of an iterable into a string, separated by the specified separator string.\n *\n * @param separator A string used to separate one element of the iterable from the next in the resulting string. If omitted, the iterable elements are separated with a comma.\n */\nexport function iterableJoin<T>(iterable: Iterable<T>, separator: string = ','): string {\n let index = 0;\n let result = '';\n\n for (const item of iterable) {\n if (index) {\n result += separator;\n }\n\n if (typeof item !== 'undefined' && item !== null) {\n result += item;\n }\n\n index++;\n }\n\n return result;\n}\n"],"mappings":";AAKO,SAAS,aAAgB,UAAuB,YAAoB,KAAa;AACtF,MAAI,QAAQ;AACZ,MAAI,SAAS;AAEb,aAAW,QAAQ,UAAU;AAC3B,QAAI,OAAO;AACT,gBAAU;AAAA,IACZ;AAEA,QAAI,OAAO,SAAS,eAAe,SAAS,MAAM;AAChD,gBAAU;AAAA,IACZ;AAEA;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/iterableEvery.ts
|
|
2
|
+
function iterableEvery(iterable, predicate, thisArg = void 0) {
|
|
3
|
+
let index = 0;
|
|
4
|
+
if (typeof predicate !== "function") {
|
|
5
|
+
throw new TypeError(`${predicate} is not a function`);
|
|
6
|
+
}
|
|
7
|
+
const boundPredicate = predicate.bind(thisArg);
|
|
8
|
+
for (const value of iterable) {
|
|
9
|
+
if (!boundPredicate(value, index++, iterable)) {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
iterableEvery
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=chunk-5CRMPYKD.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableEvery.ts"],"sourcesContent":["/**\n * Determines whether all the members of an iterable satisfy the specified test.\n *\n * @param predicate A function that accepts up to three arguments. The every method calls\n * the predicate function for each element in the iterable until the predicate returns a value\n * which is coercible to the Boolean value false, or until the end of the iterable.\n *\n * @param thisArg An object to which the this keyword can refer in the predicate function.\n * If thisArg is omitted, undefined is used as the this value.\n */\nexport function iterableEvery<T, S extends T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => value is S,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): iterable is S[];\n\n/**\n * Determines whether all the members of an iterable satisfy the specified test.\n *\n * @param predicate A function that accepts up to three arguments. The every method calls\n * the predicate function for each element in the iterable until the predicate returns a value\n * which is coercible to the Boolean value false, or until the end of the iterable.\n *\n * @param thisArg An object to which the this keyword can refer in the predicate function.\n * If thisArg is omitted, undefined is used as the this value.\n */\nexport function iterableEvery<T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): boolean;\n\nexport function iterableEvery<T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg: any = undefined\n): boolean {\n let index = 0;\n\n if (typeof predicate !== 'function') {\n throw new TypeError(`${predicate} is not a function`);\n }\n\n const boundPredicate = predicate.bind(thisArg);\n\n for (const value of iterable) {\n if (!boundPredicate(value, index++, iterable)) {\n return false;\n }\n }\n\n return true;\n}\n"],"mappings":";AAkCO,SAAS,cACd,UACA,WAEA,UAAe,QACN;AACT,MAAI,QAAQ;AAEZ,MAAI,OAAO,cAAc,YAAY;AACnC,UAAM,IAAI,UAAU,GAAG,SAAS,oBAAoB;AAAA,EACtD;AAEA,QAAM,iBAAiB,UAAU,KAAK,OAAO;AAE7C,aAAW,SAAS,UAAU;AAC5B,QAAI,CAAC,eAAe,OAAO,SAAS,QAAQ,GAAG;AAC7C,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/iterableSome.ts
|
|
2
|
+
function iterableSome(iterable, predicate, thisArg = void 0) {
|
|
3
|
+
let index = 0;
|
|
4
|
+
if (typeof predicate !== "function") {
|
|
5
|
+
throw new TypeError(`${predicate} is not a function`);
|
|
6
|
+
}
|
|
7
|
+
const boundPredicate = predicate.bind(thisArg);
|
|
8
|
+
for (const value of iterable) {
|
|
9
|
+
if (boundPredicate(value, index++, iterable)) {
|
|
10
|
+
return true;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
iterableSome
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=chunk-6C3P4TNK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableSome.ts"],"sourcesContent":["/**\n * Determines whether the specified callback function returns true for any element of an iterable.\n *\n * @param predicate\n * A function that accepts up to three arguments. The some method calls the predicate function for each element in the iterable until the predicate returns a value which is coercible to the Boolean value true, or until the end of the iterable.\n *\n * @param thisArg\n * An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.\n */\nexport function iterableSome<T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg: any = undefined\n): boolean {\n let index = 0;\n\n if (typeof predicate !== 'function') {\n throw new TypeError(`${predicate} is not a function`);\n }\n\n const boundPredicate = predicate.bind(thisArg);\n\n for (const value of iterable) {\n if (boundPredicate(value, index++, iterable)) {\n return true;\n }\n }\n\n return false;\n}\n"],"mappings":";AASO,SAAS,aACd,UACA,WAEA,UAAe,QACN;AACT,MAAI,QAAQ;AAEZ,MAAI,OAAO,cAAc,YAAY;AACnC,UAAM,IAAI,UAAU,GAAG,SAAS,oBAAoB;AAAA,EACtD;AAEA,QAAM,iBAAiB,UAAU,KAAK,OAAO;AAE7C,aAAW,SAAS,UAAU;AAC5B,QAAI,eAAe,OAAO,SAAS,QAAQ,GAAG;AAC5C,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/iterableMap.ts
|
|
2
|
+
function* iterableMap(iterable, callbackfn, thisArg) {
|
|
3
|
+
let index = 0;
|
|
4
|
+
if (typeof callbackfn !== "function") {
|
|
5
|
+
throw new TypeError(`${callbackfn} is not a function`);
|
|
6
|
+
}
|
|
7
|
+
for (const value of iterable) {
|
|
8
|
+
yield callbackfn.call(thisArg, value, index++, iterable);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
iterableMap
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=chunk-EZC33HE6.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableMap.ts"],"sourcesContent":["/**\n * Calls a defined callback function on each element of an array, and returns an array that contains the results.\n * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\nexport function* iterableMap<T, U>(\n iterable: Iterable<T>,\n callbackfn: (value: T, index: number, array: Iterable<T>) => U,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): IterableIterator<U> {\n let index = 0;\n\n if (typeof callbackfn !== 'function') {\n throw new TypeError(`${callbackfn} is not a function`);\n }\n\n for (const value of iterable) {\n yield callbackfn.call(thisArg, value, index++, iterable);\n }\n}\n"],"mappings":";AAKO,UAAU,YACf,UACA,YAEA,SACqB;AACrB,MAAI,QAAQ;AAEZ,MAAI,OAAO,eAAe,YAAY;AACpC,UAAM,IAAI,UAAU,GAAG,UAAU,oBAAoB;AAAA,EACvD;AAEA,aAAW,SAAS,UAAU;AAC5B,UAAM,WAAW,KAAK,SAAS,OAAO,SAAS,QAAQ;AAAA,EACzD;AACF;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/iterableConcat.ts
|
|
2
|
+
function* iterableConcat(iterable, ...items) {
|
|
3
|
+
yield* iterable;
|
|
4
|
+
for (const item of items) {
|
|
5
|
+
if (item && typeof item === "object" && Symbol.iterator in item) {
|
|
6
|
+
yield* item;
|
|
7
|
+
} else {
|
|
8
|
+
yield item;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
iterableConcat
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=chunk-GWZF5BB7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableConcat.ts"],"sourcesContent":["/**\n * Combines two or more iterables.\n * This method returns a new iterable without modifying any existing iterables.\n *\n * @param items Additional iterables and/or items to add to the end of the iterable.\n */\nexport function iterableConcat<T>(iterable: Iterable<T>, ...items: Iterable<T>[]): IterableIterator<T>;\n\n/**\n * Combines two or more iterables.\n * This method returns a new iterable without modifying any existing iterables.\n *\n * @param items Additional iterables and/or items to add to the end of the iterable.\n */\nexport function iterableConcat<T>(iterable: Iterable<T>, ...items: (T | Iterable<T>)[]): IterableIterator<T>;\n\nexport function* iterableConcat<T>(iterable: Iterable<T>, ...items: (T | Iterable<T>)[]): IterableIterator<T> {\n yield* iterable;\n\n for (const item of items) {\n if (item && typeof item === 'object' && Symbol.iterator in item) {\n yield* item;\n } else {\n yield item;\n }\n }\n}\n"],"mappings":";AAgBO,UAAU,eAAkB,aAA0B,OAAiD;AAC5G,SAAO;AAEP,aAAW,QAAQ,OAAO;AACxB,QAAI,QAAQ,OAAO,SAAS,YAAY,OAAO,YAAY,MAAM;AAC/D,aAAO;AAAA,IACT,OAAO;AACL,YAAM;AAAA,IACR;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/iterableFindIndex.ts
|
|
2
|
+
function iterableFindIndex(iterable, predicate, thisArg) {
|
|
3
|
+
let index = 0;
|
|
4
|
+
if (typeof predicate !== "function") {
|
|
5
|
+
throw new TypeError(`${predicate} is not a function`);
|
|
6
|
+
}
|
|
7
|
+
const boundPredicate = predicate.bind(thisArg);
|
|
8
|
+
for (const value of iterable) {
|
|
9
|
+
if (boundPredicate(value, index, iterable)) {
|
|
10
|
+
return index;
|
|
11
|
+
}
|
|
12
|
+
index++;
|
|
13
|
+
}
|
|
14
|
+
return -1;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
iterableFindIndex
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=chunk-HYU4EN7J.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableFindIndex.ts"],"sourcesContent":["/**\n * Returns the index of the first element in the iterable where predicate is true, and -1\n * otherwise.\n *\n * @param predicate find calls predicate once for each element of the iterable, in ascending\n * order, until it finds one where predicate returns true. If such an element is found,\n * findIndex immediately returns that element index. Otherwise, findIndex returns -1.\n *\n * @param thisArg If provided, it will be used as the this value for each invocation of\n * predicate. If it is not provided, undefined is used instead.\n */\nexport function iterableFindIndex<T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, obj: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): number {\n let index = 0;\n\n if (typeof predicate !== 'function') {\n throw new TypeError(`${predicate} is not a function`);\n }\n\n const boundPredicate = predicate.bind(thisArg);\n\n for (const value of iterable) {\n if (boundPredicate(value, index, iterable)) {\n return index;\n }\n\n index++;\n }\n\n return -1;\n}\n"],"mappings":";AAWO,SAAS,kBACd,UACA,WAEA,SACQ;AACR,MAAI,QAAQ;AAEZ,MAAI,OAAO,cAAc,YAAY;AACnC,UAAM,IAAI,UAAU,GAAG,SAAS,oBAAoB;AAAA,EACtD;AAEA,QAAM,iBAAiB,UAAU,KAAK,OAAO;AAE7C,aAAW,SAAS,UAAU;AAC5B,QAAI,eAAe,OAAO,OAAO,QAAQ,GAAG;AAC1C,aAAO;AAAA,IACT;AAEA;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// src/iterableForEach.ts
|
|
2
|
+
function iterableForEach(iterable, callbackfn, thisArg) {
|
|
3
|
+
let index = 0;
|
|
4
|
+
if (typeof callbackfn !== "function") {
|
|
5
|
+
throw new TypeError(`${callbackfn} is not a function`);
|
|
6
|
+
}
|
|
7
|
+
const boundCallbackfn = callbackfn.bind(thisArg);
|
|
8
|
+
for (const value of iterable) {
|
|
9
|
+
boundCallbackfn(value, index++, iterable);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
iterableForEach
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=chunk-JU353VSE.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableForEach.ts"],"sourcesContent":["/**\n * Performs the specified action for each element in an iterable.\n *\n * @param callbackfn A function that accepts up to three arguments. forEach calls the callbackfn function one time for each element in the iterable.\n *\n * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.\n */\nexport function iterableForEach<T>(\n iterable: Iterable<T>,\n callbackfn: (value: T, index: number, iterable: Iterable<T>) => void,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): void {\n let index = 0;\n\n if (typeof callbackfn !== 'function') {\n throw new TypeError(`${callbackfn} is not a function`);\n }\n\n const boundCallbackfn = callbackfn.bind(thisArg);\n\n for (const value of iterable) {\n boundCallbackfn(value, index++, iterable);\n }\n}\n"],"mappings":";AAOO,SAAS,gBACd,UACA,YAEA,SACM;AACN,MAAI,QAAQ;AAEZ,MAAI,OAAO,eAAe,YAAY;AACpC,UAAM,IAAI,UAAU,GAAG,UAAU,oBAAoB;AAAA,EACvD;AAEA,QAAM,kBAAkB,WAAW,KAAK,OAAO;AAE/C,aAAW,SAAS,UAAU;AAC5B,oBAAgB,OAAO,SAAS,QAAQ;AAAA,EAC1C;AACF;","names":[]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toIntegerOrInfinity
|
|
3
|
+
} from "./chunk-W5NEOEVE.mjs";
|
|
4
|
+
|
|
5
|
+
// src/iterableSlice.ts
|
|
6
|
+
function* iterableSlice(iterable, start = 0, end = Infinity) {
|
|
7
|
+
let index = 0;
|
|
8
|
+
start = toIntegerOrInfinity(start);
|
|
9
|
+
start = start === -Infinity ? 0 : start;
|
|
10
|
+
end = toIntegerOrInfinity(end);
|
|
11
|
+
end = end === -Infinity ? 0 : end;
|
|
12
|
+
if (start < 0) {
|
|
13
|
+
throw new TypeError("start cannot be a negative finite number");
|
|
14
|
+
}
|
|
15
|
+
if (end < 0) {
|
|
16
|
+
throw new TypeError("end cannot be a negative finite number");
|
|
17
|
+
}
|
|
18
|
+
if (start === Infinity) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
for (const item of iterable) {
|
|
22
|
+
if (index >= start && index < end) {
|
|
23
|
+
yield item;
|
|
24
|
+
}
|
|
25
|
+
index++;
|
|
26
|
+
if (index > end) {
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
iterableSlice
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=chunk-KONB7TV6.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableSlice.ts"],"sourcesContent":["import toIntegerOrInfinity from './private/toIntegerOrInfinity';\n\n/**\n * Returns a copy of a section of an iterable.\n * For both start and end, a negative index can be used to indicate an offset from the end of the iterable.\n * For example, -2 refers to the second to last element of the iterable.\n *\n * @param start The beginning index of the specified portion of the iterable.\n * If start is undefined, then the slice begins at index 0.\n *\n * @param end The end index of the specified portion of the iterable. This is exclusive of the element at the index 'end'.\n * If end is undefined, then the slice extends to the end of the iterable.\n */\nexport function* iterableSlice<T>(iterable: Iterable<T>, start: number = 0, end: number = Infinity): Iterable<T> {\n let index = 0;\n\n start = toIntegerOrInfinity(start);\n start = start === -Infinity ? 0 : start;\n end = toIntegerOrInfinity(end);\n end = end === -Infinity ? 0 : end;\n\n if (start < 0) {\n throw new TypeError('start cannot be a negative finite number');\n }\n\n if (end < 0) {\n throw new TypeError('end cannot be a negative finite number');\n }\n\n if (start === Infinity) {\n return;\n }\n\n for (const item of iterable) {\n if (index >= start && index < end) {\n yield item;\n }\n\n index++;\n\n if (index > end) {\n break;\n }\n }\n}\n"],"mappings":";;;;;AAaO,UAAU,cAAiB,UAAuB,QAAgB,GAAG,MAAc,UAAuB;AAC/G,MAAI,QAAQ;AAEZ,UAAQ,oBAAoB,KAAK;AACjC,UAAQ,UAAU,YAAY,IAAI;AAClC,QAAM,oBAAoB,GAAG;AAC7B,QAAM,QAAQ,YAAY,IAAI;AAE9B,MAAI,QAAQ,GAAG;AACb,UAAM,IAAI,UAAU,0CAA0C;AAAA,EAChE;AAEA,MAAI,MAAM,GAAG;AACX,UAAM,IAAI,UAAU,wCAAwC;AAAA,EAC9D;AAEA,MAAI,UAAU,UAAU;AACtB;AAAA,EACF;AAEA,aAAW,QAAQ,UAAU;AAC3B,QAAI,SAAS,SAAS,QAAQ,KAAK;AACjC,YAAM;AAAA,IACR;AAEA;AAEA,QAAI,QAAQ,KAAK;AACf;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toIntegerOrInfinity
|
|
3
|
+
} from "./chunk-W5NEOEVE.mjs";
|
|
4
|
+
|
|
5
|
+
// src/iterableAt.ts
|
|
6
|
+
function iterableAt(iterable, index) {
|
|
7
|
+
let currentIndex = 0;
|
|
8
|
+
index = toIntegerOrInfinity(index);
|
|
9
|
+
if (!isFinite(index)) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (index < 0) {
|
|
13
|
+
throw new TypeError("index cannot be a negative finite number");
|
|
14
|
+
}
|
|
15
|
+
for (const value of iterable) {
|
|
16
|
+
if (currentIndex++ === index) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
iterableAt
|
|
25
|
+
};
|
|
26
|
+
//# sourceMappingURL=chunk-MDBK7ND5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableAt.ts"],"sourcesContent":["import toIntegerOrInfinity from './private/toIntegerOrInfinity';\n\n/**\n * Returns the item located at the specified index.\n *\n * @param index The zero-based index of the desired code unit. A negative index will count back from the last item.\n */\nexport function iterableAt<T>(iterable: Iterable<T>, index: number): T | undefined {\n let currentIndex = 0;\n\n index = toIntegerOrInfinity(index);\n\n if (!isFinite(index)) {\n return;\n }\n\n if (index < 0) {\n throw new TypeError('index cannot be a negative finite number');\n }\n\n for (const value of iterable) {\n if (currentIndex++ === index) {\n return value;\n }\n }\n\n return undefined;\n}\n"],"mappings":";;;;;AAOO,SAAS,WAAc,UAAuB,OAA8B;AACjF,MAAI,eAAe;AAEnB,UAAQ,oBAAoB,KAAK;AAEjC,MAAI,CAAC,SAAS,KAAK,GAAG;AACpB;AAAA,EACF;AAEA,MAAI,QAAQ,GAAG;AACb,UAAM,IAAI,UAAU,0CAA0C;AAAA,EAChE;AAEA,aAAW,SAAS,UAAU;AAC5B,QAAI,mBAAmB,OAAO;AAC5B,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/iteratorToIterable.ts
|
|
2
|
+
function iteratorToIterable(iterator) {
|
|
3
|
+
const iterableIterator = {
|
|
4
|
+
[Symbol.iterator]: () => iterableIterator,
|
|
5
|
+
next: iterator.next.bind(iterator),
|
|
6
|
+
...iterator.return ? { return: iterator.return.bind(iterator) } : {},
|
|
7
|
+
...iterator.throw ? { throw: iterator.throw.bind(iterator) } : {}
|
|
8
|
+
};
|
|
9
|
+
return iterableIterator;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
iteratorToIterable
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=chunk-MNDAEMYM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iteratorToIterable.ts"],"sourcesContent":["export function iteratorToIterable<T>(iterator: Iterator<T>): IterableIterator<T> {\n const iterableIterator: IterableIterator<T> = {\n [Symbol.iterator]: () => iterableIterator,\n next: iterator.next.bind(iterator),\n ...(iterator.return ? { return: iterator.return.bind(iterator) } : {}),\n ...(iterator.throw ? { throw: iterator.throw.bind(iterator) } : {})\n };\n\n return iterableIterator;\n}\n"],"mappings":";AAAO,SAAS,mBAAsB,UAA4C;AAChF,QAAM,mBAAwC;AAAA,IAC5C,CAAC,OAAO,QAAQ,GAAG,MAAM;AAAA,IACzB,MAAM,SAAS,KAAK,KAAK,QAAQ;AAAA,IACjC,GAAI,SAAS,SAAS,EAAE,QAAQ,SAAS,OAAO,KAAK,QAAQ,EAAE,IAAI,CAAC;AAAA,IACpE,GAAI,SAAS,QAAQ,EAAE,OAAO,SAAS,MAAM,KAAK,QAAQ,EAAE,IAAI,CAAC;AAAA,EACnE;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/iterableFind.ts
|
|
2
|
+
function iterableFind(iterable, predicate, thisArg) {
|
|
3
|
+
let index = 0;
|
|
4
|
+
if (typeof predicate !== "function") {
|
|
5
|
+
throw new TypeError(`${predicate} is not a function`);
|
|
6
|
+
}
|
|
7
|
+
const boundPredicate = predicate.bind(thisArg);
|
|
8
|
+
for (const value of iterable) {
|
|
9
|
+
if (boundPredicate(value, index++, iterable)) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return void 0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
iterableFind
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=chunk-MNLOWKTC.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableFind.ts"],"sourcesContent":["/**\n * Returns the value of the first element in the iterable where predicate is true, and undefined\n * otherwise.\n *\n * @param predicate find calls predicate once for each element of the iterable, in ascending\n * order, until it finds one where predicate returns true. If such an element is found, find\n * immediately returns that element value. Otherwise, find returns undefined.\n *\n * @param thisArg If provided, it will be used as the this value for each invocation of\n * predicate. If it is not provided, undefined is used instead.\n */\nexport function iterableFind<T, S extends T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, obj: Iterable<T>) => value is S,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): S | undefined;\n\nexport function iterableFind<T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, obj: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): T | undefined;\n\nexport function iterableFind<T, S extends T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, obj: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): S | undefined {\n let index = 0;\n\n if (typeof predicate !== 'function') {\n throw new TypeError(`${predicate} is not a function`);\n }\n\n const boundPredicate = predicate.bind(thisArg);\n\n for (const value of iterable) {\n if (boundPredicate(value, index++, iterable)) {\n return value as S;\n }\n }\n\n return undefined;\n}\n"],"mappings":";AAyBO,SAAS,aACd,UACA,WAEA,SACe;AACf,MAAI,QAAQ;AAEZ,MAAI,OAAO,cAAc,YAAY;AACnC,UAAM,IAAI,UAAU,GAAG,SAAS,oBAAoB;AAAA,EACtD;AAEA,QAAM,iBAAiB,UAAU,KAAK,OAAO;AAE7C,aAAW,SAAS,UAAU;AAC5B,QAAI,eAAe,OAAO,SAAS,QAAQ,GAAG;AAC5C,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// src/iterableFindLastIndex.ts
|
|
2
|
+
function iterableFindLastIndex(iterable, predicate, thisArg) {
|
|
3
|
+
let index = 0;
|
|
4
|
+
let lastIndex = -1;
|
|
5
|
+
if (typeof predicate !== "function") {
|
|
6
|
+
throw new TypeError(`${predicate} is not a function`);
|
|
7
|
+
}
|
|
8
|
+
const boundPredicate = predicate.bind(thisArg);
|
|
9
|
+
for (const value of iterable) {
|
|
10
|
+
if (boundPredicate(value, index, iterable)) {
|
|
11
|
+
lastIndex = index;
|
|
12
|
+
}
|
|
13
|
+
index++;
|
|
14
|
+
}
|
|
15
|
+
return lastIndex;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
iterableFindLastIndex
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=chunk-TEI3K6GT.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableFindLastIndex.ts"],"sourcesContent":["/**\n * Returns the index of the last element in the iterable where predicate is true, and -1\n * otherwise.\n *\n * @param predicate findLastIndex calls predicate once for each element of the iterable, in descending\n * order, until it finds one where predicate returns true. If such an element is found,\n * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.\n *\n * @param thisArg If provided, it will be used as the this value for each invocation of\n * predicate. If it is not provided, undefined is used instead.\n */\nexport function iterableFindLastIndex<T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): number {\n let index = 0;\n let lastIndex: number = -1;\n\n if (typeof predicate !== 'function') {\n throw new TypeError(`${predicate} is not a function`);\n }\n\n const boundPredicate = predicate.bind(thisArg);\n\n for (const value of iterable) {\n if (boundPredicate(value, index, iterable)) {\n lastIndex = index;\n }\n\n index++;\n }\n\n return lastIndex;\n}\n"],"mappings":";AAWO,SAAS,sBACd,UACA,WAEA,SACQ;AACR,MAAI,QAAQ;AACZ,MAAI,YAAoB;AAExB,MAAI,OAAO,cAAc,YAAY;AACnC,UAAM,IAAI,UAAU,GAAG,SAAS,oBAAoB;AAAA,EACtD;AAEA,QAAM,iBAAiB,UAAU,KAAK,OAAO;AAE7C,aAAW,SAAS,UAAU;AAC5B,QAAI,eAAe,OAAO,OAAO,QAAQ,GAAG;AAC1C,kBAAY;AAAA,IACd;AAEA;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
toIntegerOrInfinity
|
|
3
|
+
} from "./chunk-W5NEOEVE.mjs";
|
|
4
|
+
|
|
5
|
+
// src/iterableIndexOf.ts
|
|
6
|
+
function iterableIndexOf(iterable, searchElement, fromIndex = 0) {
|
|
7
|
+
let index = 0;
|
|
8
|
+
fromIndex = toIntegerOrInfinity(fromIndex);
|
|
9
|
+
if (fromIndex !== Infinity) {
|
|
10
|
+
fromIndex = fromIndex === -Infinity ? 0 : fromIndex;
|
|
11
|
+
if (fromIndex < 0) {
|
|
12
|
+
throw new TypeError("fromIndex cannot be a negative finite number");
|
|
13
|
+
}
|
|
14
|
+
for (const item of iterable) {
|
|
15
|
+
if (index >= fromIndex && Object.is(item, searchElement)) {
|
|
16
|
+
return index;
|
|
17
|
+
}
|
|
18
|
+
index++;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return -1;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export {
|
|
25
|
+
iterableIndexOf
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=chunk-UIEKIMLW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableIndexOf.ts"],"sourcesContent":["import toIntegerOrInfinity from './private/toIntegerOrInfinity';\n\n/**\n * Returns the index of the first occurrence of a value in an iterable, or -1 if it is not present.\n *\n * @param searchElement The value to locate in the iterable.\n * @param fromIndex The iterable index at which to begin the search. If fromIndex is omitted, the search starts at index 0.\n */\nexport function iterableIndexOf<T>(iterable: Iterable<T>, searchElement: T, fromIndex: number = 0): number {\n let index = 0;\n\n fromIndex = toIntegerOrInfinity(fromIndex);\n\n if (fromIndex !== Infinity) {\n fromIndex = fromIndex === -Infinity ? 0 : fromIndex;\n\n if (fromIndex < 0) {\n // TODO: Support negative fromIndex.\n throw new TypeError('fromIndex cannot be a negative finite number');\n }\n\n for (const item of iterable) {\n if (index >= fromIndex && Object.is(item, searchElement)) {\n return index;\n }\n\n index++;\n }\n }\n\n return -1;\n}\n"],"mappings":";;;;;AAQO,SAAS,gBAAmB,UAAuB,eAAkB,YAAoB,GAAW;AACzG,MAAI,QAAQ;AAEZ,cAAY,oBAAoB,SAAS;AAEzC,MAAI,cAAc,UAAU;AAC1B,gBAAY,cAAc,YAAY,IAAI;AAE1C,QAAI,YAAY,GAAG;AAEjB,YAAM,IAAI,UAAU,8CAA8C;AAAA,IACpE;AAEA,eAAW,QAAQ,UAAU;AAC3B,UAAI,SAAS,aAAa,OAAO,GAAG,MAAM,aAAa,GAAG;AACxD,eAAO;AAAA,MACT;AAEA;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// src/iterableFindLast.ts
|
|
2
|
+
function iterableFindLast(iterable, predicate, thisArg) {
|
|
3
|
+
let index = 0;
|
|
4
|
+
let last;
|
|
5
|
+
if (typeof predicate !== "function") {
|
|
6
|
+
throw new TypeError(`${predicate} is not a function`);
|
|
7
|
+
}
|
|
8
|
+
const boundPredicate = predicate.bind(thisArg);
|
|
9
|
+
for (const value of iterable) {
|
|
10
|
+
if (boundPredicate(value, index++, iterable)) {
|
|
11
|
+
last = value;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
return last;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
iterableFindLast
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=chunk-V6OWQQ3Q.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/iterableFindLast.ts"],"sourcesContent":["/**\n * Returns the value of the last element in the iterable where predicate is true, and undefined\n * otherwise.\n *\n * @param predicate findLast calls predicate once for each element of the iterable, in descending\n * order, until it finds one where predicate returns true. If such an element is found, findLast\n * immediately returns that element value. Otherwise, findLast returns undefined.\n *\n * @param thisArg If provided, it will be used as the this value for each invocation of\n * predicate. If it is not provided, undefined is used instead.\n */\nexport function iterableFindLast<T, S extends T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => value is S,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): S | undefined;\n\nexport function iterableFindLast<T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): T | undefined;\n\nexport function iterableFindLast<T, S extends T>(\n iterable: Iterable<T>,\n predicate: (value: T, index: number, iterable: Iterable<T>) => unknown,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n thisArg?: any\n): S | undefined {\n let index = 0;\n let last: S | undefined;\n\n if (typeof predicate !== 'function') {\n throw new TypeError(`${predicate} is not a function`);\n }\n\n const boundPredicate = predicate.bind(thisArg);\n\n for (const value of iterable) {\n if (boundPredicate(value, index++, iterable)) {\n last = value as S;\n }\n }\n\n return last;\n}\n"],"mappings":";AAyBO,SAAS,iBACd,UACA,WAEA,SACe;AACf,MAAI,QAAQ;AACZ,MAAI;AAEJ,MAAI,OAAO,cAAc,YAAY;AACnC,UAAM,IAAI,UAAU,GAAG,SAAS,oBAAoB;AAAA,EACtD;AAEA,QAAM,iBAAiB,UAAU,KAAK,OAAO;AAE7C,aAAW,SAAS,UAAU;AAC5B,QAAI,eAAe,OAAO,SAAS,QAAQ,GAAG;AAC5C,aAAO;AAAA,IACT;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// src/private/toIntegerOrInfinity.ts
|
|
2
|
+
function toIntegerOrInfinity(value) {
|
|
3
|
+
if (value === Infinity || value === -Infinity) {
|
|
4
|
+
return value;
|
|
5
|
+
}
|
|
6
|
+
return ~~value;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export {
|
|
10
|
+
toIntegerOrInfinity
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=chunk-W5NEOEVE.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/private/toIntegerOrInfinity.ts"],"sourcesContent":["export default function toIntegerOrInfinity(value: number): number {\n if (value === Infinity || value === -Infinity) {\n return value;\n }\n\n return ~~value;\n}\n"],"mappings":";AAAe,SAAR,oBAAqC,OAAuB;AACjE,MAAI,UAAU,YAAY,UAAU,WAAW;AAC7C,WAAO;AAAA,EACT;AAEA,SAAO,CAAC,CAAC;AACX;","names":[]}
|