1.0.2 • Published 7 years ago
enumify-mod v1.0.2
enumify-mod
A JavaScript / TypeScript library for enums - mod of Enumify.
Install
npm i enumify-mod --save
Features
- enumify implementation in typescript
- Support
valueOf
methodconst Color = Enum.create('Color', ['RED', 'GREEN', 'BLUE']); Color.GREEN.valueOf() === 1 // true
- Support
fromValue
methodconst Color = Enum.create('Color', { RED: '#F00', GREEN: '#0F0', BLUE: { alias: 'blue', }, }); Color.fromValue('#0F0') === Color.GREEN // true Color.fromValue(2) === Color.BLUE // true
- Support
fromName
methodColor.fromName('GREEN') === Color.GREEN // true Color.fromName('BLUE') === Color.BLUE // true
- Require repeating all values for avoiding creating additional type
class YesNoEnum extends Enum { static YES; static NO; } YesNoEnum.initEnum({ YES: true, NO: false }); YesNoEnum.YES.valueOf() === true // true
NPM scripts
npm t
: Run test suitenpm start
: Runsnpm run build
in watch modenpm run test:watch
: Run test suite in interactive watch modenpm run test:prod
: Run linting and generate coveragenpm run build
: Generage bundles and typings, create docsnpm run lint
: Lints codenpm run commit
: Commit using conventional commit style (husky will tell you to use it if you haven't :wink:)
Thanks
@alexjoverm for nice TypeScript library starter