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

segedin

v1.2.0

Published

Type-safe getters/setters for nested object structures

Readme

Segedin

Type-safe getters/setters for nested object structures.

Example usage

import { set, get } from 'segedin'

// Setting deeply nested property
const obj = { a: { b: { c: 40 } } }
const updatedObj = set(obj, _ => _.a.b.c)(42)
const updatedObj2 = set(obj, _ => _.a.b.c)((value) => value + 1)

// Getting nested property
const obj2 = { a: [{ b: { c: 'foo' } }] }
const value = get(obj2, _ => _.a[0].b.c) // 'foo'
const value2 = get(obj2, _ => _.a[1].b.c) // undefined
const value3 = get(obj2, _ => _.a[1].b.c, 'default') // 'default'

About the project

This library aims to provide helpers for two use-cases:

  1. Accessing deeply nested data with possibly null properties in the access chain. This problem is commonly referenced as Optional chaining and hopefully it should by covered by one of upcoming ES standards (Proposal). The goal of this library is to provide type-safe way of how to do it until it lands.
  2. Setting deeply nested properties on plain immutable objects in type-safe manner.

Why?

I had to adopt older project with complex API models depending heavily on lodash get/set functions for accessing deeply nested data. Once we started migrating project to TS we had to get rid of it to not break type-safety.

There are several existing solutions with similar idea (for example idx) but they haven't satisfied all my requirements:

  1. I want to benefit from Typescript (and avoid Babel transpilation).
  2. I want to provide legacy solution for IE11 which doesn't provide native Proxy support.
  3. I want to create performant solution so that the helpers can be used across the application.

How does this project differ from others?

This library comes with 2 flavours. There is a plain JS implementation (Proxy based) which can be used without Typescript (ie. in legacy projects). And there is also bundled Typescript transformer which compiles the helper calls into effective JS code to optimize any performance hits and possible polyfill requirements for Proxy (IE). Both solutions are functionally equal.

How to use Typescript transform

To get the best out of this library I recommend to use it together with bundled Typescript transform. The usage depends on the way you use Typescript in your project so I will refer you to documentation of common options:

Node:

Webpack:

Performance considerations

This library is meant as a replacement for lodash set / get helpers which come with decent performance hit. Their accessor has to be constructed from string (unless array is used) and that comes with a price of parsing it before walking the object.

This library is implemented using Proxy which has it's own drawbacks. It is computationally cheaper but it requires bigger memory footprint (lambda, Proxy itself, accessor objects).

I would not expect the performance to differ significantly (TODO: needs benchmarks). The only issue may be IE 11 which comes with additional overhead because of required Proxy polyfill.

If it is used together with bundled TS transformation there is no need for Proxy. The get operation are transformed to index access without any helper which offers best possible performance. The set operation still uses helper function but it receives serialized chain so any performance costs for constructing it is eliminated.

Similar projects

Who uses Segedin

Credits

My thanks to @bufi for awesome project name suggestion :)