npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@jlhv/object-helper

v1.0.1

Published

A simple utility library for object manipulation.

Downloads

9

Readme

Object Helper Library

A collection of utility functions for common object operations in TypeScript.

Installation

To install the package, use:

npm install @jlhv/object-helper

Usage

Import the library and use its functions:

import * as ObjectHelper from "@jlhv/object-helper";

const obj = { a: 1, b: 2, c: 3 };
console.log(ObjectHelper.isEmpty(obj)); // false

API Reference

isEmpty(obj: Record<string, any>): boolean

Checks if an object is empty.

ObjectHelper.isEmpty({}); // true
ObjectHelper.isEmpty({ key: "value" }); // false

merge<T, U>(obj1: T, obj2: U): T & U

Merges two objects without modifying the originals.

const merged = ObjectHelper.merge({ a: 1 }, { b: 2 });
console.log(merged); // { a: 1, b: 2 }

deepClone<T>(obj: T): T

Creates a deep copy of an object.

const original = { a: { b: 2 } };
const copy = ObjectHelper.deepClone(original);
console.log(copy); // { a: { b: 2 } }

pick<T, K extends keyof T>(obj: T, keys: K[]): Pick<T, K>

Picks specific keys from an object.

const obj = { a: 1, b: 2, c: 3 };
console.log(ObjectHelper.pick(obj, ["a", "c"])); // { a: 1, c: 3 }

omit<T, K extends keyof T>(obj: T, keys: K[]): Omit<T, K>

Omits specific keys from an object.

console.log(ObjectHelper.omit({ a: 1, b: 2, c: 3 }, ["b"])); // { a: 1, c: 3 }

isEqual<T>(obj1: T, obj2: T): boolean

Checks if two objects are equal (shallow comparison).

ObjectHelper.isEqual({ a: 1 }, { a: 1 }); // true
ObjectHelper.isEqual({ a: 1 }, { a: 2 }); // false

hasNested(obj: Record<string, any>, path: string): boolean

Checks if an object has a nested property.

const obj = { a: { b: { c: 42 } } };
console.log(ObjectHelper.hasNested(obj, "a.b.c")); // true
console.log(ObjectHelper.hasNested(obj, "a.x.y")); // false

getNested<T>(obj: Record<string, any>, path: string, defaultValue?: T): T | undefined

Safely retrieves a nested property.

console.log(ObjectHelper.getNested({ a: { b: { c: 42 } } }, "a.b.c")); // 42
console.log(ObjectHelper.getNested({ a: { b: { c: 42 } } }, "a.x.y", "default")); // "default"

setNested<T>(obj: Record<string, any>, path: string, value: T): void

Sets a nested property in an object.

const obj = { a: { b: {} } };
ObjectHelper.setNested(obj, "a.b.d", 100);
console.log(obj.a.b.d); // 100

invert<T>(obj: T): Record<string, keyof T>

Swaps keys and values in an object.

console.log(ObjectHelper.invert({ a: 1, b: 2 })); // { "1": "a", "2": "b" }

toPairs<T>(obj: T): [keyof T, T[keyof T]][]

Converts an object to an array of key-value pairs.

console.log(ObjectHelper.toPairs({ a: 1, b: 2 })); // [["a", 1], ["b", 2]]

fromPairs<T>(pairs: [string, T][]): Record<string, T>

Creates an object from key-value pairs.

console.log(ObjectHelper.fromPairs([["a", 1], ["b", 2]])); // { a: 1, b: 2 }

freeze<T>(obj: T): Readonly<T>

Freezes an object to prevent modifications.

const frozen = ObjectHelper.freeze({ a: 1 });
// frozen.a = 2; // Error in strict mode

mapValues<T, U>(obj: T, callback: (value: T[keyof T], key: keyof T) => U): Record<keyof T, U>

Applies a function to each value in an object.

console.log(ObjectHelper.mapValues({ a: 1, b: 2 }, val => val * 2)); // { a: 2, b: 4 }

filter<T>(obj: T, predicate: (value: T[keyof T], key: keyof T) => boolean): Partial<T>

Filters object properties based on a function.

console.log(ObjectHelper.filter({ a: 1, b: 2, c: 3 }, val => val > 1)); // { b: 2, c: 3 }

deepMerge<T, U>(obj1: T, obj2: U): T & U

Performs a deep merge of two objects.

const obj1 = { a: { b: 1 } };
const obj2 = { a: { c: 2 } };
console.log(ObjectHelper.deepMerge(obj1, obj2)); // { a: { b: 1, c: 2 } }

License

ISC License.

Author

Vijayavel R