ts-enums-tools
v0.0.2
Published
Java-style enums for TypeScript with decorators, type safety, and serialization
Downloads
11
Readme
ts-enums
A clean, type-safe enum library for TypeScript with only @Enum() decorator.
Features
- ✅ Automatic
values(),valueOf() - ✅ Immutable, frozen, readonly
- ✅ Full type safety
Usage
import { BaseEnum, Enum, EnumValue } from 'ts-enums-tools';
@Enum()
class Color extends BaseEnum<Color> {
readonly hex: string;
constructor(name: string, hex: string) {
super(name);
this.hex = hex;
}
@EnumValue('#FF0000')
static readonly RED: Color;
@EnumValue('#00FF00')
static readonly GREEN: Color;
@EnumValue('#0000FF')
static readonly BLUE: Color;
}
console.log('Color.RED:', Color.RED.toString()); // RED
console.log('Green by name:', Color.valueOf('GREEN')); // Color.GREEN