2.0.0 • Published 5 years ago

@brunoluiz/extended-obj v2.0.0

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

@brunoluiz/extended-obj

Extended objects for JavaScript

KeyValue

Create a key-value map with extra methods, such as

  • getByValue(v: string): returns value's key
  • keys(): string: returns object keys
  • values(): string | number: returns object values
  • toJSON(): 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'
2.0.0

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.0

5 years ago