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

@kattebak/typespec-enum-emitter

v1.2.2

Published

TypeSpec emitter for JavaScript const enums

Readme

TypeSpec Enum Emitter

A custom TypeSpec emitter that exports enums as JavaScript const objects with proper TypeScript type definitions.

Features

  • Converts TypeSpec enums to JavaScript const objects
  • Generates TypeScript declaration files (.d.ts)
  • Supports string and numeric enum values
  • Uses the TypeSpec emitter framework

Installation

npm install typespec-enum-emitter

Usage

1. Create a TypeSpec file with enums

import "typespec-enum-emitter";

enum Status {
	Active,
	Inactive,
	Pending,
}

enum Priority {
	Low: "low",
	Medium: "medium",
	High: "high",
}

enum HttpStatusCode {
	OK: 200,
	NotFound: 404,
	InternalServerError: 500,
}

2. Configure tspconfig.yaml

emit:
  - @kattebak/typespec-enum-emitter
options:
  typespec-enum-emitter:
    output-file: "enums.js"
    emitter-output-dir: "{cwd}/build/ts-enums"
    package-name: "@mycorp/enums"
    package-version: "1.0.0"

3. Compile

npx tsp compile .

4. Generated Output

enums.js:

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });

export const Status = {
  Active: "Active",
  Inactive: "Inactive",
  Pending: "Pending",
};

export const Priority = {
  Low: "low",
  Medium: "medium",
  High: "high",
};

export const HttpStatusCode = {
  OK: 200,
  NotFound: 404,
  InternalServerError: 500,
};

enums.d.ts:

export declare const Status: {
  readonly Active: "Active";
  readonly Inactive: "Inactive";
  readonly Pending: "Pending";
};

export declare const Priority: {
  readonly Low: "low";
  readonly Medium: "medium";
  readonly High: "high";
};

export declare const HttpStatusCode: {
  readonly OK: 200;
  readonly NotFound: 404;
  readonly InternalServerError: 500;
};

Configuration Options

  • output-file: Name of the output file (default: "enums.js")
  • emitter-output-dir: Custom output directory (supports variable interpolation like {cwd}, {project-root})
  • package-name: If provided, generates a package.json file with this name
  • package-version: Version for the generated package.json (default: "0.0.1")

Why Use This?

TypeScript enums have some quirks:

  • They generate runtime code that can be hard to tree-shake
  • Const enums don't preserve values at runtime
  • Regular enums can have unexpected behavior with numeric values

This emitter generates simple const objects that:

  • Are fully tree-shakeable
  • Have clear runtime behavior
  • Work seamlessly with TypeScript's type system
  • Are easy to inspect and debug

Implementation

Built using the TypeSpec emitter framework with:

  • @typespec/compiler for AST traversal
  • Namespace-aware enum collection
  • Proper TypeScript declaration generation