Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// TODO: See "iteratorKind" in https://tc39.es/ecma262/#sec-runtime-semantics-forin-div-ofbodyevaluation-lhs-stmt-iterator-lhskind-labelset – see how it loops and validates the returned values
// TODO: THERE'S ACTUALLY A "throw" method MENTION IN https://tc39.es/ecma262/#sec-generator-function-definitions-runtime-semantics-evaluation: "NOTE: Exceptions from the inner iterator throw method are propagated. Normal completions from an inner throw method are processed similarly to an inner next." THOUGH NOT SURE HOW TO TRIGGER IT IN PRACTICE, SEE yield.spec.js

import { isType, typesafeIsArray } from '@voxpelli/typed-utils';
import { findLeastTargeted } from './lib/find-least-targeted.js';
import { arrayDeleteInPlace, makeIterableAsync } from './lib/misc.js';
import { isAsyncIterable, isIterable, isPartOfArray } from './lib/type-checks.js';
Expand Down Expand Up @@ -51,8 +52,8 @@ export function bufferedAsyncMap (input, callback, options) {

if (!input) throw new TypeError('Expected input to be provided');
if (!isAsyncIterable(asyncIterable)) throw new TypeError('Expected asyncIterable to have a Symbol.asyncIterator function');
if (typeof callback !== 'function') throw new TypeError('Expected callback to be a function');
if (typeof bufferSize !== 'number') throw new TypeError('Expected bufferSize to be a number');
if (!isType(callback, 'function')) throw new TypeError('Expected callback to be a function');
if (!isType(bufferSize, 'number')) throw new TypeError('Expected bufferSize to be a number');

/** @type {AsyncIterator<T, unknown>} */
const asyncIterator = asyncIterable[Symbol.asyncIterator]();
Expand Down Expand Up @@ -130,7 +131,7 @@ export function bufferedAsyncMap (input, callback, options) {
err: err instanceof Error ? err : new Error('Unknown subiterator error'),
}))
.then(async result => {
if (typeof result !== 'object') {
if (!isType(result, 'object')) {
throw new TypeError('Expected an object value');
}
if ('err' in result || result.done) {
Expand All @@ -155,7 +156,7 @@ export function bufferedAsyncMap (input, callback, options) {
err: err instanceof Error ? err : new Error('Unknown iterator error'),
}))
.then(async result => {
if (typeof result !== 'object') {
if (!isType(result, 'object')) {
throw new TypeError('Expected an object value');
}
if ('err' in result || result.done) {
Expand Down
4 changes: 3 additions & 1 deletion lib/type-checks.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { guardedArrayIncludes } from '@voxpelli/typed-utils';

/**
* @param {unknown} value
* @returns {value is Iterable<unknown>}
Expand All @@ -16,4 +18,4 @@ export const isAsyncIterable = (value) => Boolean(value && typeof value === 'obj
* @param {Values[]} list
* @returns {value is Values}
*/
export const isPartOfArray = (value, list) => list.includes(/** @type {Values} */ (value));
export const isPartOfArray = (value, list) => guardedArrayIncludes(list, value);
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"author": "Pelle Wessman <pelle@kodfabrik.se> (http://kodfabrik.se/)",
"license": "MIT",
"engines": {
"node": ">=18.6.0"
"node": "^20.11.0 || >=22.0.0"
},
"type": "module",
"exports": "./index.js",
Expand Down Expand Up @@ -71,5 +71,8 @@
"type-coverage": "^2.29.1",
"typescript": "~5.5.3",
"validate-conventional-commit": "^1.0.4"
},
"dependencies": {
"@voxpelli/typed-utils": "^2.6.0"
}
}