Skip to content

Commit e685142

Browse files
committed
chore: remove deps
1 parent 1404960 commit e685142

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

cli.ts

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// deno-lint-ignore-file no-explicit-any
22

3-
import { parse } from "./deps.ts";
43
import { Hasher } from "./hasher.ts";
54

65
const isDeno = typeof (globalThis as any).Deno !== "undefined";
@@ -10,14 +9,48 @@ const cmd = isDeno
109
: "npx inthash";
1110

1211
const args = parse(
13-
isDeno ? (globalThis as any).Deno.args : (globalThis as any).process.argv,
12+
isDeno
13+
? (globalThis as any).Deno.args
14+
: (globalThis as any).process.argv.slice(2),
1415
);
1516

16-
const options = Hasher.generate(+(args.b ?? args.bit ?? args.bits ?? "53"));
17+
const options = Hasher.generate(args.b ?? args.bit ?? args.bits ?? 53);
1718

1819
console.log(JSON.stringify(options, null, " "));
1920
console.error(`
2021
2122
$ ${cmd} | pbcopy
2223
2324
then paste to your code! :-) good luck.`);
25+
26+
type Args = {
27+
b?: number;
28+
bit?: number;
29+
bits?: number;
30+
};
31+
32+
function parse(args: string[]): Args {
33+
const argv: Args = {};
34+
35+
for (let i = 0; i < args.length; i++) {
36+
const arg = args[i];
37+
let match;
38+
if ((match = arg.match(/^--(b|bit|bits)=(\d+)/))) {
39+
const [, key, value] = match;
40+
argv[key as "b" | "bit" | "bits"] = +value;
41+
} else if ((match = arg.match(/^--(b|bit|bits)$/))) {
42+
const [, key] = match;
43+
const next = args[i + 1];
44+
if (
45+
next &&
46+
/\d+/.test(next)
47+
) {
48+
argv[key as "b" | "bit" | "bits"] = +next;
49+
i++;
50+
}
51+
} else if ((match = arg.match(/^-b(\d+)/))) {
52+
argv.b = +match[1];
53+
}
54+
}
55+
return argv;
56+
}

deps.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)