forked from ulid/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.ts
More file actions
40 lines (30 loc) · 1.01 KB
/
Copy pathcli.ts
File metadata and controls
40 lines (30 loc) · 1.01 KB
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
import { monotonicFactory } from "./ulid.js";
function parseArgs(args: Array<string>): Record<string, string | boolean> {
const output = {};
while (args.length > 0) {
const arg = args.shift();
if (/^\-\-/.test(arg)) {
if (/=/.test(arg)) {
const [key, value] = arg.split("=");
output[key.substring(2)] = value;
} else {
const value = args.shift();
if (/^-/.test(value)) {
args.unshift(value);
} else if (!value) {
output[arg.substring(2)] = true;
} else {
output[arg.substring(2)] = value;
}
}
}
}
return output;
}
const argv = parseArgs(process.argv.slice(2));
const count = /^\d+/.test(argv["count"] as string) ? parseInt(argv["count"] as string, 10) : 1;
const factory = monotonicFactory();
for (let i = 0; i < count; i += 1) {
console.log(factory());
}