JSPM

object-iterable

0.2.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 10
  • Score
    100M100P100Q34871F
  • License ISC

Create a new object containing the same properties (through assignment) of another object along with an @@iterator method can make use of the default iteration behavior (such as for-of) that built-in iterables like Array or Map have.

Package Exports

  • object-iterable

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (object-iterable) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

npm version Dependency Status

Object Iterable

Create a new object containing the same properties (through assignment) of another object along with an @@iterator method can make use of the default iteration behavior (such as for-of) that built-in iterables like Array or Map have.

npm install --save object-iterable

Let's see an example

const larry = {
  name: 'Larry Johnson',
  alias: 'Grandmama',
  position: [
    'Power Forward',
    'Small Forward'
  ],
  weight: 250,
  height: {
    feet: 6,
    inches: 6
  },
  college: 'UNLV',
  draft: {
    team: 'Charlotte Hornets',
    year: 1991,
    pick: 1
  }
};

for (let val of larry) {
  console.log(val);
}
// Uncaught TypeError: larry[Symbol.iterator] is not a function

Oh nos!

But we can get through this.

Here an iterable new object is returned with all the same properties (which after use can optionally be kept or discarded).

import iterable from 'object-iterable';

const iterableLarry = iterable(larry);

for (let val of iterableLarry) {
  console.log(val);
}
// Larry Johnson
// Grandmama
// ["Power Forward","Small Forward"]
// 250
// {"feet":6,"inches":6}
// UNLV
// {"team":"Charlotte Hornets","year":1991,"pick":1}

console.log(larry == iterableLarry);
// false