1.1.1 • Published 10 years ago

iterableobject v1.1.1

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

iterableobject

Create an iterable from a JavaScript object.

Usage

Normally, you cannot iterate over a JavaScript object. This, for example, will give an error:

var obj = {
    first: {
        name: 'one',
        number: 1
    },
    second: {
        name: 'two',
        number: 2
    }
};

var iterator = obj[Symbol.iterator](); // throws an error

Using iterableobject, you can create an object that can be iterated over and therefore can be used in for...of loops.

var iterable = require('iterableobject');

var armour = {
    helmet: {
        name: 'Helmet of the Gods',
        description: 'An impressive helmet, believed to have come from another realm.'
    },
    boots: {
        name: 'Steel Shoes',
        description: 'A pair of heavy steel shoes. They glisten in the sunlight.'
    }
};

for (var part of iterable(armour)) {
    console.log(part.name + ": " + part.description);
}

The output of the above example will be the following:

Helmet of the Gods: An impressive helmet, believed to have come from another realm.

Steel Shoes: A pair of heavy steel shoes. They glisten in the sunlight.

Development

You can execute the tests for this project by running npm test.

isiterable and object-equal have been used to make testing easier.

license

MIT

1.1.1

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago

0.9.0

10 years ago

0.0.3

10 years ago

0.0.2

10 years ago

0.0.1

10 years ago