File tree Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Expand file tree Collapse file tree 2 files changed +36
-4
lines changed Original file line number Diff line number Diff line change 11// deno-lint-ignore-file no-explicit-any
22
3- import { parse } from "./deps.ts" ;
43import { Hasher } from "./hasher.ts" ;
54
65const isDeno = typeof ( globalThis as any ) . Deno !== "undefined" ;
@@ -10,14 +9,48 @@ const cmd = isDeno
109 : "npx inthash" ;
1110
1211const 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
1819console . log ( JSON . stringify ( options , null , " " ) ) ;
1920console . error ( `
2021
2122$ ${ cmd } | pbcopy
2223
2324then 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 | b i t | b i t s ) = ( \d + ) / ) ) ) {
39+ const [ , key , value ] = match ;
40+ argv [ key as "b" | "bit" | "bits" ] = + value ;
41+ } else if ( ( match = arg . match ( / ^ - - ( b | b i t | b i t s ) $ / ) ) ) {
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+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments