🚀 Launch Week Day 2:Introducing Custom Tabs for Org Alerts.Learn More →
Socket
Book a DemoInstallSign in
Socket

magic-iterable

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magic-iterable

Call a method on all items in an iterable by calling it on the iterable itself

Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

magic-iterable Build Status

Call a method on all items in an iterable by calling it on the iterable itself

Uses the Proxy API.

Install

$ npm install magic-iterable

Usage

const magicIterable = require('magic-iterable');

const x = {
	i: 0,
	increment(value) {
		this.i += value;
		return this.i;
	}
};

const array = [x, x, x, x];
const magicArray = magicIterable(array);

Array.isArray(magicArray);
//=> true

magicArray.increment(2);
//=> [2, 4, 6, 8];

x.i;
//=> 8
const magicIterable = require('magic-iterable');

// Subscribes to click events for all `<a>` elements
magicIterable(document.querySelectorAll('a')).addEventListener('click', () => {
	console.log('Click');
});

API

magicIterable(iterable)

Returns a version of iterable that when you call a method on it, it will call that method on all items in the iterable and return an array with the result.

iterable

Type: Iterable (For example, an Array)

Iterable where all the items has the method you want to call.

  • on-change - Watch an object or array for changes (Uses Proxy too)
  • negative-array - Negative array index support (Uses Proxy too)
  • known - Allow only access to known object properties (Uses Proxy too)

License

MIT © Sindre Sorhus

Keywords

iterable

FAQs

Package last updated on 14 Jan 2018

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