looppa
Simple functional script to loop array, strings, numbers, objects, Map and Set. Looppa will always returns a function to map your primitives
looppa(collection:any)(function(value:any, key:string|number, index:number) {}):array
Installation
npm i looppa -S
Usage
; // normalize null and undefinedconst nullCollection = ; // []const undefinedCollection = ; // [] // arrays will be left untouchedconst array = ; // [['foo', 0], [null, 1], [undefined, 2]] // numbers to arrayconst numbers = n * 2; // [2, 4, 6, 8] // strings to arrayconst string = ; // [['c', 0], ['i', 1], ['a', 2], ['o', 3]] // objects to arrayconst obj = ; // [['foo', 'bar'], ['buz', 'baz']] // Map to arrayconst myMap = ;myMap;myMap;const map = ; // [['foo', 'bar'], ['buz', 'baz']] // Set to arrayconst mySet = ;mySet;mySet;const map = ; // [['foo', 'foo'], ['bar', 'bar']]
With React.js
This script is really handy if you need to deal with React loops
<div> <h1>Array</h1> <ul> <li>number</li> </ul> <h1>Numbers</h1> <ul> <li>number</li> </ul> <h1>Letters</h1> <ul> <li>letter</li> </ul> <h1>Object</h1> <ul> value key <li>key value</li> </ul> <h1>Map</h1> <ul> value key <li>key value</li> </ul> <h1>Set</h1> <ul> <li>value</li> </ul></div>