2.0.0 • Published 5 years ago
@brunoluiz/extended-obj v2.0.0
@brunoluiz/extended-obj
Extended objects for JavaScript
KeyValue
Create a key-value map with extra methods, such as
getByValue(v: string)
: returns value's keykeys(): string
: returns object keysvalues(): string | number
: returns object valuestoJSON(): string number
: returns object as a JSON (same as JSON.stringify())
const { KeyValue } = require('@brunoluiz/extended-obj')
const o = KeyValue({ FOO: 'BAR' })
console.log(o.FOO) // BAR (normal object behaviour)
console.log(o.getByValue('BAR')) // FOO (returns value key)
console.log(o.values()) // ['BAR']
console.log(o.keys()) // ['FOO']
Enum
Create an enum with the same extras added on KeyValue
const { Enum } = require('@brunoluiz/extended-obj')
const e = Enum(['FOO', 'BAR'])
console.log(e.FOO) // 1
console.log(e.getByValue(1)) // 'FOO'