New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

ai-filter

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ai-filter - npm Package Compare versions

Comparing version 1.0.2 to 1.1.0

41

index.js
import isAsyncIterable from "is-async-iterable";
import AsyncIterable from "asynciterable";

@@ -17,21 +18,31 @@ /**

*/
export default async function* filter(predicate, data) {
if (typeof predicate !== "function") {
throw new TypeError("predicate argument must be a function.");
}
export default function filter(predicate, data) {
return new AsyncIterable(async (write, end) => {
if (typeof predicate !== "function") {
throw new TypeError("predicate argument must be a function.");
}
if (typeof data === "undefined") {
return filter.bind(null, predicate);
}
if (typeof data === "undefined") {
return filter.bind(null, predicate);
}
if (!isAsyncIterable(data)) {
throw new TypeError("data argument must be an iterable or async-iterable.");
}
if (!isAsyncIterable(data)) {
throw new TypeError(
"data argument must be an iterable or async-iterable."
);
}
let index = 0;
for await (const item of data) {
if (await predicate(item, index++, data)) {
yield item;
const generator = data[Symbol.asyncIterator] || data[Symbol.iterator];
const iterator = generator.call(data);
let index = 0;
let item = await iterator.next();
while (!item.done) {
if (await predicate(await item.value, index, data)) {
write(item.value);
}
index++;
item = await iterator.next();
}
}
end();
});
}
{
"name": "ai-filter",
"version": "1.0.2",
"version": "1.1.0",
"description": "Filter over async iterables.",

@@ -13,3 +13,3 @@ "repository": "parro-it/ai-filter",

"scripts": {
"test": "node --harmony_async_iteration -r @std/esm test.js | tap-colorize - && linterjs .",
"test": "node -r @std/esm test.js | tap-colorize - && linterjs .",
"doc": "documentation readme index.js --section=API"

@@ -28,5 +28,5 @@ },

"@std/esm": "^0.16.0",
"ai-concat": "^1.0.0",
"ai-concat": "^1.3.0",
"ai-from-stream": "^1.0.0",
"ai-lines": "^1.0.0",
"ai-lines": "^1.1.0",
"asynciterable": "^1.0.1",

@@ -39,4 +39,5 @@ "documentation": "^5.3.3",

"dependencies": {
"asynciterable": "^1.0.1",
"is-async-iterable": "^1.0.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc