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

@jclem/get-in

v2.0.1

Published

A function for getting deeply nested values

Readme

getIn

This package provides a function getIn, which allows null-error and type-safe traversal of objects.

The getIn function works by wrapping a value in a function that returns that value, and then wrapping that function in a Proxy. To use it, call getIn on the object you want to traverse (e.g. getIn(object)) and get properties as you normally would, but when you want an actual value, call the property like a function (e.g. getIn(object).foo.bar[0][1].baz()). The return value will be null or the value itself.

Limitations

  • There are likely edge cases here. I've mostly experimented with simple arrays and plain JavaScript objects.
  • Even if a type is non-nullable (such as firstName in the below example), the type will be nullable when gotten through getIn, and you'll need to perform a check for the type checker to be happy. I haven't found a way around this, yet.

Example

type Person = {
  firstName: string
  middleName?: string
  lastName: string
  
  address?: Address
}

type Address = {
  streets: string[]
  city: string
  state: string
  zip: string
}

const p1: Person = {
  firstName: 'Jonathan',
  lastName: 'Clem',
  
  address: {
    streets: ['123 Main St.'],
    city: 'Juneau',
    state: 'Alaska',
    zip: '11111'
  }
}

const p2: Person = {
  firstName: 'Bob',
  lastName: 'Clem'
}

getIn(p1).firstName() // Type is string | null
getIn(p1).address.state() // Type is string | null, value is `'Alaska'`.
getIn(p1).address.streets[0]() // Type is string | null, value is `'123 Main St.'`.
getIn(p2).address.streets[1]() // Type is string | null, value is `null`.