Skip to main content

Built and signed on GitHub Actions

This package works with Node.js, DenoIt is unknown whether this package works with Cloudflare Workers, Bun, Browsers
It is unknown whether this package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
It is unknown whether this package works with Bun
It is unknown whether this package works with Browsers
JSR Score
94%
Published
2 days ago (0.1.0)
function filter
filter<T>(fn: (chunk: T) => boolean | Promise<boolean>): ReadableWritablePair<T>

Filter stream chunks based on a predicate function.

Examples

Example 1

const onlyEven = filter(num => num % 2 === 0);

Example 2

const onlyStrings = filter(item => typeof item === 'string');

Example 3

const onlyPositive = filter(num => num > 0);

Type Parameters

Parameters

fn: (chunk: T) => boolean | Promise<boolean>

The predicate function, that will be applied to each chunk. If the function returns true, the chunk will be passed through.

Return Type

ReadableWritablePair<T>

A readable stream whose chunks are the ones that passed the predicate function

Add Package

deno add jsr:@sgmonda/qfu

Import symbol

import { filter } from "@sgmonda/qfu";

---- OR ----

Import directly with a jsr specifier

import { filter } from "jsr:@sgmonda/qfu";

Add Package

npx jsr add @sgmonda/qfu

Import symbol

import { filter } from "@sgmonda/qfu";

Add Package

yarn dlx jsr add @sgmonda/qfu

Import symbol

import { filter } from "@sgmonda/qfu";

Add Package

pnpm dlx jsr add @sgmonda/qfu

Import symbol

import { filter } from "@sgmonda/qfu";

Add Package

bunx jsr add @sgmonda/qfu

Import symbol

import { filter } from "@sgmonda/qfu";