@hugoalh/adler32 0.3.0 โ 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -36
- package/mod.d.ts +10 -46
- package/mod.d.ts.map +1 -1
- package/mod.js +34 -67
- package/package.json +3 -19
- package/_dnt.polyfills.d.ts +0 -36
- package/_dnt.polyfills.d.ts.map +0 -1
- package/_dnt.polyfills.js +0 -15
- package/_dnt.shims.d.ts +0 -12
- package/_dnt.shims.d.ts.map +0 -1
- package/_dnt.shims.js +0 -70
- package/cli.d.ts +0 -3
- package/cli.d.ts.map +0 -1
- package/cli.js +0 -113
- package/deps/jsr.io/@std/cli/1.0.9/parse_args.d.ts +0 -233
- package/deps/jsr.io/@std/cli/1.0.9/parse_args.d.ts.map +0 -1
- package/deps/jsr.io/@std/cli/1.0.9/parse_args.js +0 -305
package/README.md
CHANGED
|
@@ -6,18 +6,17 @@
|
|
|
6
6
|
[](https://jsr.io/@hugoalh/adler32)
|
|
7
7
|
[](https://www.npmjs.com/package/@hugoalh/adler32)
|
|
8
8
|
|
|
9
|
-
An
|
|
9
|
+
An ECMAScript (JavaScript & TypeScript) module to get the checksum of the data with algorithm Adler32.
|
|
10
10
|
|
|
11
11
|
## ๐ฐ Begin
|
|
12
12
|
|
|
13
13
|
### ๐ฏ Targets
|
|
14
14
|
|
|
15
|
-
|
|
|
16
|
-
|
|
17
|
-
| **[Bun](https://bun.sh/)** >= v1.1.0 | โ |
|
|
18
|
-
| **[
|
|
19
|
-
| **[
|
|
20
|
-
| **[NodeJS](https://nodejs.org/)** >= v16.13.0 | โ | โ | โ๏ธ |
|
|
15
|
+
| **Targets** | **Remote** | **JSR** | **NPM** |
|
|
16
|
+
|:--|:-:|:-:|:-:|
|
|
17
|
+
| **[Bun](https://bun.sh/)** >= v1.1.0 | โ | โ๏ธ | โ๏ธ |
|
|
18
|
+
| **[Deno](https://deno.land/)** >= v2.1.0 | โ๏ธ | โ๏ธ | โ๏ธ |
|
|
19
|
+
| **[NodeJS](https://nodejs.org/)** >= v20.9.0 | โ | โ๏ธ | โ๏ธ |
|
|
21
20
|
|
|
22
21
|
> [!NOTE]
|
|
23
22
|
> - It is possible to use this module in other methods/ways which not listed in here, however those methods/ways are not officially supported, and should beware maybe cause security issues.
|
|
@@ -50,8 +49,7 @@ An ES (JavaScript & TypeScript) CLI and module to get the checksum of the data w
|
|
|
50
49
|
|
|
51
50
|
### ๐ก๏ธ Runtime Permissions
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
- *Resources* (Optional)
|
|
52
|
+
*This module does not request any runtime permission.*
|
|
55
53
|
|
|
56
54
|
## ๐งฉ APIs
|
|
57
55
|
|
|
@@ -60,20 +58,19 @@ An ES (JavaScript & TypeScript) CLI and module to get the checksum of the data w
|
|
|
60
58
|
constructor(data?: Adler32AcceptDataType);
|
|
61
59
|
get freezed(): boolean;
|
|
62
60
|
freeze(): this;
|
|
63
|
-
hash():
|
|
64
|
-
hashBase16(): string;
|
|
65
|
-
hashBase32Hex(): string;
|
|
66
|
-
hashBase36(): string;
|
|
67
|
-
hashBigInt(): bigint;
|
|
61
|
+
hash(): Uint8Array;
|
|
68
62
|
hashHex(): string;
|
|
69
|
-
hashHexPadding(): string;
|
|
70
|
-
hashNumber(): number;
|
|
71
63
|
update(data: Adler32AcceptDataType): this;
|
|
72
|
-
|
|
64
|
+
updateFromStream(stream: ReadableStream<Adler32AcceptDataType>): Promise<this>;
|
|
73
65
|
}
|
|
74
66
|
```
|
|
75
67
|
- ```ts
|
|
76
|
-
type Adler32AcceptDataType =
|
|
68
|
+
type Adler32AcceptDataType =
|
|
69
|
+
| string
|
|
70
|
+
| BigUint64Array
|
|
71
|
+
| Uint8Array
|
|
72
|
+
| Uint16Array
|
|
73
|
+
| Uint32Array;
|
|
77
74
|
```
|
|
78
75
|
|
|
79
76
|
> [!NOTE]
|
|
@@ -81,26 +78,9 @@ An ES (JavaScript & TypeScript) CLI and module to get the checksum of the data w
|
|
|
81
78
|
> - [Deno CLI `deno doc`](https://docs.deno.com/runtime/reference/cli/documentation_generator/)
|
|
82
79
|
> - [JSR](https://jsr.io/@hugoalh/adler32)
|
|
83
80
|
|
|
84
|
-
## ๐งฉ CLIs
|
|
85
|
-
|
|
86
|
-
**Entrypoint:** `cli.js`/`cli.ts`
|
|
87
|
-
|
|
88
|
-
- From argument; Output hex padding
|
|
89
|
-
```ps1
|
|
90
|
-
adler32 {Data}
|
|
91
|
-
```
|
|
92
|
-
- From file; Output hex padding
|
|
93
|
-
```ps1
|
|
94
|
-
adler32 --file {FilePath}
|
|
95
|
-
```
|
|
96
|
-
- From stdin; Output hex padding
|
|
97
|
-
```ps1
|
|
98
|
-
adler32 --stdin
|
|
99
|
-
```
|
|
100
|
-
|
|
101
81
|
## โ๏ธ Examples
|
|
102
82
|
|
|
103
83
|
- ```ts
|
|
104
|
-
new Adler32("Wikipedia").
|
|
84
|
+
new Adler32("Wikipedia").hashHex();
|
|
105
85
|
//=> "11E60398"
|
|
106
86
|
```
|
package/mod.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "./_dnt.polyfills.js";
|
|
2
1
|
export type Adler32AcceptDataType = string | BigUint64Array | Uint8Array | Uint16Array | Uint32Array;
|
|
3
2
|
/**
|
|
4
3
|
* Get the checksum of the data with algorithm Adler32.
|
|
@@ -8,7 +7,7 @@ export declare class Adler32 {
|
|
|
8
7
|
get [Symbol.toStringTag](): string;
|
|
9
8
|
/**
|
|
10
9
|
* Initialize.
|
|
11
|
-
* @param {Adler32AcceptDataType} [data] Data. Can append later via the method {@linkcode Adler32.update}.
|
|
10
|
+
* @param {Adler32AcceptDataType} [data] Data. Can append later via the method {@linkcode Adler32.update} and {@linkcode Adler32.updateFromStream}.
|
|
12
11
|
*/
|
|
13
12
|
constructor(data?: Adler32AcceptDataType);
|
|
14
13
|
/**
|
|
@@ -17,55 +16,20 @@ export declare class Adler32 {
|
|
|
17
16
|
*/
|
|
18
17
|
get freezed(): boolean;
|
|
19
18
|
/**
|
|
20
|
-
* Freeze the instance to prevent any update.
|
|
19
|
+
* Freeze the instance to prevent any further update.
|
|
21
20
|
* @returns {this}
|
|
22
21
|
*/
|
|
23
22
|
freeze(): this;
|
|
24
23
|
/**
|
|
25
|
-
* Get the checksum of the data, in
|
|
26
|
-
* @returns {
|
|
24
|
+
* Get the checksum of the data, in Uint8Array.
|
|
25
|
+
* @returns {Uint8Array}
|
|
27
26
|
*/
|
|
28
|
-
hash():
|
|
27
|
+
hash(): Uint8Array;
|
|
29
28
|
/**
|
|
30
|
-
* Get the checksum of the data, in
|
|
31
|
-
* @returns {string}
|
|
32
|
-
*/
|
|
33
|
-
hashBase16(): string;
|
|
34
|
-
/**
|
|
35
|
-
* Get the checksum of the data, in Base32Hex ({@link https://datatracker.ietf.org/doc/html/rfc4648#section-7 RFC 4648 ยง7}).
|
|
36
|
-
* @returns {string}
|
|
37
|
-
*/
|
|
38
|
-
hashBase32Hex(): string;
|
|
39
|
-
/**
|
|
40
|
-
* Get the checksum of the data, in Base36.
|
|
41
|
-
* @returns {string}
|
|
42
|
-
*/
|
|
43
|
-
hashBase36(): string;
|
|
44
|
-
/**
|
|
45
|
-
* Get the checksum of the data, in big integer.
|
|
46
|
-
* @returns {bigint}
|
|
47
|
-
*/
|
|
48
|
-
hashBigInt(): bigint;
|
|
49
|
-
/**
|
|
50
|
-
* Get the checksum of the data, in big integer.
|
|
51
|
-
* @returns {bigint}
|
|
52
|
-
*/
|
|
53
|
-
hashBigInteger: () => bigint;
|
|
54
|
-
/**
|
|
55
|
-
* Get the checksum of the data, in hex/hexadecimal without padding.
|
|
29
|
+
* Get the checksum of the data, in hexadecimal with padding.
|
|
56
30
|
* @returns {string}
|
|
57
31
|
*/
|
|
58
32
|
hashHex(): string;
|
|
59
|
-
/**
|
|
60
|
-
* Get the checksum of the data, in hex/hexadecimal with padding.
|
|
61
|
-
* @returns {string}
|
|
62
|
-
*/
|
|
63
|
-
hashHexPadding(): string;
|
|
64
|
-
/**
|
|
65
|
-
* Get the checksum of the data, in number.
|
|
66
|
-
* @returns {number}
|
|
67
|
-
*/
|
|
68
|
-
hashNumber(): number;
|
|
69
33
|
/**
|
|
70
34
|
* Append data.
|
|
71
35
|
* @param {Adler32AcceptDataType} data Data.
|
|
@@ -73,11 +37,11 @@ export declare class Adler32 {
|
|
|
73
37
|
*/
|
|
74
38
|
update(data: Adler32AcceptDataType): this;
|
|
75
39
|
/**
|
|
76
|
-
*
|
|
77
|
-
* @param {ReadableStream<Adler32AcceptDataType>} stream
|
|
78
|
-
* @returns {Promise<
|
|
40
|
+
* Append data from the readable stream.
|
|
41
|
+
* @param {ReadableStream<Adler32AcceptDataType>} stream Data from the readable stream.
|
|
42
|
+
* @returns {Promise<this>}
|
|
79
43
|
*/
|
|
80
|
-
|
|
44
|
+
updateFromStream(stream: ReadableStream<Adler32AcceptDataType>): Promise<this>;
|
|
81
45
|
}
|
|
82
46
|
export default Adler32;
|
|
83
47
|
//# sourceMappingURL=mod.d.ts.map
|
package/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["src/mod.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,qBAAqB,GAC9B,MAAM,GACN,cAAc,GACd,UAAU,GACV,WAAW,GACX,WAAW,CAAC;AACf;;GAEG;AACH,qBAAa,OAAO;;IACnB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,MAAM,CAEjC;IAMD;;;OAGG;gBACS,IAAI,CAAC,EAAE,qBAAqB;IAKxC;;;OAGG;IACH,IAAI,OAAO,IAAI,OAAO,CAErB;IACD;;;OAGG;IACH,MAAM,IAAI,IAAI;IAId;;;OAGG;IACH,IAAI,IAAI,UAAU;IAalB;;;OAGG;IACH,OAAO,IAAI,MAAM;IASjB;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI;IAazC;;;;OAIG;IACG,gBAAgB,CAAC,MAAM,EAAE,cAAc,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;CAMpF;AACD,eAAe,OAAO,CAAC"}
|
package/mod.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import "./_dnt.polyfills.js";
|
|
2
1
|
/**
|
|
3
2
|
* Get the checksum of the data with algorithm Adler32.
|
|
4
3
|
*/
|
|
@@ -7,12 +6,13 @@ export class Adler32 {
|
|
|
7
6
|
return "Adler32";
|
|
8
7
|
}
|
|
9
8
|
#freezed = false;
|
|
10
|
-
#
|
|
9
|
+
#hashHex = null;
|
|
10
|
+
#hashUint8Array = null;
|
|
11
11
|
#a = 1n;
|
|
12
12
|
#b = 0n;
|
|
13
13
|
/**
|
|
14
14
|
* Initialize.
|
|
15
|
-
* @param {Adler32AcceptDataType} [data] Data. Can append later via the method {@linkcode Adler32.update}.
|
|
15
|
+
* @param {Adler32AcceptDataType} [data] Data. Can append later via the method {@linkcode Adler32.update} and {@linkcode Adler32.updateFromStream}.
|
|
16
16
|
*/
|
|
17
17
|
constructor(data) {
|
|
18
18
|
if (typeof data !== "undefined") {
|
|
@@ -27,7 +27,7 @@ export class Adler32 {
|
|
|
27
27
|
return this.#freezed;
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
|
-
* Freeze the instance to prevent any update.
|
|
30
|
+
* Freeze the instance to prevent any further update.
|
|
31
31
|
* @returns {this}
|
|
32
32
|
*/
|
|
33
33
|
freeze() {
|
|
@@ -35,68 +35,34 @@ export class Adler32 {
|
|
|
35
35
|
return this;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
|
-
* Get the checksum of the data, in
|
|
39
|
-
* @returns {
|
|
38
|
+
* Get the checksum of the data, in Uint8Array.
|
|
39
|
+
* @returns {Uint8Array}
|
|
40
40
|
*/
|
|
41
41
|
hash() {
|
|
42
|
-
if (this.#
|
|
43
|
-
|
|
42
|
+
if (this.#hashUint8Array === null) {
|
|
43
|
+
const hex = this.hashHex();
|
|
44
|
+
const bytes = [];
|
|
45
|
+
for (let index = 0; index < hex.length; index += 2) {
|
|
46
|
+
bytes.push(hex.slice(index, index + 2));
|
|
47
|
+
}
|
|
48
|
+
this.#hashUint8Array = Uint8Array.from(bytes.map((byte) => {
|
|
49
|
+
return Number.parseInt(byte, 16);
|
|
50
|
+
}));
|
|
44
51
|
}
|
|
45
|
-
return this.#
|
|
52
|
+
return Uint8Array.from(this.#hashUint8Array);
|
|
46
53
|
}
|
|
47
54
|
/**
|
|
48
|
-
* Get the checksum of the data, in
|
|
49
|
-
* @returns {string}
|
|
50
|
-
*/
|
|
51
|
-
hashBase16() {
|
|
52
|
-
return this.hashBigInt().toString(16).toUpperCase();
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Get the checksum of the data, in Base32Hex ({@link https://datatracker.ietf.org/doc/html/rfc4648#section-7 RFC 4648 ยง7}).
|
|
56
|
-
* @returns {string}
|
|
57
|
-
*/
|
|
58
|
-
hashBase32Hex() {
|
|
59
|
-
return this.hashBigInt().toString(32).toUpperCase();
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Get the checksum of the data, in Base36.
|
|
63
|
-
* @returns {string}
|
|
64
|
-
*/
|
|
65
|
-
hashBase36() {
|
|
66
|
-
return this.hashBigInt().toString(36).toUpperCase();
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Get the checksum of the data, in big integer.
|
|
70
|
-
* @returns {bigint}
|
|
71
|
-
*/
|
|
72
|
-
hashBigInt() {
|
|
73
|
-
return this.hash();
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Get the checksum of the data, in big integer.
|
|
77
|
-
* @returns {bigint}
|
|
78
|
-
*/
|
|
79
|
-
hashBigInteger = this.hashBigInt;
|
|
80
|
-
/**
|
|
81
|
-
* Get the checksum of the data, in hex/hexadecimal without padding.
|
|
55
|
+
* Get the checksum of the data, in hexadecimal with padding.
|
|
82
56
|
* @returns {string}
|
|
83
57
|
*/
|
|
84
58
|
hashHex() {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return this.hashHex().padStart(8, "0");
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Get the checksum of the data, in number.
|
|
96
|
-
* @returns {number}
|
|
97
|
-
*/
|
|
98
|
-
hashNumber() {
|
|
99
|
-
return Number(this.hash());
|
|
59
|
+
if (this.#hashHex === null) {
|
|
60
|
+
this.#hashHex = (this.#b * 65536n + this.#a).toString(16).toUpperCase().padStart(8, "0");
|
|
61
|
+
if (this.#hashHex.length !== 8) {
|
|
62
|
+
throw new Error(`Unexpected hash hex result \`${this.#hashHex}\`! Please submit a bug report.`);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return this.#hashHex;
|
|
100
66
|
}
|
|
101
67
|
/**
|
|
102
68
|
* Append data.
|
|
@@ -107,24 +73,25 @@ export class Adler32 {
|
|
|
107
73
|
if (this.#freezed) {
|
|
108
74
|
throw new Error(`Instance is freezed!`);
|
|
109
75
|
}
|
|
110
|
-
this.#
|
|
111
|
-
|
|
76
|
+
this.#hashHex = null;
|
|
77
|
+
this.#hashUint8Array = null;
|
|
78
|
+
const dataFmt = (typeof data === "string") ? new TextEncoder().encode(data) : data;
|
|
79
|
+
for (const byte of dataFmt) {
|
|
112
80
|
this.#a = (this.#a + BigInt(byte)) % 65521n;
|
|
113
81
|
this.#b = (this.#b + this.#a) % 65521n;
|
|
114
82
|
}
|
|
115
83
|
return this;
|
|
116
84
|
}
|
|
117
85
|
/**
|
|
118
|
-
*
|
|
119
|
-
* @param {ReadableStream<Adler32AcceptDataType>} stream
|
|
120
|
-
* @returns {Promise<
|
|
86
|
+
* Append data from the readable stream.
|
|
87
|
+
* @param {ReadableStream<Adler32AcceptDataType>} stream Data from the readable stream.
|
|
88
|
+
* @returns {Promise<this>}
|
|
121
89
|
*/
|
|
122
|
-
|
|
123
|
-
const instance = new this();
|
|
90
|
+
async updateFromStream(stream) {
|
|
124
91
|
for await (const chunk of stream) {
|
|
125
|
-
|
|
92
|
+
this.update(chunk);
|
|
126
93
|
}
|
|
127
|
-
return
|
|
94
|
+
return this;
|
|
128
95
|
}
|
|
129
96
|
}
|
|
130
97
|
export default Adler32;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hugoalh/adler32",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "A module to get the checksum of the data with algorithm Adler32.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"adler32",
|
|
7
7
|
"checksum"
|
|
@@ -13,18 +13,9 @@
|
|
|
13
13
|
"license": "MIT",
|
|
14
14
|
"author": "hugoalh",
|
|
15
15
|
"type": "module",
|
|
16
|
-
"bin": {
|
|
17
|
-
"adler32": "./cli.js"
|
|
18
|
-
},
|
|
19
16
|
"main": "./mod.js",
|
|
20
17
|
"module": "./mod.js",
|
|
21
18
|
"exports": {
|
|
22
|
-
"./cli": {
|
|
23
|
-
"import": {
|
|
24
|
-
"types": "./cli.d.ts",
|
|
25
|
-
"default": "./cli.js"
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
19
|
".": {
|
|
29
20
|
"import": {
|
|
30
21
|
"types": "./mod.d.ts",
|
|
@@ -38,17 +29,10 @@
|
|
|
38
29
|
"url": "git+https://github.com/hugoalh/adler32-es.git"
|
|
39
30
|
},
|
|
40
31
|
"scripts": {},
|
|
41
|
-
"dependencies": {
|
|
42
|
-
"@deno/shim-deno": "~0.18.0",
|
|
43
|
-
"@deno/shim-prompts": "~0.1.0",
|
|
44
|
-
"@deno/shim-timers": "~0.1.0"
|
|
45
|
-
},
|
|
46
32
|
"devDependencies": {
|
|
47
33
|
"@types/node": "^20.9.0"
|
|
48
34
|
},
|
|
49
|
-
"engines": {
|
|
50
|
-
"node": ">=16.13.0"
|
|
51
|
-
},
|
|
35
|
+
"engines": {},
|
|
52
36
|
"private": false,
|
|
53
37
|
"publishConfig": {
|
|
54
38
|
"access": "public"
|
package/_dnt.polyfills.d.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
declare global {
|
|
2
|
-
interface ImportMeta {
|
|
3
|
-
/** A flag that indicates if the current module is the main module that was
|
|
4
|
-
* called when starting the program under Deno.
|
|
5
|
-
*
|
|
6
|
-
* ```ts
|
|
7
|
-
* if (import.meta.main) {
|
|
8
|
-
* // this was loaded as the main module, maybe do some bootstrapping
|
|
9
|
-
* }
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
main: boolean;
|
|
13
|
-
/** A function that returns resolved specifier as if it would be imported
|
|
14
|
-
* using `import(specifier)`.
|
|
15
|
-
*
|
|
16
|
-
* ```ts
|
|
17
|
-
* console.log(import.meta.resolve("./foo.js"));
|
|
18
|
-
* // file:///dev/foo.js
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
|
-
resolve(specifier: string): string;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
export {};
|
|
25
|
-
declare global {
|
|
26
|
-
interface Object {
|
|
27
|
-
/**
|
|
28
|
-
* Determines whether an object has a property with the specified name.
|
|
29
|
-
* @param o An object.
|
|
30
|
-
* @param v A property name.
|
|
31
|
-
*/
|
|
32
|
-
hasOwn(o: object, v: PropertyKey): boolean;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
export {};
|
|
36
|
-
//# sourceMappingURL=_dnt.polyfills.d.ts.map
|
package/_dnt.polyfills.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;WAQG;QACH,IAAI,EAAE,OAAO,CAAC;QAEd;;;;;;;WAOG;QAEH,OAAO,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAAC;KACpC;CACF;AAED,OAAO,EAAE,CAAA;AAgBT,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC"}
|
package/_dnt.polyfills.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
|
|
2
|
-
if (!Object.hasOwn) {
|
|
3
|
-
Object.defineProperty(Object, "hasOwn", {
|
|
4
|
-
value: function (object, property) {
|
|
5
|
-
if (object == null) {
|
|
6
|
-
throw new TypeError("Cannot convert undefined or null to object");
|
|
7
|
-
}
|
|
8
|
-
return Object.prototype.hasOwnProperty.call(Object(object), property);
|
|
9
|
-
},
|
|
10
|
-
configurable: true,
|
|
11
|
-
enumerable: false,
|
|
12
|
-
writable: true,
|
|
13
|
-
});
|
|
14
|
-
}
|
|
15
|
-
export {};
|
package/_dnt.shims.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export { Deno } from "@deno/shim-deno";
|
|
2
|
-
export { alert, confirm, prompt } from "@deno/shim-prompts";
|
|
3
|
-
export { setInterval, setTimeout } from "@deno/shim-timers";
|
|
4
|
-
export declare const dntGlobalThis: Omit<typeof globalThis, "Deno" | "alert" | "confirm" | "prompt" | "setInterval" | "setTimeout"> & {
|
|
5
|
-
Deno: any;
|
|
6
|
-
alert: any;
|
|
7
|
-
confirm: any;
|
|
8
|
-
prompt: any;
|
|
9
|
-
setInterval: any;
|
|
10
|
-
setTimeout: any;
|
|
11
|
-
};
|
|
12
|
-
//# sourceMappingURL=_dnt.shims.d.ts.map
|
package/_dnt.shims.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"_dnt.shims.d.ts","sourceRoot":"","sources":["../src/_dnt.shims.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAU5D,eAAO,MAAM,aAAa;;;;;;;CAA2C,CAAC"}
|
package/_dnt.shims.js
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Deno } from "@deno/shim-deno";
|
|
2
|
-
export { Deno } from "@deno/shim-deno";
|
|
3
|
-
import { alert, confirm, prompt } from "@deno/shim-prompts";
|
|
4
|
-
export { alert, confirm, prompt } from "@deno/shim-prompts";
|
|
5
|
-
import { setInterval, setTimeout } from "@deno/shim-timers";
|
|
6
|
-
export { setInterval, setTimeout } from "@deno/shim-timers";
|
|
7
|
-
const dntGlobals = {
|
|
8
|
-
Deno,
|
|
9
|
-
alert,
|
|
10
|
-
confirm,
|
|
11
|
-
prompt,
|
|
12
|
-
setInterval,
|
|
13
|
-
setTimeout,
|
|
14
|
-
};
|
|
15
|
-
export const dntGlobalThis = createMergeProxy(globalThis, dntGlobals);
|
|
16
|
-
function createMergeProxy(baseObj, extObj) {
|
|
17
|
-
return new Proxy(baseObj, {
|
|
18
|
-
get(_target, prop, _receiver) {
|
|
19
|
-
if (prop in extObj) {
|
|
20
|
-
return extObj[prop];
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
return baseObj[prop];
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
set(_target, prop, value) {
|
|
27
|
-
if (prop in extObj) {
|
|
28
|
-
delete extObj[prop];
|
|
29
|
-
}
|
|
30
|
-
baseObj[prop] = value;
|
|
31
|
-
return true;
|
|
32
|
-
},
|
|
33
|
-
deleteProperty(_target, prop) {
|
|
34
|
-
let success = false;
|
|
35
|
-
if (prop in extObj) {
|
|
36
|
-
delete extObj[prop];
|
|
37
|
-
success = true;
|
|
38
|
-
}
|
|
39
|
-
if (prop in baseObj) {
|
|
40
|
-
delete baseObj[prop];
|
|
41
|
-
success = true;
|
|
42
|
-
}
|
|
43
|
-
return success;
|
|
44
|
-
},
|
|
45
|
-
ownKeys(_target) {
|
|
46
|
-
const baseKeys = Reflect.ownKeys(baseObj);
|
|
47
|
-
const extKeys = Reflect.ownKeys(extObj);
|
|
48
|
-
const extKeysSet = new Set(extKeys);
|
|
49
|
-
return [...baseKeys.filter((k) => !extKeysSet.has(k)), ...extKeys];
|
|
50
|
-
},
|
|
51
|
-
defineProperty(_target, prop, desc) {
|
|
52
|
-
if (prop in extObj) {
|
|
53
|
-
delete extObj[prop];
|
|
54
|
-
}
|
|
55
|
-
Reflect.defineProperty(baseObj, prop, desc);
|
|
56
|
-
return true;
|
|
57
|
-
},
|
|
58
|
-
getOwnPropertyDescriptor(_target, prop) {
|
|
59
|
-
if (prop in extObj) {
|
|
60
|
-
return Reflect.getOwnPropertyDescriptor(extObj, prop);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
return Reflect.getOwnPropertyDescriptor(baseObj, prop);
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
has(_target, prop) {
|
|
67
|
-
return prop in extObj || prop in baseObj;
|
|
68
|
-
},
|
|
69
|
-
});
|
|
70
|
-
}
|
package/cli.d.ts
DELETED
package/cli.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,qBAAqB,CAAC;AAC7B,OAAO,qBAAqB,CAAC"}
|
package/cli.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import "./_dnt.polyfills.js";
|
|
3
|
-
import * as dntShim from "./_dnt.shims.js";
|
|
4
|
-
var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
|
|
5
|
-
if (value !== null && value !== void 0) {
|
|
6
|
-
if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
|
|
7
|
-
var dispose, inner;
|
|
8
|
-
if (async) {
|
|
9
|
-
if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
|
|
10
|
-
dispose = value[Symbol.asyncDispose];
|
|
11
|
-
}
|
|
12
|
-
if (dispose === void 0) {
|
|
13
|
-
if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
|
|
14
|
-
dispose = value[Symbol.dispose];
|
|
15
|
-
if (async) inner = dispose;
|
|
16
|
-
}
|
|
17
|
-
if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
|
|
18
|
-
if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
|
|
19
|
-
env.stack.push({ value: value, dispose: dispose, async: async });
|
|
20
|
-
}
|
|
21
|
-
else if (async) {
|
|
22
|
-
env.stack.push({ async: true });
|
|
23
|
-
}
|
|
24
|
-
return value;
|
|
25
|
-
};
|
|
26
|
-
var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
|
|
27
|
-
return function (env) {
|
|
28
|
-
function fail(e) {
|
|
29
|
-
env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
|
|
30
|
-
env.hasError = true;
|
|
31
|
-
}
|
|
32
|
-
var r, s = 0;
|
|
33
|
-
function next() {
|
|
34
|
-
while (r = env.stack.pop()) {
|
|
35
|
-
try {
|
|
36
|
-
if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
|
|
37
|
-
if (r.dispose) {
|
|
38
|
-
var result = r.dispose.call(r.value);
|
|
39
|
-
if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
|
|
40
|
-
}
|
|
41
|
-
else s |= 1;
|
|
42
|
-
}
|
|
43
|
-
catch (e) {
|
|
44
|
-
fail(e);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
|
|
48
|
-
if (env.hasError) throw env.error;
|
|
49
|
-
}
|
|
50
|
-
return next();
|
|
51
|
-
};
|
|
52
|
-
})(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
53
|
-
var e = new Error(message);
|
|
54
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
55
|
-
});
|
|
56
|
-
import { parseArgs } from "./deps/jsr.io/@std/cli/1.0.9/parse_args.js";
|
|
57
|
-
import { Adler32 } from "./mod.js";
|
|
58
|
-
if (!(import.meta.url === ("file:///" + process.argv[1].replace(/\\/g, "/")).replace(/\/{3,}/, "///"))) {
|
|
59
|
-
throw new Error(`This script is for command line usage only!`);
|
|
60
|
-
}
|
|
61
|
-
const args = parseArgs(dntShim.Deno.args, {
|
|
62
|
-
boolean: [
|
|
63
|
-
"file",
|
|
64
|
-
"stdin"
|
|
65
|
-
]
|
|
66
|
-
});
|
|
67
|
-
const fromFile = args.file;
|
|
68
|
-
const fromStdin = args.stdin;
|
|
69
|
-
const argsValues = args._.map((value) => {
|
|
70
|
-
return String(value);
|
|
71
|
-
});
|
|
72
|
-
if (fromFile && fromStdin) {
|
|
73
|
-
throw new SyntaxError(`Unable to use the sources of file and stdin together!`);
|
|
74
|
-
}
|
|
75
|
-
if (fromFile) {
|
|
76
|
-
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
77
|
-
try {
|
|
78
|
-
if (argsValues.length === 0) {
|
|
79
|
-
throw new SyntaxError(`File path is not defined!`);
|
|
80
|
-
}
|
|
81
|
-
if (argsValues.length !== 1) {
|
|
82
|
-
throw new SyntaxError(`Too many arguments! Expect: 1; Current: ${argsValues.length}.`);
|
|
83
|
-
}
|
|
84
|
-
const file = __addDisposableResource(env_1, await dntShim.Deno.open(argsValues[0]), false);
|
|
85
|
-
console.log((await Adler32.fromStream(file.readable)).hashHexPadding());
|
|
86
|
-
}
|
|
87
|
-
catch (e_1) {
|
|
88
|
-
env_1.error = e_1;
|
|
89
|
-
env_1.hasError = true;
|
|
90
|
-
}
|
|
91
|
-
finally {
|
|
92
|
-
__disposeResources(env_1);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
else if (fromStdin) {
|
|
96
|
-
if (argsValues.length !== 0) {
|
|
97
|
-
throw new SyntaxError(`Too many arguments! Expect: 0; Current: ${argsValues.length}.`);
|
|
98
|
-
}
|
|
99
|
-
let data = Uint8Array.from([]);
|
|
100
|
-
for await (const chunk of dntShim.Deno.stdin.readable) {
|
|
101
|
-
data = Uint8Array.from([...data, ...chunk]);
|
|
102
|
-
}
|
|
103
|
-
console.log(new Adler32(new TextDecoder().decode(data).replace(/\r?\n$/, "")).hashHexPadding());
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
if (argsValues.length === 0) {
|
|
107
|
-
throw new SyntaxError(`Data is not defined!`);
|
|
108
|
-
}
|
|
109
|
-
if (argsValues.length !== 1) {
|
|
110
|
-
throw new SyntaxError(`Too many arguments! Expect: 1; Current: ${argsValues.length}.`);
|
|
111
|
-
}
|
|
112
|
-
console.log(new Adler32(argsValues[0]).hashHexPadding());
|
|
113
|
-
}
|
|
@@ -1,233 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Command line arguments parser based on
|
|
3
|
-
* {@link https://github.com/minimistjs/minimist | minimist}.
|
|
4
|
-
*
|
|
5
|
-
* @example Usage
|
|
6
|
-
* ```ts
|
|
7
|
-
* import { parseArgs } from "@std/cli/parse-args";
|
|
8
|
-
*
|
|
9
|
-
* const args = parseArgs(Deno.args);
|
|
10
|
-
* ```
|
|
11
|
-
*
|
|
12
|
-
* @module
|
|
13
|
-
*/
|
|
14
|
-
/** Combines recursively all intersection types and returns a new single type.
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
type Id<TRecord> = TRecord extends Record<string, unknown> ? TRecord extends infer InferredRecord ? {
|
|
18
|
-
[Key in keyof InferredRecord]: Id<InferredRecord[Key]>;
|
|
19
|
-
} : never : TRecord;
|
|
20
|
-
/** Converts a union type `A | B | C` into an intersection type `A & B & C`.
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
type UnionToIntersection<TValue> = (TValue extends unknown ? (args: TValue) => unknown : never) extends (args: infer R) => unknown ? R extends Record<string, unknown> ? R : never : never;
|
|
24
|
-
/** @internal */
|
|
25
|
-
type BooleanType = boolean | string | undefined;
|
|
26
|
-
/** @internal */
|
|
27
|
-
type StringType = string | undefined;
|
|
28
|
-
/** @internal */
|
|
29
|
-
type ArgType = StringType | BooleanType;
|
|
30
|
-
/** @internal */
|
|
31
|
-
type Collectable = string | undefined;
|
|
32
|
-
/** @internal */
|
|
33
|
-
type Negatable = string | undefined;
|
|
34
|
-
type UseTypes<TBooleans extends BooleanType, TStrings extends StringType, TCollectable extends Collectable> = undefined extends ((false extends TBooleans ? undefined : TBooleans) & TCollectable & TStrings) ? false : true;
|
|
35
|
-
/**
|
|
36
|
-
* Creates a record with all available flags with the corresponding type and
|
|
37
|
-
* default type.
|
|
38
|
-
* @internal
|
|
39
|
-
*/
|
|
40
|
-
type Values<TBooleans extends BooleanType, TStrings extends StringType, TCollectable extends Collectable, TNegatable extends Negatable, TDefault extends Record<string, unknown> | undefined, TAliases extends Aliases | undefined> = UseTypes<TBooleans, TStrings, TCollectable> extends true ? Record<string, unknown> & AddAliases<SpreadDefaults<CollectValues<TStrings, string, TCollectable, TNegatable> & RecursiveRequired<CollectValues<TBooleans, boolean, TCollectable>> & CollectUnknownValues<TBooleans, TStrings, TCollectable, TNegatable>, DedotRecord<TDefault>>, TAliases> : Record<string, any>;
|
|
41
|
-
/** @internal */
|
|
42
|
-
type Aliases<TArgNames = string, TAliasNames extends string = string> = Partial<Record<Extract<TArgNames, string>, TAliasNames | ReadonlyArray<TAliasNames>>>;
|
|
43
|
-
type AddAliases<TArgs, TAliases extends Aliases | undefined> = {
|
|
44
|
-
[TArgName in keyof TArgs as AliasNames<TArgName, TAliases>]: TArgs[TArgName];
|
|
45
|
-
};
|
|
46
|
-
type AliasNames<TArgName, TAliases extends Aliases | undefined> = TArgName extends keyof TAliases ? string extends TAliases[TArgName] ? TArgName : TAliases[TArgName] extends string ? TArgName | TAliases[TArgName] : TAliases[TArgName] extends Array<string> ? TArgName | TAliases[TArgName][number] : TArgName : TArgName;
|
|
47
|
-
/**
|
|
48
|
-
* Spreads all default values of Record `TDefaults` into Record `TArgs`
|
|
49
|
-
* and makes default values required.
|
|
50
|
-
*
|
|
51
|
-
* **Example:**
|
|
52
|
-
* `SpreadValues<{ foo?: boolean, bar?: number }, { foo: number }>`
|
|
53
|
-
*
|
|
54
|
-
* **Result:** `{ foo: boolean | number, bar?: number }`
|
|
55
|
-
*/
|
|
56
|
-
type SpreadDefaults<TArgs, TDefaults> = TDefaults extends undefined ? TArgs : TArgs extends Record<string, unknown> ? Omit<TArgs, keyof TDefaults> & {
|
|
57
|
-
[Default in keyof TDefaults]: Default extends keyof TArgs ? (TArgs[Default] & TDefaults[Default] | TDefaults[Default]) extends Record<string, unknown> ? NonNullable<SpreadDefaults<TArgs[Default], TDefaults[Default]>> : TDefaults[Default] | NonNullable<TArgs[Default]> : unknown;
|
|
58
|
-
} : never;
|
|
59
|
-
/**
|
|
60
|
-
* Defines the Record for the `default` option to add
|
|
61
|
-
* auto-suggestion support for IDE's.
|
|
62
|
-
* @internal
|
|
63
|
-
*/
|
|
64
|
-
type Defaults<TBooleans extends BooleanType, TStrings extends StringType> = Id<UnionToIntersection<Record<string, unknown> & MapTypes<TStrings, unknown> & MapTypes<TBooleans, unknown> & MapDefaults<TBooleans> & MapDefaults<TStrings>>>;
|
|
65
|
-
type MapDefaults<TArgNames extends ArgType> = Partial<Record<TArgNames extends string ? TArgNames : string, unknown>>;
|
|
66
|
-
type RecursiveRequired<TRecord> = TRecord extends Record<string, unknown> ? {
|
|
67
|
-
[Key in keyof TRecord]-?: RecursiveRequired<TRecord[Key]>;
|
|
68
|
-
} : TRecord;
|
|
69
|
-
/** Same as `MapTypes` but also supports collectable options. */
|
|
70
|
-
type CollectValues<TArgNames extends ArgType, TType, TCollectable extends Collectable, TNegatable extends Negatable = undefined> = UnionToIntersection<Extract<TArgNames, TCollectable> extends string ? (Exclude<TArgNames, TCollectable> extends never ? Record<never, never> : MapTypes<Exclude<TArgNames, TCollectable>, TType, TNegatable>) & (Extract<TArgNames, TCollectable> extends never ? Record<never, never> : RecursiveRequired<MapTypes<Extract<TArgNames, TCollectable>, Array<TType>, TNegatable>>) : MapTypes<TArgNames, TType, TNegatable>>;
|
|
71
|
-
/** Same as `Record` but also supports dotted and negatable options. */
|
|
72
|
-
type MapTypes<TArgNames extends ArgType, TType, TNegatable extends Negatable = undefined> = undefined extends TArgNames ? Record<never, never> : TArgNames extends `${infer Name}.${infer Rest}` ? {
|
|
73
|
-
[Key in Name]?: MapTypes<Rest, TType, TNegatable extends `${Name}.${infer Negate}` ? Negate : undefined>;
|
|
74
|
-
} : TArgNames extends string ? Partial<Record<TArgNames, TNegatable extends TArgNames ? TType | false : TType>> : Record<never, never>;
|
|
75
|
-
type CollectUnknownValues<TBooleans extends BooleanType, TStrings extends StringType, TCollectable extends Collectable, TNegatable extends Negatable> = UnionToIntersection<TCollectable extends TBooleans & TStrings ? Record<never, never> : DedotRecord<Record<Exclude<Extract<Exclude<TCollectable, TNegatable>, string>, Extract<TStrings | TBooleans, string>>, Array<unknown>> & Record<Exclude<Extract<Extract<TCollectable, TNegatable>, string>, Extract<TStrings | TBooleans, string>>, Array<unknown> | false>>>;
|
|
76
|
-
/** Converts `{ "foo.bar.baz": unknown }` into `{ foo: { bar: { baz: unknown } } }`. */
|
|
77
|
-
type DedotRecord<TRecord> = Record<string, unknown> extends TRecord ? TRecord : TRecord extends Record<string, unknown> ? UnionToIntersection<ValueOf<{
|
|
78
|
-
[Key in keyof TRecord]: Key extends string ? Dedot<Key, TRecord[Key]> : never;
|
|
79
|
-
}>> : TRecord;
|
|
80
|
-
type Dedot<TKey extends string, TValue> = TKey extends `${infer Name}.${infer Rest}` ? {
|
|
81
|
-
[Key in Name]: Dedot<Rest, TValue>;
|
|
82
|
-
} : {
|
|
83
|
-
[Key in TKey]: TValue;
|
|
84
|
-
};
|
|
85
|
-
type ValueOf<TValue> = TValue[keyof TValue];
|
|
86
|
-
/** The value returned from {@linkcode parseArgs}. */
|
|
87
|
-
export type Args<TArgs extends Record<string, unknown> = Record<string, any>, TDoubleDash extends boolean | undefined = undefined> = Id<TArgs & {
|
|
88
|
-
/** Contains all the arguments that didn't have an option associated with
|
|
89
|
-
* them. */
|
|
90
|
-
_: Array<string | number>;
|
|
91
|
-
} & (boolean extends TDoubleDash ? DoubleDash : true extends TDoubleDash ? Required<DoubleDash> : Record<never, never>)>;
|
|
92
|
-
/** @internal */
|
|
93
|
-
type DoubleDash = {
|
|
94
|
-
/** Contains all the arguments that appear after the double dash: "--". */
|
|
95
|
-
"--"?: Array<string>;
|
|
96
|
-
};
|
|
97
|
-
/** Options for {@linkcode parseArgs}. */
|
|
98
|
-
export interface ParseOptions<TBooleans extends BooleanType = BooleanType, TStrings extends StringType = StringType, TCollectable extends Collectable = Collectable, TNegatable extends Negatable = Negatable, TDefault extends Record<string, unknown> | undefined = Record<string, unknown> | undefined, TAliases extends Aliases | undefined = Aliases | undefined, TDoubleDash extends boolean | undefined = boolean | undefined> {
|
|
99
|
-
/**
|
|
100
|
-
* When `true`, populate the result `_` with everything before the `--` and
|
|
101
|
-
* the result `['--']` with everything after the `--`.
|
|
102
|
-
*
|
|
103
|
-
* @default {false}
|
|
104
|
-
*
|
|
105
|
-
* @example Double dash option is false
|
|
106
|
-
* ```ts
|
|
107
|
-
* // $ deno run example.ts -- a arg1
|
|
108
|
-
* import { parseArgs } from "@std/cli/parse-args";
|
|
109
|
-
* const args = parseArgs(Deno.args, { "--": false }); // args equals { _: [ "a", "arg1" ] }
|
|
110
|
-
* ```
|
|
111
|
-
*
|
|
112
|
-
* @example Double dash option is true
|
|
113
|
-
* ```ts
|
|
114
|
-
* // $ deno run example.ts -- a arg1
|
|
115
|
-
* import { parseArgs } from "@std/cli/parse-args";
|
|
116
|
-
* const args = parseArgs(Deno.args, { "--": true }); // args equals { _: [], --: [ "a", "arg1" ] }
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
"--"?: TDoubleDash;
|
|
120
|
-
/**
|
|
121
|
-
* An object mapping string names to strings or arrays of string argument
|
|
122
|
-
* names to use as aliases.
|
|
123
|
-
*
|
|
124
|
-
* @default {{}}
|
|
125
|
-
*/
|
|
126
|
-
alias?: TAliases;
|
|
127
|
-
/**
|
|
128
|
-
* A boolean, string or array of strings to always treat as booleans. If
|
|
129
|
-
* `true` will treat all double hyphenated arguments without equal signs as
|
|
130
|
-
* `boolean` (e.g. affects `--foo`, not `-f` or `--foo=bar`).
|
|
131
|
-
* All `boolean` arguments will be set to `false` by default.
|
|
132
|
-
*
|
|
133
|
-
* @default {false}
|
|
134
|
-
*/
|
|
135
|
-
boolean?: TBooleans | ReadonlyArray<Extract<TBooleans, string>>;
|
|
136
|
-
/**
|
|
137
|
-
* An object mapping string argument names to default values.
|
|
138
|
-
*
|
|
139
|
-
* @default {{}}
|
|
140
|
-
*/
|
|
141
|
-
default?: TDefault & Defaults<TBooleans, TStrings>;
|
|
142
|
-
/**
|
|
143
|
-
* When `true`, populate the result `_` with everything after the first
|
|
144
|
-
* non-option.
|
|
145
|
-
*
|
|
146
|
-
* @default {false}
|
|
147
|
-
*/
|
|
148
|
-
stopEarly?: boolean;
|
|
149
|
-
/**
|
|
150
|
-
* A string or array of strings argument names to always treat as strings.
|
|
151
|
-
*
|
|
152
|
-
* @default {[]}
|
|
153
|
-
*/
|
|
154
|
-
string?: TStrings | ReadonlyArray<Extract<TStrings, string>>;
|
|
155
|
-
/**
|
|
156
|
-
* A string or array of strings argument names to always treat as arrays.
|
|
157
|
-
* Collectable options can be used multiple times. All values will be
|
|
158
|
-
* collected into one array. If a non-collectable option is used multiple
|
|
159
|
-
* times, the last value is used.
|
|
160
|
-
*
|
|
161
|
-
* @default {[]}
|
|
162
|
-
*/
|
|
163
|
-
collect?: TCollectable | ReadonlyArray<Extract<TCollectable, string>>;
|
|
164
|
-
/**
|
|
165
|
-
* A string or array of strings argument names which can be negated
|
|
166
|
-
* by prefixing them with `--no-`, like `--no-config`.
|
|
167
|
-
*
|
|
168
|
-
* @default {[]}
|
|
169
|
-
*/
|
|
170
|
-
negatable?: TNegatable | ReadonlyArray<Extract<TNegatable, string>>;
|
|
171
|
-
/**
|
|
172
|
-
* A function which is invoked with a command line parameter not defined in
|
|
173
|
-
* the `options` configuration object. If the function returns `false`, the
|
|
174
|
-
* unknown option is not added to `parsedArgs`.
|
|
175
|
-
*
|
|
176
|
-
* @default {unknown}
|
|
177
|
-
*/
|
|
178
|
-
unknown?: (arg: string, key?: string, value?: unknown) => unknown;
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Take a set of command line arguments, optionally with a set of options, and
|
|
182
|
-
* return an object representing the flags found in the passed arguments.
|
|
183
|
-
*
|
|
184
|
-
* By default, any arguments starting with `-` or `--` are considered boolean
|
|
185
|
-
* flags. If the argument name is followed by an equal sign (`=`) it is
|
|
186
|
-
* considered a key-value pair. Any arguments which could not be parsed are
|
|
187
|
-
* available in the `_` property of the returned object.
|
|
188
|
-
*
|
|
189
|
-
* By default, this module tries to determine the type of all arguments
|
|
190
|
-
* automatically and the return type of this function will have an index
|
|
191
|
-
* signature with `any` as value (`{ [x: string]: any }`).
|
|
192
|
-
*
|
|
193
|
-
* If the `string`, `boolean` or `collect` option is set, the return value of
|
|
194
|
-
* this function will be fully typed and the index signature of the return
|
|
195
|
-
* type will change to `{ [x: string]: unknown }`.
|
|
196
|
-
*
|
|
197
|
-
* Any arguments after `'--'` will not be parsed and will end up in `parsedArgs._`.
|
|
198
|
-
*
|
|
199
|
-
* Numeric-looking arguments will be returned as numbers unless `options.string`
|
|
200
|
-
* or `options.boolean` is set for that argument name.
|
|
201
|
-
*
|
|
202
|
-
* @param args An array of command line arguments.
|
|
203
|
-
* @param options Options for the parse function.
|
|
204
|
-
*
|
|
205
|
-
* @typeParam TArgs Type of result.
|
|
206
|
-
* @typeParam TDoubleDash Used by `TArgs` for the result.
|
|
207
|
-
* @typeParam TBooleans Used by `TArgs` for the result.
|
|
208
|
-
* @typeParam TStrings Used by `TArgs` for the result.
|
|
209
|
-
* @typeParam TCollectable Used by `TArgs` for the result.
|
|
210
|
-
* @typeParam TNegatable Used by `TArgs` for the result.
|
|
211
|
-
* @typeParam TDefaults Used by `TArgs` for the result.
|
|
212
|
-
* @typeParam TAliases Used by `TArgs` for the result.
|
|
213
|
-
* @typeParam TAliasArgNames Used by `TArgs` for the result.
|
|
214
|
-
* @typeParam TAliasNames Used by `TArgs` for the result.
|
|
215
|
-
*
|
|
216
|
-
* @return The parsed arguments.
|
|
217
|
-
*
|
|
218
|
-
* @example Usage
|
|
219
|
-
* ```ts
|
|
220
|
-
* import { parseArgs } from "@std/cli/parse-args";
|
|
221
|
-
* import { assertEquals } from "@std/assert";
|
|
222
|
-
*
|
|
223
|
-
* // For proper use, one should use `parseArgs(Deno.args)`
|
|
224
|
-
* assertEquals(parseArgs(["--foo", "--bar=baz", "./quux.txt"]), {
|
|
225
|
-
* foo: true,
|
|
226
|
-
* bar: "baz",
|
|
227
|
-
* _: ["./quux.txt"],
|
|
228
|
-
* });
|
|
229
|
-
* ```
|
|
230
|
-
*/
|
|
231
|
-
export declare function parseArgs<TArgs extends Values<TBooleans, TStrings, TCollectable, TNegatable, TDefaults, TAliases>, TDoubleDash extends boolean | undefined = undefined, TBooleans extends BooleanType = undefined, TStrings extends StringType = undefined, TCollectable extends Collectable = undefined, TNegatable extends Negatable = undefined, TDefaults extends Record<string, unknown> | undefined = undefined, TAliases extends Aliases<TAliasArgNames, TAliasNames> | undefined = undefined, TAliasArgNames extends string = string, TAliasNames extends string = string>(args: string[], options?: ParseOptions<TBooleans, TStrings, TCollectable, TNegatable, TDefaults, TAliases, TDoubleDash>): Args<TArgs, TDoubleDash>;
|
|
232
|
-
export {};
|
|
233
|
-
//# sourceMappingURL=parse_args.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"parse_args.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/cli/1.0.9/parse_args.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;GAYG;AAEH;;GAEG;AACH,KAAK,EAAE,CAAC,OAAO,IAAI,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACtD,OAAO,SAAS,MAAM,cAAc,GAClC;KAAG,GAAG,IAAI,MAAM,cAAc,GAAG,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;CAAE,GAC5D,KAAK,GACL,OAAO,CAAC;AAEZ;;GAEG;AACH,KAAK,mBAAmB,CAAC,MAAM,IAC7B,CAAC,MAAM,SAAS,OAAO,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,KAAK,CAAC,SAC1D,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,OAAO,GAAG,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,GACxE,KAAK,CAAC;AAEZ,gBAAgB;AAChB,KAAK,WAAW,GAAG,OAAO,GAAG,MAAM,GAAG,SAAS,CAAC;AAChD,gBAAgB;AAChB,KAAK,UAAU,GAAG,MAAM,GAAG,SAAS,CAAC;AACrC,gBAAgB;AAChB,KAAK,OAAO,GAAG,UAAU,GAAG,WAAW,CAAC;AAExC,gBAAgB;AAChB,KAAK,WAAW,GAAG,MAAM,GAAG,SAAS,CAAC;AACtC,gBAAgB;AAChB,KAAK,SAAS,GAAG,MAAM,GAAG,SAAS,CAAC;AAEpC,KAAK,QAAQ,CACX,SA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C,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC;CACnE;AAyED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,wBAAgB,SAAS,CACvB,KAAK,SAAS,MAAM,CAClB,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,SAAS,EACT,QAAQ,CACT,EACD,WAAW,SAAS,OAAO,GAAG,SAAS,GAAG,SAAS,EACnD,SAAS,SAAS,WAAW,GAAG,SAAS,EACzC,QAAQ,SAAS,UAAU,GAAG,SAAS,EACvC,YAAY,SAAS,WAAW,GAAG,SAAS,EAC5C,UAAU,SAAS,SAAS,GAAG,SAAS,EACxC,SAAS,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAAG,SAAS,EACjE,QAAQ,SAAS,OAAO,CAAC,cAAc,EAAE,WAAW,CAAC,GAAG,SAAS,GAAG,SAAS,EAC7E,cAAc,SAAS,MAAM,GAAG,MAAM,EACtC,WAAW,SAAS,MAAM,GAAG,MAAM,EAEnC,IAAI,EAAE,MAAM,EAAE,EACd,OAAO,CAAC,EAAE,YAAY,CACpB,SAAS,EACT,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,SAAS,EACT,QAAQ,EACR,WAAW,CACZ,GACA,IAAI,CAAC,KAAK,EAAE,WAAW,CAAC,CAwQ1B"}
|
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
2
|
-
// This module is browser compatible.
|
|
3
|
-
const FLAG_REGEXP = /^(?:-(?:(?<doubleDash>-)(?<negated>no-)?)?)(?<key>.+?)(?:=(?<value>.+?))?$/s;
|
|
4
|
-
const LETTER_REGEXP = /[A-Za-z]/;
|
|
5
|
-
const NUMBER_REGEXP = /-?\d+(\.\d*)?(e-?\d+)?$/;
|
|
6
|
-
const HYPHEN_REGEXP = /^(-|--)[^-]/;
|
|
7
|
-
const VALUE_REGEXP = /=(?<value>.+)/;
|
|
8
|
-
const FLAG_NAME_REGEXP = /^--[^=]+$/;
|
|
9
|
-
const SPECIAL_CHAR_REGEXP = /\W/;
|
|
10
|
-
const NON_WHITESPACE_REGEXP = /\S/;
|
|
11
|
-
function isNumber(string) {
|
|
12
|
-
return NON_WHITESPACE_REGEXP.test(string) && Number.isFinite(Number(string));
|
|
13
|
-
}
|
|
14
|
-
function setNested(object, keys, value, collect = false) {
|
|
15
|
-
keys = [...keys];
|
|
16
|
-
const key = keys.pop();
|
|
17
|
-
keys.forEach((key) => object = (object[key] ??= {}));
|
|
18
|
-
if (collect) {
|
|
19
|
-
const v = object[key];
|
|
20
|
-
if (Array.isArray(v)) {
|
|
21
|
-
v.push(value);
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
value = v ? [v, value] : [value];
|
|
25
|
-
}
|
|
26
|
-
object[key] = value;
|
|
27
|
-
}
|
|
28
|
-
function hasNested(object, keys) {
|
|
29
|
-
for (const key of keys) {
|
|
30
|
-
const value = object[key];
|
|
31
|
-
if (!Object.hasOwn(object, key))
|
|
32
|
-
return false;
|
|
33
|
-
object = value;
|
|
34
|
-
}
|
|
35
|
-
return true;
|
|
36
|
-
}
|
|
37
|
-
function aliasIsBoolean(aliasMap, booleanSet, key) {
|
|
38
|
-
const set = aliasMap.get(key);
|
|
39
|
-
if (set === undefined)
|
|
40
|
-
return false;
|
|
41
|
-
for (const alias of set)
|
|
42
|
-
if (booleanSet.has(alias))
|
|
43
|
-
return true;
|
|
44
|
-
return false;
|
|
45
|
-
}
|
|
46
|
-
function isBooleanString(value) {
|
|
47
|
-
return value === "true" || value === "false";
|
|
48
|
-
}
|
|
49
|
-
function parseBooleanString(value) {
|
|
50
|
-
return value !== "false";
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Take a set of command line arguments, optionally with a set of options, and
|
|
54
|
-
* return an object representing the flags found in the passed arguments.
|
|
55
|
-
*
|
|
56
|
-
* By default, any arguments starting with `-` or `--` are considered boolean
|
|
57
|
-
* flags. If the argument name is followed by an equal sign (`=`) it is
|
|
58
|
-
* considered a key-value pair. Any arguments which could not be parsed are
|
|
59
|
-
* available in the `_` property of the returned object.
|
|
60
|
-
*
|
|
61
|
-
* By default, this module tries to determine the type of all arguments
|
|
62
|
-
* automatically and the return type of this function will have an index
|
|
63
|
-
* signature with `any` as value (`{ [x: string]: any }`).
|
|
64
|
-
*
|
|
65
|
-
* If the `string`, `boolean` or `collect` option is set, the return value of
|
|
66
|
-
* this function will be fully typed and the index signature of the return
|
|
67
|
-
* type will change to `{ [x: string]: unknown }`.
|
|
68
|
-
*
|
|
69
|
-
* Any arguments after `'--'` will not be parsed and will end up in `parsedArgs._`.
|
|
70
|
-
*
|
|
71
|
-
* Numeric-looking arguments will be returned as numbers unless `options.string`
|
|
72
|
-
* or `options.boolean` is set for that argument name.
|
|
73
|
-
*
|
|
74
|
-
* @param args An array of command line arguments.
|
|
75
|
-
* @param options Options for the parse function.
|
|
76
|
-
*
|
|
77
|
-
* @typeParam TArgs Type of result.
|
|
78
|
-
* @typeParam TDoubleDash Used by `TArgs` for the result.
|
|
79
|
-
* @typeParam TBooleans Used by `TArgs` for the result.
|
|
80
|
-
* @typeParam TStrings Used by `TArgs` for the result.
|
|
81
|
-
* @typeParam TCollectable Used by `TArgs` for the result.
|
|
82
|
-
* @typeParam TNegatable Used by `TArgs` for the result.
|
|
83
|
-
* @typeParam TDefaults Used by `TArgs` for the result.
|
|
84
|
-
* @typeParam TAliases Used by `TArgs` for the result.
|
|
85
|
-
* @typeParam TAliasArgNames Used by `TArgs` for the result.
|
|
86
|
-
* @typeParam TAliasNames Used by `TArgs` for the result.
|
|
87
|
-
*
|
|
88
|
-
* @return The parsed arguments.
|
|
89
|
-
*
|
|
90
|
-
* @example Usage
|
|
91
|
-
* ```ts
|
|
92
|
-
* import { parseArgs } from "@std/cli/parse-args";
|
|
93
|
-
* import { assertEquals } from "@std/assert";
|
|
94
|
-
*
|
|
95
|
-
* // For proper use, one should use `parseArgs(Deno.args)`
|
|
96
|
-
* assertEquals(parseArgs(["--foo", "--bar=baz", "./quux.txt"]), {
|
|
97
|
-
* foo: true,
|
|
98
|
-
* bar: "baz",
|
|
99
|
-
* _: ["./quux.txt"],
|
|
100
|
-
* });
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
export function parseArgs(args, options) {
|
|
104
|
-
const { "--": doubleDash = false, alias = {}, boolean = false, default: defaults = {}, stopEarly = false, string = [], collect = [], negatable = [], unknown: unknownFn = (i) => i, } = options ?? {};
|
|
105
|
-
const aliasMap = new Map();
|
|
106
|
-
const booleanSet = new Set();
|
|
107
|
-
const stringSet = new Set();
|
|
108
|
-
const collectSet = new Set();
|
|
109
|
-
const negatableSet = new Set();
|
|
110
|
-
let allBools = false;
|
|
111
|
-
if (alias) {
|
|
112
|
-
for (const [key, value] of Object.entries(alias)) {
|
|
113
|
-
if (value === undefined) {
|
|
114
|
-
throw new TypeError("Alias value must be defined");
|
|
115
|
-
}
|
|
116
|
-
const aliases = Array.isArray(value) ? value : [value];
|
|
117
|
-
aliasMap.set(key, new Set(aliases));
|
|
118
|
-
aliases.forEach((alias) => aliasMap.set(alias, new Set([key, ...aliases.filter((it) => it !== alias)])));
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
if (boolean) {
|
|
122
|
-
if (typeof boolean === "boolean") {
|
|
123
|
-
allBools = boolean;
|
|
124
|
-
}
|
|
125
|
-
else {
|
|
126
|
-
const booleanArgs = Array.isArray(boolean) ? boolean : [boolean];
|
|
127
|
-
for (const key of booleanArgs.filter(Boolean)) {
|
|
128
|
-
booleanSet.add(key);
|
|
129
|
-
aliasMap.get(key)?.forEach((al) => {
|
|
130
|
-
booleanSet.add(al);
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (string) {
|
|
136
|
-
const stringArgs = Array.isArray(string) ? string : [string];
|
|
137
|
-
for (const key of stringArgs.filter(Boolean)) {
|
|
138
|
-
stringSet.add(key);
|
|
139
|
-
aliasMap.get(key)?.forEach((al) => stringSet.add(al));
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
if (collect) {
|
|
143
|
-
const collectArgs = Array.isArray(collect) ? collect : [collect];
|
|
144
|
-
for (const key of collectArgs.filter(Boolean)) {
|
|
145
|
-
collectSet.add(key);
|
|
146
|
-
aliasMap.get(key)?.forEach((al) => collectSet.add(al));
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
if (negatable) {
|
|
150
|
-
const negatableArgs = Array.isArray(negatable) ? negatable : [negatable];
|
|
151
|
-
for (const key of negatableArgs.filter(Boolean)) {
|
|
152
|
-
negatableSet.add(key);
|
|
153
|
-
aliasMap.get(key)?.forEach((alias) => negatableSet.add(alias));
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
const argv = { _: [] };
|
|
157
|
-
function setArgument(key, value, arg, collect) {
|
|
158
|
-
if (!booleanSet.has(key) &&
|
|
159
|
-
!stringSet.has(key) &&
|
|
160
|
-
!aliasMap.has(key) &&
|
|
161
|
-
!(allBools && FLAG_NAME_REGEXP.test(arg)) &&
|
|
162
|
-
unknownFn?.(arg, key, value) === false) {
|
|
163
|
-
return;
|
|
164
|
-
}
|
|
165
|
-
if (typeof value === "string" && !stringSet.has(key)) {
|
|
166
|
-
value = isNumber(value) ? Number(value) : value;
|
|
167
|
-
}
|
|
168
|
-
const collectable = collect && collectSet.has(key);
|
|
169
|
-
setNested(argv, key.split("."), value, collectable);
|
|
170
|
-
aliasMap.get(key)?.forEach((key) => {
|
|
171
|
-
setNested(argv, key.split("."), value, collectable);
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
let notFlags = [];
|
|
175
|
-
// all args after "--" are not parsed
|
|
176
|
-
const index = args.indexOf("--");
|
|
177
|
-
if (index !== -1) {
|
|
178
|
-
notFlags = args.slice(index + 1);
|
|
179
|
-
args = args.slice(0, index);
|
|
180
|
-
}
|
|
181
|
-
argsLoop: for (let i = 0; i < args.length; i++) {
|
|
182
|
-
const arg = args[i];
|
|
183
|
-
const groups = arg.match(FLAG_REGEXP)?.groups;
|
|
184
|
-
if (groups) {
|
|
185
|
-
const { doubleDash, negated } = groups;
|
|
186
|
-
let key = groups.key;
|
|
187
|
-
let value = groups.value;
|
|
188
|
-
if (doubleDash) {
|
|
189
|
-
if (value) {
|
|
190
|
-
if (booleanSet.has(key))
|
|
191
|
-
value = parseBooleanString(value);
|
|
192
|
-
setArgument(key, value, arg, true);
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
if (negated) {
|
|
196
|
-
if (negatableSet.has(key)) {
|
|
197
|
-
setArgument(key, false, arg, false);
|
|
198
|
-
continue;
|
|
199
|
-
}
|
|
200
|
-
key = `no-${key}`;
|
|
201
|
-
}
|
|
202
|
-
const next = args[i + 1];
|
|
203
|
-
if (next) {
|
|
204
|
-
if (!booleanSet.has(key) &&
|
|
205
|
-
!allBools &&
|
|
206
|
-
!next.startsWith("-") &&
|
|
207
|
-
(!aliasMap.has(key) || !aliasIsBoolean(aliasMap, booleanSet, key))) {
|
|
208
|
-
value = next;
|
|
209
|
-
i++;
|
|
210
|
-
setArgument(key, value, arg, true);
|
|
211
|
-
continue;
|
|
212
|
-
}
|
|
213
|
-
if (isBooleanString(next)) {
|
|
214
|
-
value = parseBooleanString(next);
|
|
215
|
-
i++;
|
|
216
|
-
setArgument(key, value, arg, true);
|
|
217
|
-
continue;
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
value = stringSet.has(key) ? "" : true;
|
|
221
|
-
setArgument(key, value, arg, true);
|
|
222
|
-
continue;
|
|
223
|
-
}
|
|
224
|
-
const letters = arg.slice(1, -1).split("");
|
|
225
|
-
for (const [j, letter] of letters.entries()) {
|
|
226
|
-
const next = arg.slice(j + 2);
|
|
227
|
-
if (next === "-") {
|
|
228
|
-
setArgument(letter, next, arg, true);
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
if (LETTER_REGEXP.test(letter)) {
|
|
232
|
-
const groups = VALUE_REGEXP.exec(next)?.groups;
|
|
233
|
-
if (groups) {
|
|
234
|
-
setArgument(letter, groups.value, arg, true);
|
|
235
|
-
continue argsLoop;
|
|
236
|
-
}
|
|
237
|
-
if (NUMBER_REGEXP.test(next)) {
|
|
238
|
-
setArgument(letter, next, arg, true);
|
|
239
|
-
continue argsLoop;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
if (letters[j + 1]?.match(SPECIAL_CHAR_REGEXP)) {
|
|
243
|
-
setArgument(letter, arg.slice(j + 2), arg, true);
|
|
244
|
-
continue argsLoop;
|
|
245
|
-
}
|
|
246
|
-
setArgument(letter, stringSet.has(letter) ? "" : true, arg, true);
|
|
247
|
-
}
|
|
248
|
-
key = arg.slice(-1);
|
|
249
|
-
if (key === "-")
|
|
250
|
-
continue;
|
|
251
|
-
const nextArg = args[i + 1];
|
|
252
|
-
if (nextArg) {
|
|
253
|
-
if (!HYPHEN_REGEXP.test(nextArg) &&
|
|
254
|
-
!booleanSet.has(key) &&
|
|
255
|
-
(!aliasMap.has(key) || !aliasIsBoolean(aliasMap, booleanSet, key))) {
|
|
256
|
-
setArgument(key, nextArg, arg, true);
|
|
257
|
-
i++;
|
|
258
|
-
continue;
|
|
259
|
-
}
|
|
260
|
-
if (isBooleanString(nextArg)) {
|
|
261
|
-
const value = parseBooleanString(nextArg);
|
|
262
|
-
setArgument(key, value, arg, true);
|
|
263
|
-
i++;
|
|
264
|
-
continue;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
setArgument(key, stringSet.has(key) ? "" : true, arg, true);
|
|
268
|
-
continue;
|
|
269
|
-
}
|
|
270
|
-
if (unknownFn?.(arg) !== false) {
|
|
271
|
-
argv._.push(stringSet.has("_") || !isNumber(arg) ? arg : Number(arg));
|
|
272
|
-
}
|
|
273
|
-
if (stopEarly) {
|
|
274
|
-
argv._.push(...args.slice(i + 1));
|
|
275
|
-
break;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
for (const [key, value] of Object.entries(defaults)) {
|
|
279
|
-
const keys = key.split(".");
|
|
280
|
-
if (!hasNested(argv, keys)) {
|
|
281
|
-
setNested(argv, keys, value);
|
|
282
|
-
aliasMap.get(key)?.forEach((key) => setNested(argv, key.split("."), value));
|
|
283
|
-
}
|
|
284
|
-
}
|
|
285
|
-
for (const key of booleanSet.keys()) {
|
|
286
|
-
const keys = key.split(".");
|
|
287
|
-
if (!hasNested(argv, keys)) {
|
|
288
|
-
const value = collectSet.has(key) ? [] : false;
|
|
289
|
-
setNested(argv, keys, value);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
for (const key of stringSet.keys()) {
|
|
293
|
-
const keys = key.split(".");
|
|
294
|
-
if (!hasNested(argv, keys) && collectSet.has(key)) {
|
|
295
|
-
setNested(argv, keys, []);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
if (doubleDash) {
|
|
299
|
-
argv["--"] = notFlags;
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
argv._.push(...notFlags);
|
|
303
|
-
}
|
|
304
|
-
return argv;
|
|
305
|
-
}
|