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

awesome-key-factory

v1.0.2

Published

A type-safe key factory for managing react-query keys

Readme

awesome-key-factory

A type-safe key factory for managing react-query keys with full TypeScript support.

📚 Documentation

Installation

Install from npm:

yarn add awesome-key-factory
# or
npm install awesome-key-factory

📦 View on npm

Usage

Basic Example

import { createKeyFactory } from 'awesome-key-factory';

const keys = createKeyFactory('baseKey', {
  a: (params: {}) => ['key1', 'key2'],
  b: {
    c: ['key3', 'key4'],
  },
});

// Access any level
keys.a({}) // => ['baseKey', 'a', 'key1', 'key2']
keys.b.c() // => ['baseKey', 'b', 'c', 'key3', 'key4']
keys.b() // => ['baseKey', 'b'] (any level can be called as a function)

With Parameters

const queryKeys = createKeyFactory('app', {
  users: {
    all: () => [],
    detail: (params: { id: string }) => [params.id],
    posts: (params: { userId: string }) => [params.userId, 'posts'],
  },
  posts: {
    all: () => [],
    detail: (params: { id: string }) => [params.id],
  },
});

// Usage in react-query
useQuery({
  queryKey: queryKeys.users.detail({ id: '123' }),
  queryFn: () => fetchUser('123'),
});

useQuery({
  queryKey: queryKeys.users.posts({ userId: '456' }),
  queryFn: () => fetchUserPosts('456'),
});

Array Shorthand

You can use arrays as a shorthand for functions that return static keys:

const keys = createKeyFactory('shop', {
  products: {
    list: ['all'], // equivalent to () => ['all']
    byId: (params: { id: string }) => [params.id],
  },
});

keys.products.list() // => ['shop', 'products', 'list', 'all']

Deep Nesting

const keys = createKeyFactory('api', {
  v1: {
    users: {
      posts: {
        comments: (params: { postId: string }) => [params.postId],
      },
    },
  },
});

keys.v1.users.posts.comments({ postId: '123' })
// => ['api', 'v1', 'users', 'posts', 'comments', '123']

keys.v1.users.posts() // => ['api', 'v1', 'users', 'posts']
keys.v1.users() // => ['api', 'v1', 'users']
keys.v1() // => ['api', 'v1']

Features

  • Fully TypeScript typed - Get autocomplete and type safety for all your keys
  • Nested key access - Access nested keys through the full path (keys.b.c)
  • Function parameters - Pass typed parameters to your key functions
  • Array shorthand - Use arrays for static key lists
  • Any level access - Call any level in the hierarchy as a function to get its path

API

createKeyFactory<BaseKey, Schema>(baseKey, schema)

Creates a type-safe key factory.

Parameters:

  • baseKey (string): The base key that will be prepended to all generated keys
  • schema (object): An object defining the key structure with nested objects and functions

Returns: A factory object where each level can be accessed as a function

Documentation

For complete documentation, examples, and best practices, see:

License

MIT