MCPcopy Index your code
hub / github.com/ulid/javascript / parseArgs

Function parseArgs

source/cli.ts:5–30  ·  view source on GitHub ↗
(args: Array<string>)

Source from the content-addressed store, hash-verified

3import { monotonicFactory } from "./ulid.js";
4
5function parseArgs(args: Array<string>): Record<string, string | boolean> {
6 const output = {};
7
8 while (args.length > 0) {
9 const arg = args.shift();
10
11 if (/^\-\-/.test(arg)) {
12 if (/=/.test(arg)) {
13 const [key, value] = arg.split("=");
14 output[key.substring(2)] = value;
15 } else {
16 const value = args.shift();
17
18 if (/^-/.test(value)) {
19 args.unshift(value);
20 } else if (!value) {
21 output[arg.substring(2)] = true;
22 } else {
23 output[arg.substring(2)] = value;
24 }
25 }
26 }
27 }
28
29 return output;
30}
31
32const argv = parseArgs(process.argv.slice(2));
33

Callers 1

cli.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected