@hugoalh/adler32 0.2.0 โ†’ 0.4.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 CHANGED
@@ -6,18 +6,17 @@
6
6
  [![JSR: @hugoalh/adler32](https://img.shields.io/jsr/v/@hugoalh/adler32?label=@hugoalh/adler32&labelColor=F7DF1E&logo=jsr&logoColor=000000&style=flat "JSR: @hugoalh/adler32")](https://jsr.io/@hugoalh/adler32)
7
7
  [![NPM: @hugoalh/adler32](https://img.shields.io/npm/v/@hugoalh/adler32?label=@hugoalh/adler32&labelColor=CB3837&logo=npm&logoColor=ffffff&style=flat "NPM: @hugoalh/adler32")](https://www.npmjs.com/package/@hugoalh/adler32)
8
8
 
9
- An ES (JavaScript & TypeScript) CLI and module to get the checksum of the data with algorithm Adler32.
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
- | | **Remote** | **JSR** | **NPM** |
16
- |:--|:--|:--|:--|
17
- | **[Bun](https://bun.sh/)** >= v1.1.0 | โŒ | โ“ | โœ”๏ธ |
18
- | **[Cloudflare Workers](https://workers.cloudflare.com/)** | โŒ | โ“ | โœ”๏ธ |
19
- | **[Deno](https://deno.land/)** >= v1.42.0 | โœ”๏ธ | โœ”๏ธ | โœ”๏ธ |
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,24 +49,27 @@ An ES (JavaScript & TypeScript) CLI and module to get the checksum of the data w
50
49
 
51
50
  ### ๐Ÿ›ก๏ธ Runtime Permissions
52
51
 
53
- - File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) ๐Ÿงช: `fs-read`\]
54
- - *Resources* (Optional)
52
+ *This module does not request any runtime permission.*
55
53
 
56
54
  ## ๐Ÿงฉ APIs
57
55
 
58
56
  - ```ts
59
57
  class Adler32 {
60
58
  constructor(data?: Adler32AcceptDataType);
59
+ get freezed(): boolean;
60
+ freeze(): this;
61
61
  hash(): bigint;
62
62
  hashBase16(): string;
63
63
  hashBase32Hex(): string;
64
64
  hashBase36(): string;
65
+ hashBase64(): string;
66
+ hashBase64URL(): string;
67
+ hashBigInt(): bigint;
68
+ hashBuffer(): Buffer;
65
69
  hashHex(): string;
66
70
  hashHexPadding(): string;
67
71
  hashNumber(): number;
68
72
  update(data: Adler32AcceptDataType): this;
69
- static fromFile(filePath: string | URL): Promise<Adler32>;
70
- static fromFileSync(filePath: string | URL): Adler32;
71
73
  static fromStream(stream: ReadableStream<Adler32AcceptDataType>): Promise<Adler32>;
72
74
  }
73
75
  ```
@@ -80,23 +82,6 @@ An ES (JavaScript & TypeScript) CLI and module to get the checksum of the data w
80
82
  > - [Deno CLI `deno doc`](https://docs.deno.com/runtime/reference/cli/documentation_generator/)
81
83
  > - [JSR](https://jsr.io/@hugoalh/adler32)
82
84
 
83
- ## ๐Ÿงฉ CLIs
84
-
85
- **Entrypoint:** `cli.js`/`cli.ts`
86
-
87
- - From argument; Output hex padding
88
- ```ps1
89
- adler32 {Data}
90
- ```
91
- - From file; Output hex padding
92
- ```ps1
93
- adler32 --file {FilePath}
94
- ```
95
- - From stdin; Output hex padding
96
- ```ps1
97
- adler32 --stdin
98
- ```
99
-
100
85
  ## โœ๏ธ Examples
101
86
 
102
87
  - ```ts
package/mod.d.ts CHANGED
@@ -1,17 +1,28 @@
1
- import "./_dnt.polyfills.js";
1
+ import { Buffer } from "node:buffer";
2
2
  export type Adler32AcceptDataType = string | BigUint64Array | Uint8Array | Uint16Array | Uint32Array;
3
3
  /**
4
4
  * Get the checksum of the data with algorithm Adler32.
5
5
  */
6
6
  export declare class Adler32 {
7
7
  #private;
8
+ get [Symbol.toStringTag](): string;
8
9
  /**
9
10
  * Initialize.
10
11
  * @param {Adler32AcceptDataType} [data] Data. Can append later via the method {@linkcode Adler32.update}.
11
12
  */
12
13
  constructor(data?: Adler32AcceptDataType);
13
14
  /**
14
- * Get the checksum of the data, in big integer.
15
+ * Whether the instance is freezed.
16
+ * @returns {boolean}
17
+ */
18
+ get freezed(): boolean;
19
+ /**
20
+ * Freeze the instance to prevent any further update.
21
+ * @returns {this}
22
+ */
23
+ freeze(): this;
24
+ /**
25
+ * Get the checksum of the data, in original format.
15
26
  * @returns {bigint}
16
27
  */
17
28
  hash(): bigint;
@@ -30,6 +41,31 @@ export declare class Adler32 {
30
41
  * @returns {string}
31
42
  */
32
43
  hashBase36(): string;
44
+ /**
45
+ * Get the checksum of the data, in Base64.
46
+ * @returns {string}
47
+ */
48
+ hashBase64(): string;
49
+ /**
50
+ * Get the checksum of the data, in Base64URL.
51
+ * @returns {string}
52
+ */
53
+ hashBase64URL(): string;
54
+ /**
55
+ * Get the checksum of the data, in big integer.
56
+ * @returns {bigint}
57
+ */
58
+ hashBigInt(): bigint;
59
+ /**
60
+ * Get the checksum of the data, in big integer.
61
+ * @returns {bigint}
62
+ */
63
+ hashBigInteger: () => bigint;
64
+ /**
65
+ * Get the checksum of the data, in Buffer.
66
+ * @returns {Buffer}
67
+ */
68
+ hashBuffer(): Buffer;
33
69
  /**
34
70
  * Get the checksum of the data, in hex/hexadecimal without padding.
35
71
  * @returns {string}
@@ -52,29 +88,7 @@ export declare class Adler32 {
52
88
  */
53
89
  update(data: Adler32AcceptDataType): this;
54
90
  /**
55
- * Initialize from file, asynchronously.
56
- *
57
- * > **๐Ÿ›ก๏ธ Runtime Permissions**
58
- * >
59
- * > - File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) ๐Ÿงช: `fs-read`\]
60
- * > - *Resources*
61
- * @param {string | URL} filePath Path of the file.
62
- * @returns {Promise<Adler32>}
63
- */
64
- static fromFile(filePath: string | URL): Promise<Adler32>;
65
- /**
66
- * Initialize from file, synchronously.
67
- *
68
- * > **๐Ÿ›ก๏ธ Runtime Permissions**
69
- * >
70
- * > - File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) ๐Ÿงช: `fs-read`\]
71
- * > - *Resources*
72
- * @param {string | URL} filePath Path of the file.
73
- * @returns {Adler32}
74
- */
75
- static fromFileSync(filePath: string | URL): Adler32;
76
- /**
77
- * Initialize from readable stream, asynchronously.
91
+ * Initialize from the readable stream.
78
92
  * @param {ReadableStream<Adler32AcceptDataType>} stream Readable stream.
79
93
  * @returns {Promise<Adler32>}
80
94
  */
package/mod.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAE7B,MAAM,MAAM,qBAAqB,GAAG,MAAM,GAAG,cAAc,GAAG,UAAU,GAAG,WAAW,GAAG,WAAW,CAAC;AACrG;;GAEG;AACH,qBAAa,OAAO;;IAInB;;;OAGG;gBACS,IAAI,CAAC,EAAE,qBAAqB;IAKxC;;;OAGG;IACH,IAAI,IAAI,MAAM;IAMd;;;OAGG;IACH,UAAU,IAAI,MAAM;IAGpB;;;OAGG;IACH,aAAa,IAAI,MAAM;IAGvB;;;OAGG;IACH,UAAU,IAAI,MAAM;IAGpB;;;OAGG;IACH,OAAO,IAAI,MAAM;IAGjB;;;OAGG;IACH,cAAc,IAAI,MAAM;IAGxB;;;OAGG;IACH,UAAU,IAAI,MAAM;IAGpB;;;;OAIG;IACH,MAAM,CA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;IAGxB;;;OAGG;IACH,UAAU,IAAI,MAAM;IAGpB;;;;OAIG;IACH,MAAM,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI;IAQzC;;;;OAIG;WACU,UAAU,CAAC,MAAM,EAAE,cAAc,CAAC,qBAAqB,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;CAOxF;AACD,eAAe,OAAO,CAAC"}
package/mod.js CHANGED
@@ -1,64 +1,20 @@
1
- import "./_dnt.polyfills.js";
2
- import * as dntShim from "./_dnt.shims.js";
3
- var __addDisposableResource = (this && this.__addDisposableResource) || function (env, value, async) {
4
- if (value !== null && value !== void 0) {
5
- if (typeof value !== "object" && typeof value !== "function") throw new TypeError("Object expected.");
6
- var dispose, inner;
7
- if (async) {
8
- if (!Symbol.asyncDispose) throw new TypeError("Symbol.asyncDispose is not defined.");
9
- dispose = value[Symbol.asyncDispose];
10
- }
11
- if (dispose === void 0) {
12
- if (!Symbol.dispose) throw new TypeError("Symbol.dispose is not defined.");
13
- dispose = value[Symbol.dispose];
14
- if (async) inner = dispose;
15
- }
16
- if (typeof dispose !== "function") throw new TypeError("Object not disposable.");
17
- if (inner) dispose = function() { try { inner.call(this); } catch (e) { return Promise.reject(e); } };
18
- env.stack.push({ value: value, dispose: dispose, async: async });
19
- }
20
- else if (async) {
21
- env.stack.push({ async: true });
22
- }
23
- return value;
24
- };
25
- var __disposeResources = (this && this.__disposeResources) || (function (SuppressedError) {
26
- return function (env) {
27
- function fail(e) {
28
- env.error = env.hasError ? new SuppressedError(e, env.error, "An error was suppressed during disposal.") : e;
29
- env.hasError = true;
30
- }
31
- var r, s = 0;
32
- function next() {
33
- while (r = env.stack.pop()) {
34
- try {
35
- if (!r.async && s === 1) return s = 0, env.stack.push(r), Promise.resolve().then(next);
36
- if (r.dispose) {
37
- var result = r.dispose.call(r.value);
38
- if (r.async) return s |= 2, Promise.resolve(result).then(next, function(e) { fail(e); return next(); });
39
- }
40
- else s |= 1;
41
- }
42
- catch (e) {
43
- fail(e);
44
- }
45
- }
46
- if (s === 1) return env.hasError ? Promise.reject(env.error) : Promise.resolve();
47
- if (env.hasError) throw env.error;
48
- }
49
- return next();
50
- };
51
- })(typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
52
- var e = new Error(message);
53
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
54
- });
1
+ import { Buffer } from "node:buffer";
55
2
  /**
56
3
  * Get the checksum of the data with algorithm Adler32.
57
4
  */
58
5
  export class Adler32 {
6
+ get [Symbol.toStringTag]() {
7
+ return "Adler32";
8
+ }
9
+ #freezed = false;
10
+ #hash = null;
11
+ #hashBase16 = null;
12
+ #hashBase32Hex = null;
13
+ #hashBase36 = null;
14
+ #hashBase64 = null;
15
+ #hashBase64URL = null;
59
16
  #a = 1n;
60
17
  #b = 0n;
61
- #hash = null;
62
18
  /**
63
19
  * Initialize.
64
20
  * @param {Adler32AcceptDataType} [data] Data. Can append later via the method {@linkcode Adler32.update}.
@@ -68,14 +24,38 @@ export class Adler32 {
68
24
  this.update(data);
69
25
  }
70
26
  }
27
+ #clearStorage() {
28
+ if (this.#freezed) {
29
+ throw new Error(`Instance is freezed!`);
30
+ }
31
+ this.#hash = null;
32
+ this.#hashBase16 = null;
33
+ this.#hashBase32Hex = null;
34
+ this.#hashBase36 = null;
35
+ this.#hashBase64 = null;
36
+ this.#hashBase64URL = null;
37
+ }
71
38
  /**
72
- * Get the checksum of the data, in big integer.
39
+ * Whether the instance is freezed.
40
+ * @returns {boolean}
41
+ */
42
+ get freezed() {
43
+ return this.#freezed;
44
+ }
45
+ /**
46
+ * Freeze the instance to prevent any further update.
47
+ * @returns {this}
48
+ */
49
+ freeze() {
50
+ this.#freezed = true;
51
+ return this;
52
+ }
53
+ /**
54
+ * Get the checksum of the data, in original format.
73
55
  * @returns {bigint}
74
56
  */
75
57
  hash() {
76
- if (this.#hash === null) {
77
- this.#hash = this.#b * 65536n + this.#a;
78
- }
58
+ this.#hash ??= this.#b * 65536n + this.#a;
79
59
  return this.#hash;
80
60
  }
81
61
  /**
@@ -83,21 +63,59 @@ export class Adler32 {
83
63
  * @returns {string}
84
64
  */
85
65
  hashBase16() {
86
- return this.hashNumber().toString(16).toUpperCase();
66
+ this.#hashBase16 ??= this.hashBigInt().toString(16).toUpperCase();
67
+ return this.#hashBase16;
87
68
  }
88
69
  /**
89
70
  * Get the checksum of the data, in Base32Hex ({@link https://datatracker.ietf.org/doc/html/rfc4648#section-7 RFC 4648 ยง7}).
90
71
  * @returns {string}
91
72
  */
92
73
  hashBase32Hex() {
93
- return this.hashNumber().toString(32).toUpperCase();
74
+ this.#hashBase32Hex ??= this.hashBigInt().toString(32).toUpperCase();
75
+ return this.#hashBase32Hex;
94
76
  }
95
77
  /**
96
78
  * Get the checksum of the data, in Base36.
97
79
  * @returns {string}
98
80
  */
99
81
  hashBase36() {
100
- return this.hashNumber().toString(36).toUpperCase();
82
+ this.#hashBase36 ??= this.hashBigInt().toString(36).toUpperCase();
83
+ return this.#hashBase36;
84
+ }
85
+ /**
86
+ * Get the checksum of the data, in Base64.
87
+ * @returns {string}
88
+ */
89
+ hashBase64() {
90
+ this.#hashBase64 ??= this.hashBuffer().toString("base64");
91
+ return this.#hashBase64;
92
+ }
93
+ /**
94
+ * Get the checksum of the data, in Base64URL.
95
+ * @returns {string}
96
+ */
97
+ hashBase64URL() {
98
+ this.#hashBase64URL ??= this.hashBuffer().toString("base64url");
99
+ return this.#hashBase64URL;
100
+ }
101
+ /**
102
+ * Get the checksum of the data, in big integer.
103
+ * @returns {bigint}
104
+ */
105
+ hashBigInt() {
106
+ return this.hash();
107
+ }
108
+ /**
109
+ * Get the checksum of the data, in big integer.
110
+ * @returns {bigint}
111
+ */
112
+ hashBigInteger = this.hashBigInt;
113
+ /**
114
+ * Get the checksum of the data, in Buffer.
115
+ * @returns {Buffer}
116
+ */
117
+ hashBuffer() {
118
+ return Buffer.from(this.hashBase16(), "hex");
101
119
  }
102
120
  /**
103
121
  * Get the checksum of the data, in hex/hexadecimal without padding.
@@ -126,7 +144,7 @@ export class Adler32 {
126
144
  * @returns {this}
127
145
  */
128
146
  update(data) {
129
- this.#hash = null;
147
+ this.#clearStorage();
130
148
  for (const byte of ((typeof data === "string") ? new TextEncoder().encode(data) : data)) {
131
149
  this.#a = (this.#a + BigInt(byte)) % 65521n;
132
150
  this.#b = (this.#b + this.#a) % 65521n;
@@ -134,49 +152,12 @@ export class Adler32 {
134
152
  return this;
135
153
  }
136
154
  /**
137
- * Initialize from file, asynchronously.
138
- *
139
- * > **๐Ÿ›ก๏ธ Runtime Permissions**
140
- * >
141
- * > - File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) ๐Ÿงช: `fs-read`\]
142
- * > - *Resources*
143
- * @param {string | URL} filePath Path of the file.
144
- * @returns {Promise<Adler32>}
145
- */
146
- static async fromFile(filePath) {
147
- const env_1 = { stack: [], error: void 0, hasError: false };
148
- try {
149
- const file = __addDisposableResource(env_1, await dntShim.Deno.open(filePath), false);
150
- return await Adler32.fromStream(file.readable);
151
- }
152
- catch (e_1) {
153
- env_1.error = e_1;
154
- env_1.hasError = true;
155
- }
156
- finally {
157
- __disposeResources(env_1);
158
- }
159
- }
160
- /**
161
- * Initialize from file, synchronously.
162
- *
163
- * > **๐Ÿ›ก๏ธ Runtime Permissions**
164
- * >
165
- * > - File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) ๐Ÿงช: `fs-read`\]
166
- * > - *Resources*
167
- * @param {string | URL} filePath Path of the file.
168
- * @returns {Adler32}
169
- */
170
- static fromFileSync(filePath) {
171
- return new this(dntShim.Deno.readFileSync(filePath));
172
- }
173
- /**
174
- * Initialize from readable stream, asynchronously.
155
+ * Initialize from the readable stream.
175
156
  * @param {ReadableStream<Adler32AcceptDataType>} stream Readable stream.
176
157
  * @returns {Promise<Adler32>}
177
158
  */
178
159
  static async fromStream(stream) {
179
- const instance = new Adler32();
160
+ const instance = new this();
180
161
  for await (const chunk of stream) {
181
162
  instance.update(chunk);
182
163
  }
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@hugoalh/adler32",
3
- "version": "0.2.0",
4
- "description": "A CLI and module to get the checksum of the data with algorithm Adler32.",
3
+ "version": "0.4.0",
4
+ "description": "A module to get the checksum of the data with algorithm Adler32.",
5
5
  "keywords": [
6
- "adler32"
6
+ "adler32",
7
+ "checksum"
7
8
  ],
8
9
  "homepage": "https://github.com/hugoalh/adler32-es#readme",
9
10
  "bugs": {
@@ -12,18 +13,9 @@
12
13
  "license": "MIT",
13
14
  "author": "hugoalh",
14
15
  "type": "module",
15
- "bin": {
16
- "adler32": "./cli.js"
17
- },
18
16
  "main": "./mod.js",
19
17
  "module": "./mod.js",
20
18
  "exports": {
21
- "./cli": {
22
- "import": {
23
- "types": "./cli.d.ts",
24
- "default": "./cli.js"
25
- }
26
- },
27
19
  ".": {
28
20
  "import": {
29
21
  "types": "./mod.d.ts",
@@ -37,17 +29,10 @@
37
29
  "url": "git+https://github.com/hugoalh/adler32-es.git"
38
30
  },
39
31
  "scripts": {},
40
- "dependencies": {
41
- "@deno/shim-deno": "~0.18.0",
42
- "@deno/shim-prompts": "~0.1.0",
43
- "@deno/shim-timers": "~0.1.0"
44
- },
45
32
  "devDependencies": {
46
33
  "@types/node": "^20.9.0"
47
34
  },
48
- "engines": {
49
- "node": ">=16.13.0"
50
- },
35
+ "engines": {},
51
36
  "private": false,
52
37
  "publishConfig": {
53
38
  "access": "public"
@@ -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
@@ -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
@@ -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
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
- import "./_dnt.polyfills.js";
3
- //# sourceMappingURL=cli.d.ts.map
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,50 +0,0 @@
1
- #!/usr/bin/env node
2
- import "./_dnt.polyfills.js";
3
- import * as dntShim from "./_dnt.shims.js";
4
- import { parseArgs } from "./deps/jsr.io/@std/cli/1.0.9/parse_args.js";
5
- import { Adler32 } from "./mod.js";
6
- if (!(import.meta.url === ("file:///" + process.argv[1].replace(/\\/g, "/")).replace(/\/{3,}/, "///"))) {
7
- throw new Error(`This script is for command line usage only!`);
8
- }
9
- const args = parseArgs(dntShim.Deno.args, {
10
- boolean: [
11
- "file",
12
- "stdin"
13
- ]
14
- });
15
- const fromFile = args.file;
16
- const fromStdin = args.stdin;
17
- const argsValues = args._.map((value) => {
18
- return String(value);
19
- });
20
- if (fromFile && fromStdin) {
21
- throw new SyntaxError(`Unable to use the sources of file and stdin together!`);
22
- }
23
- if (fromFile) {
24
- if (argsValues.length === 0) {
25
- throw new SyntaxError(`File path is not defined!`);
26
- }
27
- if (argsValues.length !== 1) {
28
- throw new SyntaxError(`Too many arguments! Expect: 1; Current: ${argsValues.length}.`);
29
- }
30
- console.log((await Adler32.fromFile(argsValues[0])).hashHexPadding());
31
- }
32
- else if (fromStdin) {
33
- if (argsValues.length !== 0) {
34
- throw new SyntaxError(`Too many arguments! Expect: 0; Current: ${argsValues.length}.`);
35
- }
36
- let data = Uint8Array.from([]);
37
- for await (const chunk of dntShim.Deno.stdin.readable) {
38
- data = Uint8Array.from([...data, ...chunk]);
39
- }
40
- console.log(new Adler32(new TextDecoder().decode(data).replace(/\r?\n$/, "")).hashHexPadding());
41
- }
42
- else {
43
- if (argsValues.length === 0) {
44
- throw new SyntaxError(`Data is not defined!`);
45
- }
46
- if (argsValues.length !== 1) {
47
- throw new SyntaxError(`Too many arguments! Expect: 1; Current: ${argsValues.length}.`);
48
- }
49
- console.log(new Adler32(argsValues[0]).hashHexPadding());
50
- }
@@ -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,KA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EtE;;;;;OAKG;IACH,SAAS,CAAC,EAAE,UAAU,GAAG,aAAa,CAAC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;IAEpE;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,CAAC,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
- }