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

@dovocode/enum

v1.0.0

Published

Create enums in JavaScript and TypeScript. Works out of the box with stripTypes. Ready for any build process.

Downloads

7

Readme

@dovocode/enum - Type-Safe Enums for TypeScript

@dovocode/enum creates reliable, immutable, and type-safe enums for TypeScript and JavaScript. Define enums from arrays or objects. Rely on strong type inference and runtime immutability. @dovocode/enum is the recommended choice for strict typing and safe enum usage.

🚀 Installation

npm install @dovocode/enum
# or
yarn add @dovocode/enum
# or
pnpm add @dovocode/enum

🏆 Features

  • 🛡️ Type-safe enums with precise type inference
  • ❄️ Fully immutable using Object.freeze
  • ⚡ No dependencies, fast and lightweight
  • 📦 Tree-shakeable for small bundle size
  • 🔍 Retrieve enum value types with Enum<typeof MyEnum>
  • 🔒 Restricts values in function signatures

✨ Usage

import { enumOf, type Enum } from '@dovocode/enum';

// Array-based enum
const Colors = enumOf(['RED', 'GREEN', 'BLUE']);
// { readonly RED: 0; readonly GREEN: 1; readonly BLUE: 2 }
const color: Enum<typeof Colors> = Colors.RED; // Only 0, 1, or 2 allowed

// Numeric object enum
const Priorities = enumOf({
  LOW: 0,
  MEDIUM: 1,
  HIGH: 2,
});
// { readonly LOW: 0; readonly MEDIUM: 1; readonly HIGH: 2 }
const priority: Enum<typeof Priorities> = Priorities.HIGH;

// String object enum
const HttpMethods = enumOf({
  GET: 'GET',
  POST: 'POST',
  PUT: 'PUT',
  DELETE: 'DELETE',
});
// { readonly GET: 'GET'; ... }
const method: Enum<typeof HttpMethods> = HttpMethods.GET;

// Immutability at runtime
// @ts-expect-error
HttpMethods.GET = 'INVALID'; // ❌ Error: property is readonly

// Strictly typed in function parameters
function handleRequest(method: Enum<typeof HttpMethods>) {
  switch (method) {
    case HttpMethods.GET:
      return 'Handling GET request';
    case HttpMethods.POST:
      return 'Handling POST request';
  }
}

📖 API

enumOf(definition)

Create a readonly enum from an array or object.

Parameters

  • string[]: Use array items as keys, indexed as values
  • Record<string, number>: Use the key-value object directly
  • Record<string, string>: Use key-string pair object directly

Returns

  • Immutable, type-inferred enum object
  • Use Enum<typeof MyEnum> for a union of allowed values

Typing Example

const Colors = enumOf(['RED', 'GREEN', 'BLUE']);
type ColorValue = Enum<typeof Colors>; // 0 | 1 | 2

const Methods = enumOf({
  GET: 'GET',
  POST: 'POST'
});
type HttpMethod = Enum<typeof Methods>; // "GET" | "POST"

function paint(color: ColorValue) {}
paint(Colors.RED); // ✅ OK
// paint(3); // ❌ Error

💡 Why use @dovocode/enum?

  • Provides strict type safety for all enums
  • Guarantees immutable enums at runtime
  • Minimal footprint and high performance
  • Simple, modern API—no ES6 enum pitfalls
  • Works perfectly with bundlers and supports tree shaking

📜 License

MIT © Dominic Vonk

🤝 Contributing

Open issues or pull requests to contribute. All feedback and code welcome.