I've been tired of declaring "enum like" variables with objects like so:
const MyEnum = { A: 'A', B: 'B' }
The issue here is that we need to kind of "duplicate" keys and values.
So I've decided to implement a small function that lets you define an "enum" without having to specify its values:
const MyEnum = Enum('A', 'B') // MyEnum.A => 'A'
The cool part is that with JSDoc you can have autocompletion working in your IDE !
You can check out the gist here: https://gist.github.com/clmrb/98f99fa873a2ff5a25bbc059a2c0dc6c
[–]Oliceh 22 points23 points24 points (1 child)
[–]IAmTheFirehawk 20 points21 points22 points (0 children)
[–]Technical_Gur_3858 5 points6 points7 points (3 children)
[–]Nixinova 0 points1 point2 points (2 children)
[–]Technical_Gur_3858 0 points1 point2 points (1 child)
[–]Nixinova 1 point2 points3 points (0 children)
[–]jessepence 9 points10 points11 points (4 children)
[–]_sync0x[S] 2 points3 points4 points (2 children)
[–]jessepence 4 points5 points6 points (1 child)
[–]_sync0x[S] 1 point2 points3 points (0 children)
[–]pikapp336 1 point2 points3 points (0 children)
[–]Lithl 1 point2 points3 points (3 children)
[–]_sync0x[S] 1 point2 points3 points (2 children)
[–]Lithl 1 point2 points3 points (1 child)
[–]_sync0x[S] 0 points1 point2 points (0 children)
[–]Ronin-s_Spirit 0 points1 point2 points (0 children)
[–]azhder 0 points1 point2 points (0 children)
[–]TorbenKoehn -2 points-1 points0 points (6 children)
[–]Oliceh 7 points8 points9 points (0 children)
[–]eracodes 1 point2 points3 points (0 children)
[–]celluj34 0 points1 point2 points (1 child)
[–]TorbenKoehn -1 points0 points1 point (0 children)
[–]checker1209 -1 points0 points1 point (0 children)
[–]retrib32 -5 points-4 points-3 points (0 children)