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

@nameof/nameof

v1.1.0

Published

A tiny utility for safely extracting property names from TypeScript objects — inspired by C#'s [`nameof`](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/nameof) operator.

Readme

nameof

A tiny utility for safely extracting property names from TypeScript objects — inspired by C#'s nameof operator.

💡 Examples

import nameof from "@nameof/nameof";

// basic
const obj = { name: "John", age: 30 };
const keyName = nameof(obj, "name");
console.log(`keyName: ${keyName}`);

// single key
const keyName2 = nameof<typeof obj>("age");
console.log(`keyName2: ${keyName2}`);

// variable name
const numbers = [1, 2, 3, 4, 5];
const variableName = nameof({ numbers });
console.log(`variableName: ${variableName}`);

// Class Name
class Person {}
const className = nameof(Person);
console.log(`className: ${className}`);

// Function Name
function bar() {}
const functionName = nameof(bar);
console.log(`functionName: ${functionName}`);

Try Online (only type)

✨ Features

  • Type-safe access to property names
  • Preserves literal types
  • Refactor-friendly
  • Zero dependencies

📦 Installation

# With Bun
bun add @nameof/nameof

with npm yarn pnpm amd more see here

🚀 Usage

import nameof from "@nameof/nameof";

const user = {
  id: 1,
  name: "Alice",
  age: 30,
};

const propName = nameof(user, "name"); // "name"

🧠 Why?

TypeScript lacks a built-in nameof operator like C#. Developers often fall back on hardcoded strings, which:

  • ❌ Aren't checked by the compiler
  • ❌ Don’t update when properties are renamed
  • ❌ Easily lead to bugs in refactors

This utility gives you type-safe property name extraction, with full support for TypeScript’s type system and IDE refactor tools.

🛡️ Refactor-Safe by Design

One of the key benefits of nameof is its compile-time safety during refactoring.

🔁 Rename-safe

const user = {
  id: 123,
  name: "Alice",
};

const field = nameof(user, "name"); // "name"

Now, if you rename name to fullName:

const user = {
  id: 123,
  fullName: "Alice",
};

// ❌ TypeScript error:
const field = nameof(user, "name");
// Argument of type '"name"' is not assignable to ...

✅ TypeScript catches it instantly. Your code is safe from silent bugs caused by outdated strings.

🔍 What about hardcoded strings?

const field = "name"; // ❌ No error on rename

Hardcoded strings aren’t tracked by the compiler — you lose all refactor safety.

💡 Pro Tip: Use as const

For stricter typing:

const config = {
  apiEndpoint: "/api/data",
  retry: true,
} as const;

const key = nameof(config, "apiEndpoint"); // type: "apiEndpoint"

Literal types are preserved in the result!

❌ Why Not a Macro or Compiler?

Some libraries implement nameof(foo.bar) using Babel or AST transforms. This package deliberately avoids those approaches.

🚫 No macros or compilers required

  • ❌ No Babel plugins
  • ❌ No SWC or TypeScript transformers
  • ❌ No custom build setup

✅ Just TypeScript

  • Works in any environment (Node, Bun, Vite, Webpack, etc.)
  • Transparent and reliable
  • Keeps your build chain simple

🔗 References

  • https://github.com/dsherret/ts-nameof/issues/121

🔧 Development

This project is built with Bun — fast, modern, and TypeScript-first.

git clone https://github.com/baboon-king/nameof.git
cd nameof
bun install
bun run build

📄 License

MIT License © 2025-PRESENT BaboonKing

🌸 Thanks

This project is heavily inspired by the following awesome projects.

🙌 Contributing

Suggestions, issues, and PRs are welcome!

If you find this useful, please ⭐️ the repo and help others discover it!