itobj
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

itobj npm

Iterate Object.

⚠️ Ignores any keys but strings in types and skips Symbols and stringifies the rest of the keys in runtime just like Object methods do.

Install

$ yarn add itobj

Usage

type TStringKey<T> = keyof T & string

const iterateObjectKeys: <T extends {}>(obj: T) => Iterable<TStringKey<T>>
const iterateObjectValues: <T extends {}>(obj: T) => Iterable<T[TStringKey<T>]>
const iterateObjectEntries: <T extends {}>(obj: T) => Iterable<[TStringKey<T>, T[TStringKey<T>]]>
import { iterateObjectKeys, iterateObjectValues, iterateObjectEntries } from 'itobj'

const obj = { a: 1, b: 2, c: 3 }

for (const key of iterateObjectKeys(obj)) {
  console.log(key)
}
// 'a'
// 'b'
// 'c'

for (const value of iterateObjectValues(obj)) {
  console.log(value)
}
// 1
// 2
// 3

for (const entry of iterateObjectEntries(obj)) {
  console.log(entry)
}
// ['a', 1]
// ['b', 2]
// ['c', 3]

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.1.0
    3
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 0.1.0
    3
  • 0.0.0
    1

Package Sidebar

Install

npm i itobj

Weekly Downloads

4

Version

0.1.0

License

MIT

Unpacked Size

12.4 kB

Total Files

9

Last publish

Collaborators

  • fosimus
  • psxcode
  • deepsweet