Toy parser of command line arguments. Part of the "toys" collection.
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 23 lines 626 B view raw
1export function pargser(argv: string[]) { 2 const parsedArguments: Record<string, unknown> = {}; 3 4 argv.forEach((argument) => { 5 if (argument.startsWith('--')) { 6 if (argument.length > 2) { 7 parsedArguments[argument.slice(2)] = true; 8 } 9 } else if (argument.startsWith('-')) { 10 const flags = argument.slice(1).split(''); 11 flags.forEach((flag) => { 12 parsedArguments[flag] = true; 13 }); 14 } else if (argument.includes('=')) { 15 const [name, value] = argument.split('='); 16 if (name) { 17 parsedArguments[name] = value; 18 } 19 } 20 }); 21 22 return parsedArguments; 23}