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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@vakulenko10/object-toolkit

v1.0.75

Published

A TypeScript toolkit for deep object manipulation and recursive operations

Downloads

198

Readme

🧰 @vakulenko10/object-toolkit

A compact, type-safe, and extensible toolkit for deep manipulation of nested objects and arrays in JavaScript and TypeScript.

✍️ About the Project

I originally created this utility set for my personal use, as I often deal with deeply nested objects in React projects, especially when working with data returned from APIs.

Instead of rewriting the same helper functions over and over again, I decided to build a reusable toolkit that allows me to:

  • 🔍 Access nested properties safely and easily
  • 🧭 Extract values using dynamic paths
  • 📊 Group, count, and analyze data structures
  • 🧱 Work with objects and arrays in a more expressive and type-safe way

Eventually, I decided to publish it as an npm package, in case it helps other developers facing similar challenges.

npm version License


📦 Installation

npm install @vakulenko10/object-toolkit
# or
yarn add @vakulenko10/object-toolkit

📚 Usage

import {
  flattenObject,
  unflattenObject,
  getValueByPath,
  getAllKeys,
  getAllValues,
  findKeyDeep,
  findAllByKey,
  findKeysByValue,
  getPathsToKey,
  findDeepByPredicate,
  groupBy,
  countOccurrences
} from '@vakulenko10/object-toolkit';

🔧 API Reference

🔄 Object Structure Utilities

flattenObject(obj) - Flattens a nested object into a single-level object using dot notation.

flattenObject({ a: { b: 1 }, c: 2 });
// ➜ { 'a.b': 1, c: 2 }

unflattenObject(obj, separator = '.')- Restores a flattened object into its original nested form.

unflattenObject({ 'a.b': 1, c: 2 });
// ➜ { a: { b: 1 }, c: 2 }

getValueByPath(obj, path, separator = '.') - Retrieves a deeply nested value from an object using a string path.

getValueByPath({ user: { profile: { name: 'Alice' } } }, 'user.profile.name');
// ➜ 'Alice'

getValueByPath(obj, 'user/profile/name', '/');
// ➜ 'Alice' with custom separator

🔍 Deep Inspection Utilities

getAllKeys(obj, separator = '.') - Returns all keys from a deeply nested object in dotted path format by default, or with custom separator passed inside as a parameter.

getAllKeys({ a: { b: 2 }, c: 3 });
// ➜ ['a', 'a.b', 'c']

getAllValues(obj) - Returns all primitive values from a deeply nested object.

getAllValues({ a: { b: 2 }, c: 3 });
// ➜ [2, 3]

findKeyDeep(obj, key) Finds the first occurrence of a key in a deeply nested object.

findKeyDeep({ user: { profile: { name: 'Alice' } } }, 'name');
// ➜ 'Alice'

findAllByKey(obj, key) Finds all values associated with a key, regardless of nesting level.

findAllByKey({
  users: [{ name: 'John' }, { name: 'Jane' }],
  meta: { name: 'meta' }
}, 'name');
// ➜ ['John', 'Jane', 'meta']

findKeysByValue(obj, value) Finds all dotted key paths where the given value occurs.

findKeysByValue({ a: 1, b: { c: 1 } }, 1);
// ➜ ['a', 'b.c']

getPathsToKey(obj, key) Finds all key paths that lead to a specific key name.

getPathsToKey({ user: { profile: { name: 'Alice' } } }, 'name');
// ➜ ['user.profile.name']

findDeepByPredicate(obj, predicate) Recursively finds all key-value pairs that match a predicate function.

findDeepByPredicate(
  { a: { b: 1 }, c: 2 },
  (key, value) => typeof value === 'number'
);
// ➜ { 'a.b': 1, 'c': 2 }

📊 Array & Value Utilities groupBy(array, key) Groups an array of objects by the specified key.

groupBy([{ age: 20 }, { age: 30 }, { age: 20 }], 'age');
// ➜ { '20': [{ age: 20 }, { age: 20 }], '30': [{ age: 30 }] }

countOccurrences(array) Counts the number of times each value appears in an array.

countOccurrences(['a', 'b', 'a']);
// ➜ { a: 2, b: 1 }

🧪 Testing This library is fully tested using Vitest. To run tests:

npm run test

✅ TypeScript Support All utilities are written in TypeScript with complete typings. Example:

const email = getValueByPath<string>(user, 'profile.contact.email');

This is an open-source project — feel free to fork the repository, contribute new utilities, suggest improvements, or submit pull requests. Let’s make it better together!