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

@chaisser/obj-path

v1.0.1

Published

Safe dot-notation object access - get(obj, 'a.b.c'), set(obj, 'a.b.c', value)

Downloads

228

Readme

🛤️ @chaisser/obj-path

Safe dot-notation object access: get, set, has, delete, pick, omit, and wildcard find


✨ Features

  • 🎯 Type-safe - Full TypeScript support with generics
  • 🔍 Dot notation - Access nested properties with 'user.address.city'
  • 📋 Array paths - Also supports ['user', 'address', 'city']
  • 🔧 Auto-create - set() creates intermediate objects/arrays automatically
  • 🗑️ Delete - Remove nested properties safely
  • 🔎 Wildcard find - Find values matching patterns like 'users.*.name'
  • ✂️ Pick & Omit - Extract or exclude paths from objects
  • Has check - Check if a nested path exists
  • 🪶 Zero dependencies - Lightweight and tree-shakeable
  • 🏎️ ESM + CJS - Dual module format support

📦 Installation

npm install @chaisser/obj-path
# or
yarn add @chaisser/obj-path
# or
pnpm add @chaisser/obj-path

🚀 Quick Start

import { get, set, has, del, find, pick, omit } from '@chaisser/obj-path';

const user = {
  name: 'Doruk',
  address: {
    city: 'Istanbul',
    zip: '34000',
  },
  hobbies: ['coding', 'music'],
};

// Get nested values safely
get(user, 'address.city');          // 'Istanbul'
get(user, 'address.country', 'TR'); // 'TR' (default)
get(user, 'hobbies.0');             // 'coding'

// Set nested values (auto-creates path)
set(user, 'address.country', 'Turkey');

// Check existence
has(user, 'address.city');   // true
has(user, 'address.phone');  // false

// Delete
del(user, 'address.zip');

// Pick specific paths
pick(user, ['name', 'address.city']);
// { name: 'Doruk', address: { city: 'Istanbul' } }

// Omit paths
omit(user, ['address', 'hobbies']);
// { name: 'Doruk' }

📖 What It Does

This package provides safe dot-notation access to nested JavaScript objects and arrays. It handles null/undefined values gracefully, auto-creates intermediate paths when setting values, and includes utilities for picking, omitting, and finding values with wildcard patterns.


🎯 How It Works

The package provides 7 core functions:

  • get - Traverse a path and return the value, or a default if not found
  • set - Set a value at a path, creating intermediate objects/arrays as needed
  • has - Check if a path resolves to a defined value
  • del - Delete a property at a path, returning whether it existed
  • find - Wildcard pattern matching to collect values across nested structures
  • pick - Create a new object containing only specified paths
  • omit - Create a deep clone excluding specified paths

🎨 What It's Useful For

  • Form Data - Safely read/write nested form state
  • API Responses - Extract fields from deep JSON structures
  • Configuration - Access nested config values with defaults
  • Data Transformation - Pick/omit fields for API payloads
  • Tree Structures - Wildcard find across hierarchical data
  • Deep Path Operations - Work with nested objects without manual null checks

💡 Usage Examples

Get with Defaults

import { get } from '@chaisser/obj-path';

const config = { database: { host: 'localhost' } };

get(config, 'database.host');              // 'localhost'
get(config, 'database.port', 5432);        // 5432 (path missing, uses default)
get(config, 'database.credentials.user');  // undefined
get(null, 'anything');                     // undefined

// Array indexing
const data = { items: [{ name: 'a' }, { name: 'b' }] };
get(data, 'items.1.name'); // 'b'

// Array path syntax
get(config, ['database', 'host']); // 'localhost'

Set with Auto-Creation

import { set } from '@chaisser/obj-path';

const obj: any = {};

set(obj, 'user.profile.name', 'Doruk');
// { user: { profile: { name: 'Doruk' } } }

set(obj, 'items.0.title', 'First');
// { items: [{ title: 'First' }] }  — auto-creates array for numeric keys

set(obj, 'a.b.c.d.e', 42);
// Creates the entire nested path

Has Check

import { has } from '@chaisser/obj-path';

const data = { user: { name: 'Doruk' } };

has(data, 'user.name');       // true
has(data, 'user.email');      // false
has(data, 'user.name.first'); // false

Delete

import { del } from '@chaisser/obj-path';

const data = { a: { b: { c: 1, d: 2 } } };

del(data, 'a.b.c');  // true
// data = { a: { b: { d: 2 } } }

del(data, 'x.y.z');  // false (path didn't exist)

Wildcard Find

import { find } from '@chaisser/obj-path';

const data = {
  users: [
    { name: 'Alice', age: 30 },
    { name: 'Bob', age: 25 },
  ],
};

find(data, 'users.*.name'); // ['Alice', 'Bob']
find(data, 'users.*.age');  // [30, 25]

Pick Paths

import { pick } from '@chaisser/obj-path';

const user = {
  name: 'Doruk',
  email: '[email protected]',
  password: 'secret',
  profile: { avatar: 'pic.jpg', bio: 'Dev' },
};

pick(user, ['name', 'email', 'profile.avatar']);
// { name: 'Doruk', email: '[email protected]', profile: { avatar: 'pic.jpg' } }

Omit Paths

import { omit } from '@chaisser/obj-path';

const user = {
  name: 'Doruk',
  email: '[email protected]',
  password: 'secret',
  token: 'abc123',
};

omit(user, ['password', 'token']);
// { name: 'Doruk', email: '[email protected]' }

📚 API Reference

get(obj, path, defaultValue?)

Get a value at a dot-notation path.

| Parameter | Type | Description | |---|---|---| | obj | object \| array | Source object | | path | string \| string[] | Dot notation path or key array | | defaultValue | any | Returned if path doesn't exist |

Returns: Value at path, or defaultValue, or undefined

set(obj, path, value)

Set a value at a dot-notation path. Auto-creates intermediate objects/arrays.

| Parameter | Type | Description | |---|---|---| | obj | object | Target object | | path | string \| string[] | Dot notation path | | value | any | Value to set |

Returns: The modified object

has(obj, path)

Check if a path exists and has a defined value.

Returns: boolean

del(obj, path)

Delete a property at a path.

Returns: booleantrue if the property existed and was deleted

find(obj, pattern)

Find all values matching a wildcard pattern. Use * as wildcard.

| Parameter | Type | Description | |---|---|---| | obj | object \| array | Source object | | pattern | string | Pattern with * wildcards (e.g. 'users.*.name') |

Returns: T[] — Array of matching values

pick(obj, paths)

Create a new object with only the specified paths.

| Parameter | Type | Description | |---|---|---| | obj | object | Source object | | paths | string[] | Paths to include |

Returns: New object with only picked paths

omit(obj, paths)

Create a deep clone of the object without the specified paths.

| Parameter | Type | Description | |---|---|---| | obj | object | Source object | | paths | string[] | Paths to exclude |

Returns: New object without omitted paths


🔗 Related Packages

Explore our other utility packages in the @chaisser namespace:


🔒 License

MIT - Free to use in personal and commercial projects


👨 Developed by

Doruk Karaboncuk [email protected]


📄 Repository


🤝 Contributing

Contributions are welcome! Feel free to:

  • Report bugs
  • Suggest new features
  • Submit pull requests
  • Improve documentation

📞 Support

For issues, questions, or suggestions, please reach out through:


Made with ❤️ by @chaisser

npm license downloads typescript