@reliverse/mapkit 2.2.8 → 2.3.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/dist/mod.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- type BaseOptions = {
1
+ interface BaseOptions {
2
2
  /**
3
3
  * Number of concurrently pending promises returned by `mapkit`.
4
4
  *
@@ -7,7 +7,7 @@ type BaseOptions = {
7
7
  * @default Infinity
8
8
  */
9
9
  readonly concurrency?: number;
10
- };
10
+ }
11
11
  export type Options = BaseOptions & {
12
12
  /**
13
13
  * When `true`, the first mapkit rejection will be rejected back to the consumer.
@@ -58,7 +58,7 @@ export type mapkit<Element = unknown, NewElement = unknown> = (element: Element,
58
58
  * Return this value from a `mapkit` function to skip including the value in the
59
59
  * returned array.
60
60
  */
61
- export declare const pMapSkip: unique symbol;
61
+ export declare const pMapSkip: any;
62
62
  /**
63
63
  * @param input - Synchronous or asynchronous iterable that is iterated over
64
64
  * concurrently, calling the `mapkit` function for each element. Each iterated
@@ -71,7 +71,7 @@ export declare const pMapSkip: unique symbol;
71
71
  * reject. The fulfilled value is an `Array` of the fulfilled values returned
72
72
  * from `mapkit` in `input` order, excluding `pMapSkip`.
73
73
  */
74
- export default function pMap<Element, NewElement>(input: AsyncIterable<Element | Promise<Element>> | Iterable<Element | Promise<Element>>, mapkit: mapkit<Element, NewElement>, options?: Options): Promise<Array<Exclude<NewElement, typeof pMapSkip>>>;
74
+ export default function pMap<Element, NewElement>(input: AsyncIterable<Element | Promise<Element>> | Iterable<Element | Promise<Element>>, mapkit: mapkit<Element, NewElement>, options?: Options): Promise<Exclude<NewElement, typeof pMapSkip>[]>;
75
75
  /**
76
76
  * @param input - Synchronous or asynchronous iterable that is iterated over
77
77
  * concurrently, calling the `mapkit` function for each element. Each iterated
package/dist/mod.js CHANGED
@@ -1,10 +1,6 @@
1
1
  export const pMapSkip = /* @__PURE__ */ Symbol("skip");
2
2
  export default async function pMap(input, mapkit, options = {}) {
3
- const {
4
- concurrency = Number.POSITIVE_INFINITY,
5
- stopOnError = true,
6
- signal
7
- } = options;
3
+ const { concurrency = Number.POSITIVE_INFINITY, stopOnError = true, signal } = options;
8
4
  if (!("Symbol" in globalThis) || input[Symbol.iterator] === void 0 && input[Symbol.asyncIterator] === void 0) {
9
5
  throw new TypeError(
10
6
  `Expected \`input\` to be either an \`Iterable\` or \`AsyncIterable\`, got (${typeof input})`
@@ -30,7 +26,9 @@ export default async function pMap(input, mapkit, options = {}) {
30
26
  let isPumping = false;
31
27
  let iteratorClosed = false;
32
28
  const safeCloseIterator = async () => {
33
- if (iteratorClosed) return;
29
+ if (iteratorClosed) {
30
+ return;
31
+ }
34
32
  const ret = iterator?.return;
35
33
  if (typeof ret === "function") {
36
34
  try {
@@ -43,7 +41,9 @@ export default async function pMap(input, mapkit, options = {}) {
43
41
  }
44
42
  };
45
43
  const onAbort = () => {
46
- if (isSettled) return;
44
+ if (isSettled) {
45
+ return;
46
+ }
47
47
  isSettled = true;
48
48
  void safeCloseIterator();
49
49
  cleanup();
@@ -73,9 +73,15 @@ export default async function pMap(input, mapkit, options = {}) {
73
73
  resolve(out);
74
74
  }
75
75
  function checkCompletion() {
76
- if (isSettled) return;
77
- if (!isIterableDone) return;
78
- if (activeCount > 0) return;
76
+ if (isSettled) {
77
+ return;
78
+ }
79
+ if (!isIterableDone) {
80
+ return;
81
+ }
82
+ if (activeCount > 0) {
83
+ return;
84
+ }
79
85
  isSettled = true;
80
86
  if (settleWithAggregateIfNeeded()) {
81
87
  return;
@@ -90,7 +96,9 @@ export default async function pMap(input, mapkit, options = {}) {
90
96
  results[index] = result;
91
97
  }
92
98
  } catch (error) {
93
- if (isSettled) return;
99
+ if (isSettled) {
100
+ return;
101
+ }
94
102
  if (stopOnError) {
95
103
  isSettled = true;
96
104
  void safeCloseIterator();
@@ -108,10 +116,12 @@ export default async function pMap(input, mapkit, options = {}) {
108
116
  }
109
117
  }
110
118
  async function pump() {
111
- if (isSettled || isPumping) return;
119
+ if (isSettled || isPumping) {
120
+ return;
121
+ }
112
122
  isPumping = true;
113
123
  try {
114
- while (!isSettled && !isIterableDone && activeCount < concurrency) {
124
+ while (!(isSettled || isIterableDone) && activeCount < concurrency) {
115
125
  let next;
116
126
  try {
117
127
  next = iterator.next();
@@ -171,7 +181,9 @@ export function pMapIterable(input, mapkit, options = {}) {
171
181
  let pulling = false;
172
182
  let iteratorClosed = false;
173
183
  const safeCloseIterator = async () => {
174
- if (iteratorClosed) return;
184
+ if (iteratorClosed) {
185
+ return;
186
+ }
175
187
  const ret = iterator?.return;
176
188
  if (typeof ret === "function") {
177
189
  try {
@@ -184,7 +196,9 @@ export function pMapIterable(input, mapkit, options = {}) {
184
196
  }
185
197
  };
186
198
  const schedulePull = () => {
187
- if (pulling || isDone) return;
199
+ if (pulling || isDone) {
200
+ return;
201
+ }
188
202
  pulling = true;
189
203
  (async () => {
190
204
  try {
package/package.json CHANGED
@@ -1,7 +1,12 @@
1
1
  {
2
2
  "name": "@reliverse/mapkit",
3
- "version": "2.2.8",
3
+ "version": "2.3.1",
4
4
  "private": false,
5
+ "license": "MIT",
6
+ "files": [
7
+ "dist",
8
+ "package.json"
9
+ ],
5
10
  "type": "module",
6
11
  "exports": {
7
12
  ".": {
@@ -12,10 +17,5 @@
12
17
  "publishConfig": {
13
18
  "access": "public"
14
19
  },
15
- "dependencies": {},
16
- "files": [
17
- "dist",
18
- "package.json"
19
- ],
20
- "license": "MIT"
20
+ "dependencies": {}
21
21
  }