New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

iterableobject

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

iterableobject

Turn an object into an iterable object.

latest
Source
npmnpm
Version
1.1.1
Version published
Maintainers
1
Created
Source

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

FAQs

Package last updated on 05 Mar 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts