hs-enum
v0.1.2
Published
A JS take on Headspring Enumeration
Downloads
3
Maintainers
Readme
Headspring Enumeration
How to Install
$ npm install hs-enum
Getting Started
import E from 'hs-enum'
const myEnum = new E([
{ key: 'HELLO_MESSAGE',
value: 0,
displayName: 'Hello JavaScripters!'
}
}])
const val = myEnum.HELLO_MESSAGE.value // 0
const key = myEnum.findKeyFromValue(0) // 'HELLO_MESSAGE'
const name = myEnum.getDisplayNameFromValue(0) // 'Hello JavaScripters!'
const obj = myEnum.getFromValue(0) // {key: 'HELLO_MESSAGE', value: 0, displayName: 'Hello JavaScripters!'}
const val2 = myEnum.getValue('HELLO_MESSAGE') // 0
const displayName2 = myEnum.getDisplayName('HELLO_MESSAGE') // 'Hello JavaScripters!'
//Using an array of strings
const myOtherEnum = new E(['HELLO_JAVASCRIPTERS'])
//Start case conversion
const myFormattedDisplayName = myOtherEnum.HELLO_JAVASCRIPTERS.displayName // 'Hello Javascripters'
const indexValue = myOtherEnum.HELLO_JAVASCRIPTERS.value // 0 (index)
License
MIT © 2016