1.0.1 ā€¢ Published 3 years ago

iwrap v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

A wrapper around Iterable to bring access to powerful methods like filter, map, etc ...

Install

Install by running this command:

npm i iwrap

How to use

import { IWrap } from ".";

const scores = new Map([
    ["Alice", 500],
    ["Bob", 356],
    ["Charles", 42],
    ["David", 999],
]);

// Output wanted:
// Alice.........................500
// Bob...........................356
// Charles.......................42
// David.........................999

// Without IWrap
const display1 = Array.from(scores) //from: scores is iterated and a array is created.
    // map: previous array is iterated and a new array is created.
    .map(([name, score]) => `${name}${".".repeat(30 - name.length)}${score}`)
    // join: previous array is iterated and return a string.
    .join("\n");
// Result: 3 iterations
console.log(display1);

// With IWrap
const display2 = IWrap.from(scores) // from: creates a wrapper around scores.
    // map: a new wrapper is created around the prevous one.
    .map(([name, score]) => `${name}${".".repeat(30 - name.length)}${score}`)
    // join: iterate the previous wrapper and return a string.
    .join("\n");
// Result: 1 iteration
console.log(display2);

Author

šŸ‘¤ Tristan Guichaoua

šŸ“ License

Copyright Ā© 2021 Tristan Guichaoua. This project is MIT licensed.