-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·40 lines (31 loc) · 863 Bytes
/
Copy pathcli.js
File metadata and controls
executable file
·40 lines (31 loc) · 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env node
const meow = require('meow');
const chunkifyArray = require('.');
const cli = meow(
`
Usage
❯ chunkify-array <string> <number> [Default: '' 1]
Options
--int, -i Accept integers from comma separated input [Default: false]
Examples
❯ chunkify-array 1,2,3,4,5 3
[ [ '1', '2' ], [ '3', '4' ], [ '5' ] ]
❯ chunkify-array --int 1,2,3,4,5 3
[ [ 1, 2 ], [ 3, 4 ], [ 5 ] ]
`,
{
flags: {
int: {
type: 'boolean',
alias: 'i'
}
}
}
);
const input = cli.input[0];
const chunks = parseInt(cli.input[1], 0) || 1;
let array = (input && input.split(',')) || [];
if (cli.flags.int) {
array = array.filter(Boolean).map(Number);
}
console.log(chunkifyArray(array, chunks)); // eslint-disable-line no-console