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

@diagonal2/nameof

v0.1.1

Published

Provides a type-safe way to access (get/set) object properties.

Downloads

8

Readme

@diagonal2/nameof

Provides a type-safe way to access (get/set) object properties.

Install

Install with npm:

$ npm install --save @diagonal2/nameof

Usage

This package only makes sense if you're using TypeScript.

Use nameof to get a string path from a property selector function.

type T = {
    prop1a: {
         prop2a: number;
    };
    prop1b?: {
         prop2b: number;
    } | null;
};

nameof<T>(t => t.prop1a.prop2a);    // Returns `["prop1a", "prop2a"]`.
nameof<T>(t => t.prop1b?.prop2b);   // Returns `["prop1b", "prop2b"]`.

Use nameofFactory to reuse nameof without repeating the generic type parameter.

const nameof = nameofFactory<T>();

nameof(t => t.prop1a.prop2a);   // Returns `["prop1a", "prop2a"]`.
nameof(t => t.prop1b?.prop2b);  // Returns `["prop1b", "prop2b"]`.

Use get to get the value of a property. The property may be described by a selector function or a string array.

const entity = {
    prop1a: {
        prop2a: [1]
    }
};

get(entity, t => t.prop1a.prop2a[0]);           // Returns 1.
get<number>(entity, ["prop1", "prop2", "0"]);   // Returns 1.

Use set to set the value of a property. The property may be described by a selector function or a string array.

type T = {
    prop1?: {
        prop2?: number;
    }
};
const entity1: T = {};
set(entity1, t => t.prop1?.prop2, 1);   // `entity1` becomes `{ prop1: { prop2: 1 } }`.

const entity2 = {};
set(entity2, ["prop1", "prop2"], 1);    // `entity2` becomes `{ prop1: { prop2: 1 } }`.

The entire reason why nameof was created is that I was unsatisfied with the type-safety issues in rc-table. In particular, the dataIndex property of ColumnType did not have a strict type-check:

type T = {
    prop1: number;
    prop2: string;
};

const columns: ColumnType<T>[] = [
    {
      title: "Prop 1",
      dataIndex: "prop1x"       // No compiler error
    },
    {
      title: "Prop 2",
      dataIndex: ["prop2x"]     // No compiler error
    }
];

This package solves that problem:

const nameof = nameofFactory<T>();

const columns: ColumnType<T>[] = [
    {
      title: "Prop 1",
      dataIndex: nameof(t => t.prop1)   // Compiler will issue an error if "prop1" is misspelled.
    },
    {
      title: "Prop 2",
      dataIndex: nameof(t => t.prop2)
    }
];

Caveats

This package only makes sense if you use TypeScript, where you can benefit from the compiler autocompleting property selectors t => t.prop, etc. If you use plain JavaScript, then t => t.prop provides no benefit over ["prop"], so this package won't benefit you.

Also, converting property selector functions to string arrays requires extensive use of Proxies. Proxies are known to be slow. If your application is performance-critical, avoid this package.

License

Released under the MIT License. Copyright � 2025, https://github.com/diagonal2.