Add some more argument validation

This commit is contained in:
David Payr
2024-12-29 02:21:54 +01:00
parent b7d8c526da
commit cc87dbfcf9
12 changed files with 340 additions and 39 deletions
+6
View File
@@ -239,3 +239,9 @@ export const toAsyncIterator = async function* <T>(source: AnyIterable<T>): Asyn
yield* source[Symbol.asyncIterator]();
}
};
export const validateAnyIterable = (iterable: AnyIterable<unknown>) => {
if (!(Symbol.iterator in iterable) && !(Symbol.asyncIterator in iterable)) {
throw new TypeError('Argument must be an iterable or async iterable.');
}
};