File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -16,3 +16,31 @@ export function Enum(...values: any[]): object {
1616}
1717
1818export type Enum < T extends object > = T [ keyof T ] ;
19+
20+ export namespace Enum {
21+ function hasOwnProperty ( obj : object , prop : string ) : boolean {
22+ return Object . prototype . hasOwnProperty . call ( obj , prop ) ;
23+ }
24+
25+ export function keys <
26+ T extends { [ _ : string ] : any }
27+ > ( e : T ) : Array < keyof T > {
28+ const result : string [ ] = [ ] ;
29+ for ( const prop in e ) {
30+ if ( hasOwnProperty ( e , prop ) ) {
31+ result . push ( prop ) ;
32+ }
33+ }
34+ return result as Array < keyof T > ;
35+ }
36+
37+ export function values <
38+ T extends { [ _ : string ] : any }
39+ > ( e : T ) : Array < Enum < T > > {
40+ const result : Array < Enum < T > > = [ ] ;
41+ for ( const key of keys ( e ) ) {
42+ result . push ( e [ key as string ] ) ;
43+ }
44+ return result ;
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments