comprehension
TypeScript icon, indicating that this package has built-in type declarations

1.1.1 • Public • Published

Comprehension.js

Using

comprehension result same as
$(3, () => 'asd') ['asd', 'asd', 'asd'] new Array(3).fill('asd')
$(5) [0, 1, 2, 3, 4] new Array(5).fill(0).map((_, index) => index)
$({ count: 5, step: 3 }) [0, 3, 6, 9, 12] new Array(5).fill(0).map((_, index) => 3 * index)
$({ from: 4, to: 9 }) [4, 5, 6, 7, 8, 9] new Array(6).fill(0).map((_, index) => index + 4)
$({ from: 4, count: 5, step: -3 }) [4, 1, -2, -5, -8] new Array(5).fill(0).map((_, index) => index * -3 + 4)
$({ from: 3, count: 4 }, i => 2 ** i) [8, 16, 32, 64] new Array(4).fill(0).map((_, index) => 2 ** (index + 3))
$({ count: 5 }, () => Math.floor(Math.random() * 8)) [2, 3, 6, 4, 2] new Array(5).fill(0).map(() => Math.floor(Math.random() * 8))

Example of usage

Asynchronously creates folders with names "folder_100", "folder_106", ... , "folder_220" in directory "dist".

await mkdirp(`${__dirname}/dist`);
console.log(await Promise.all($({ from: 100, to: 220, step: 6 }, async i => {
    const path = `${__dirname}/dist/folder_${i}`;
    await mkdirp(path);
    return path;
})));

Readme

Keywords

none

Package Sidebar

Install

npm i comprehension

Weekly Downloads

1

Version

1.1.1

License

MIT

Unpacked Size

8.72 kB

Total Files

7

Last publish

Collaborators

  • nicklatkovich