@pakal/for-each
v0.2.1
Published
ForEach is package from Pakal library
Downloads
9
Maintainers
Readme
@pakal/for-each
ForEach is package from Pakal library
Install
$ yarn add @pakal/for-each
Or
$ npm install --save @pakal/for-each
Use
Module
import {
default as forEach
} from '@pakal/for-each';
Browser
<script src="https://unpkg.com/@pakal/for-each/bundle.umd.min.js"></script>
let {
forEach
} = _;
Examples
let word: string = 'abc';
forEach(word, (char: string, index: number, array: string) => {
console.log(`${index} = ${value}`);
});
// => '0 = a'
// => '1 = b'
// => '2 = c'
// => 'abc'
let array: boolean[] = [true, true, false, true, true];
forEach(array, (value: boolean, index: number) => {
console.log(index);
return value;
});
// => 0
// => 1
// => 2
// => array
let array: ArrayLike<any> = {length: 2, 1: 'some', foo: 'bar'};
forEach(array, console.log);
// => undefined 0 array
// => 33 'some' array
// => array
let object: {[key: string: number]} = {a: 1, b: 2,c: 3};
forEach(object, (value: number, key: string, object: {[key: string: number]}) => {
console.log(`${key} = ${value}`);
});
// => 'a = 1'
// => 'b = 2'
// => 'c = 3'
// => object
forEach(); // => undefined
forEach(null); // => null
forEach(true, console.log); // => true
let _log = (value: any) => (console.log(value), value);
let collection = {
get foo(){ return _log('bar'); },
get non(){ return _log(false); },
get name(){ return _log('bob'); }
};
forEach(collection);
// => 'foo'
// => false
// => collection
License
Copyright © Yisrael Eliev, Licensed under the MIT license.