Skip to content

Instantly share code, notes, and snippets.

View clmrb's full-sized avatar
🏠
Doing things

clmrb

🏠
Doing things
View GitHub Profile
@clmrb
clmrb / enum.js
Last active December 20, 2025 19:28
JavaScript enum function with working JSDoc autocompletion
/**
* @description
* Creates a frozen enumeration object where each key maps to its own string value.
* This is useful for defining a set of constant string values that can be referenced by name.
* This also avoids defining an object with duplicated string values manually.
* @template {string} T
* @param {...T} values
* @returns {{ [K in T]: K }}
* @example
* const Colors = Enum('Red', 'Green', 'Blue');