Skip to main content

@mel/core@0.1.2

latest

core utilities

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
88%
Published
4 months ago (0.1.2)
function filterObject
filterObject<T extends object>(
obj: T,
fn: (
entry: Entry<T>,
i: number,
arr: Entry<T>[],
) => boolean
,
): Partial<T>

Filters the entries of an object based on a provided function.

Examples

Example 1

const obj = { a: 1, b: 2, c: 3 }; const result = filterObject(obj, ([key, value]) => value > 1); console.log(result); // Output: { b: 2, c: 3 }

Type Parameters

T extends object
  • The type of the object to be filtered.

Parameters

obj: T
  • The object to be filtered.
fn: (
entry: Entry<T>,
i: number,
arr: Entry<T>[],
) => boolean
  • The function to test each entry of the object. It receives the current entry, the index of the entry, and the array of all entries.

Return Type

Partial<T>
  • A new object with only the entries that pass the test implemented by the provided function.

Add Package

deno add jsr:@mel/core

Import symbol

import { filterObject } from "@mel/core";

---- OR ----

Import directly with a jsr specifier

import { filterObject } from "jsr:@mel/core";

Add Package

npx jsr add @mel/core

Import symbol

import { filterObject } from "@mel/core";

Add Package

yarn dlx jsr add @mel/core

Import symbol

import { filterObject } from "@mel/core";

Add Package

pnpm dlx jsr add @mel/core

Import symbol

import { filterObject } from "@mel/core";

Add Package

bunx jsr add @mel/core

Import symbol

import { filterObject } from "@mel/core";