@northscaler/better-enum
Version:
Better enumeration support for TypeScript than its `enum` keyword. This class is modeled after [Java's enumeration pattern](https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html), where enums are instances of classes. This library provides a base
19 lines (14 loc) • 505 B
text/typescript
import { _of, _values, Enumeration } from '../../main'
export default class HelloWorld extends Enumeration<HelloWorld> {
static readonly HELLO = new HelloWorld('HELLO', 0)
static readonly WORLD = new HelloWorld('WORLD', 1)
static of(it: HelloWorld | string | number): HelloWorld {
return _of(it, HelloWorld)
}
static values(): HelloWorld[] {
return _values<HelloWorld>(HelloWorld)
}
private constructor(name: string, ordinal: number) {
super(name, ordinal, HelloWorld)
}
}