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

butter-enums

v0.0.8

Published

Typesafe specialized enums for TypeScript - Smooth like butter

Readme

Butter Enums

Smooth like butter - Type-safe enum utilities for TypeScript

A lightweight TypeScript library providing type-safe enum utilities that make working with enums in TypeScript smoother.

Installation

npm install butter-enums
# or
yarn add butter-enums
# or
pnpm add butter-enums

Features

  • ButterTupleEnum: Create type-safe enums from tuples of strings
  • ButterKeyedEnum: Create type-safe enums from objects with additional metadata
  • Deep immutability: All enums are deeply frozen for safety

Usage

ButterTupleEnum

Tuple enums are created with a tuple of strings. They provide type safety when converting back and forth between enums and tuples, which is extremely useful when working with libraries like Drizzle ORM.

import { ButterTupleEnum } from 'butter-enums';

// Create a tuple enum
const Colors = ButterTupleEnum(['red', 'green', 'blue']);

// Access as tuple
const firstColor = Colors.get(0); // 'red'
const allColors = Colors.tuple; // readonly ['red', 'green', 'blue']
const colorCount = Colors.length; // 3

// Access as enum
const redColor = Colors.enum.red; // 'red'

ButterKeyedEnum

Keyed enums are created with an object of objects. They provide type safety when converting back and forth between enums and objects, allowing you to attach additional metadata to each enum value.

import { ButterKeyedEnum } from 'butter-enums';

// Create a keyed enum
const Fruits = ButterKeyedEnum({
  apple: {
    name: 'Apple',
    color: 'red',
    sweetness: 7
  },
  banana: {
    name: 'Banana',
    color: 'yellow',
    sweetness: 8
  },
  lemon: {
    name: 'Lemon',
    color: 'yellow',
    sweetness: 2
  }
}, {
  // This is optional, but if you want tuple support or ordered keys, you must provide it.
  // Typescript cannot convert from a union to a tuple with
  // * Guaranteed order
  // * Better performance than O(n^2)
  // See https://stackoverflow.com/questions/55127004/how-to-transform-union-type-to-tuple-type
  //
  // So, we have to provide a tuple factory. It constrains the tuple to make sure you're not missing any values.
  // Making our typescript compiler happy.
  tupleFactory: (enumObject) => [
    enumObject.apple,
    enumObject.lemon,
    enumObject.banana,
  ]
});

// Access enum values
const apple = Fruits.enum.apple;
// { name: 'Apple', color: 'red', sweetness: 7, key: 'apple' }

// Get a value by key
const banana = Fruits.get('banana');
// { name: 'Banana', color: 'yellow', sweetness: 8, key: 'banana' }

// Get all keys
const fruitKeys = Fruits.keys; // ['apple', 'banana', 'lemon']

// Get all values
const allFruits = Fruits.values;

// Find a value
const yellowFruit = Fruits.find(fruit => fruit.color === 'yellow');
// { name: 'Banana', color: 'yellow', sweetness: 8, key: 'banana' }

License

MIT