@hugoalh/adler32 0.1.0 → 0.1.1

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
@@ -48,9 +48,10 @@ An ES (JavaScript & TypeScript) CLI and module to get the checksum of the data w
48
48
  > - For usage of JSR or NPM resources, it is recommended to import the entire module with the main entrypoint, however it is also able to import part of the module with sub entrypoint if available, please visit the [file `jsr.jsonc`](./jsr.jsonc) property `exports` for available sub entrypoints.
49
49
  > - It is recommended to use this module with tag for immutability.
50
50
 
51
- ### 🛡️ Require Runtime Permissions
51
+ ### 🛡️ Runtime Permissions
52
52
 
53
- *This module does not require any runtime permission.*
53
+ - File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) 🧪: `fs-read`\]
54
+ - *Resources* (Optional)
54
55
 
55
56
  ## 🧩 APIs
56
57
 
package/cli.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,qBAAqB,CAAC"}
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 CHANGED
@@ -7,46 +7,49 @@ if (!(import.meta.url === ("file:///" + process.argv[1].replace(/\\/g, "/")).rep
7
7
  throw new Error(`This script is for command line usage only!`);
8
8
  }
9
9
  const args = parseArgs(dntShim.Deno.args, {
10
- boolean: ["file", "stdin"],
10
+ boolean: [
11
+ "file",
12
+ "stdin"
13
+ ]
11
14
  });
12
15
  const fromFile = args.file;
13
16
  const fromStdin = args.stdin;
14
- const values = args._.map((value) => {
17
+ const argsValues = args._.map((value) => {
15
18
  return String(value);
16
19
  });
17
20
  if (fromFile && fromStdin) {
18
21
  throw new SyntaxError(`Unable to use the sources of file and stdin together!`);
19
22
  }
20
23
  if (fromFile) {
21
- if (values.length === 0) {
24
+ if (argsValues.length === 0) {
22
25
  throw new SyntaxError(`File path is not defined!`);
23
26
  }
24
- if (values.length !== 1) {
25
- throw new SyntaxError(`Too many arguments! Expect: 1; Current: ${values.length}.`);
27
+ if (argsValues.length !== 1) {
28
+ throw new SyntaxError(`Too many arguments! Expect: 1; Current: ${argsValues.length}.`);
26
29
  }
27
- console.log((await Adler32.fromFile(values[0])).hashHexPadding());
30
+ console.log((await Adler32.fromFile(argsValues[0])).hashHexPadding());
28
31
  }
29
32
  else if (fromStdin) {
30
- if (values.length !== 0) {
31
- throw new SyntaxError(`Too many arguments! Expect: 0; Current: ${values.length}.`);
33
+ if (argsValues.length !== 0) {
34
+ throw new SyntaxError(`Too many arguments! Expect: 0; Current: ${argsValues.length}.`);
32
35
  }
33
36
  const stdinReader = dntShim.Deno.stdin.readable.getReader();
34
- const instance = new Adler32();
37
+ let data = Uint8Array.from([]);
35
38
  while (true) {
36
39
  const { done, value } = await stdinReader.read();
37
40
  if (done) {
38
41
  break;
39
42
  }
40
- instance.update(value);
43
+ data = Uint8Array.from([...data, ...value]);
41
44
  }
42
- console.log(instance.hashHexPadding());
45
+ console.log(new Adler32(new TextDecoder().decode(data).replace(/\r?\n$/, "")).hashHexPadding());
43
46
  }
44
47
  else {
45
- if (values.length === 0) {
48
+ if (argsValues.length === 0) {
46
49
  throw new SyntaxError(`Data is not defined!`);
47
50
  }
48
- if (values.length !== 1) {
49
- throw new SyntaxError(`Too many arguments! Expect: 1; Current: ${values.length}.`);
51
+ if (argsValues.length !== 1) {
52
+ throw new SyntaxError(`Too many arguments! Expect: 1; Current: ${argsValues.length}.`);
50
53
  }
51
- console.log(new Adler32(values[0]).hashHexPadding());
54
+ console.log(new Adler32(argsValues[0]).hashHexPadding());
52
55
  }
package/mod.d.ts CHANGED
@@ -53,12 +53,22 @@ export declare class Adler32 {
53
53
  update(data: Adler32AcceptDataType): this;
54
54
  /**
55
55
  * Initialize from file, asynchronously.
56
+ *
57
+ * > **🛡️ Runtime Permissions**
58
+ * >
59
+ * > - File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) 🧪: `fs-read`\]
60
+ * > - *Resources*
56
61
  * @param {string | URL} filePath Path of the file.
57
62
  * @returns {Promise<Adler32>}
58
63
  */
59
64
  static fromFile(filePath: string | URL): Promise<Adler32>;
60
65
  /**
61
66
  * Initialize from file, synchronously.
67
+ *
68
+ * > **🛡️ Runtime Permissions**
69
+ * >
70
+ * > - File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) 🧪: `fs-read`\]
71
+ * > - *Resources*
62
72
  * @param {string | URL} filePath Path of the file.
63
73
  * @returns {Adler32}
64
74
  */
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,WAAW,GAAG,aAAa,GAAG,cAAc,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,GAAG,WAAW,CAAC;AACzK;;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,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI;IAQzC;;;;OAIG;WACU,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAG/D;;;;OAIG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO;CAGpD;AACD,eAAe,OAAO,CAAC"}
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,WAAW,GAAG,aAAa,GAAG,cAAc,GAAG,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,WAAW,GAAG,WAAW,CAAC;AACzK;;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,CAAC,IAAI,EAAE,qBAAqB,GAAG,IAAI;IAQzC;;;;;;;;;OASG;WACU,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAG/D;;;;;;;;;OASG;IACH,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,GAAG,OAAO;CAGpD;AACD,eAAe,OAAO,CAAC"}
package/mod.js CHANGED
@@ -83,19 +83,29 @@ export class Adler32 {
83
83
  }
84
84
  /**
85
85
  * Initialize from file, asynchronously.
86
+ *
87
+ * > **🛡️ Runtime Permissions**
88
+ * >
89
+ * > - File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) 🧪: `fs-read`\]
90
+ * > - *Resources*
86
91
  * @param {string | URL} filePath Path of the file.
87
92
  * @returns {Promise<Adler32>}
88
93
  */
89
94
  static async fromFile(filePath) {
90
- return new Adler32(await dntShim.Deno.readFile(filePath));
95
+ return new this(await dntShim.Deno.readFile(filePath));
91
96
  }
92
97
  /**
93
98
  * Initialize from file, synchronously.
99
+ *
100
+ * > **🛡️ Runtime Permissions**
101
+ * >
102
+ * > - File System - Read \[Deno: `read`; NodeJS (>= v20.9.0) 🧪: `fs-read`\]
103
+ * > - *Resources*
94
104
  * @param {string | URL} filePath Path of the file.
95
105
  * @returns {Adler32}
96
106
  */
97
107
  static fromFileSync(filePath) {
98
- return new Adler32(dntShim.Deno.readFileSync(filePath));
108
+ return new this(dntShim.Deno.readFileSync(filePath));
99
109
  }
100
110
  }
101
111
  export default Adler32;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hugoalh/adler32",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A CLI and module to get the checksum of the data with algorithm Adler32.",
5
5
  "keywords": [
6
6
  "adler32"
@@ -18,6 +18,12 @@
18
18
  "main": "./mod.js",
19
19
  "module": "./mod.js",
20
20
  "exports": {
21
+ "./cli": {
22
+ "import": {
23
+ "types": "./cli.d.ts",
24
+ "default": "./cli.js"
25
+ }
26
+ },
21
27
  ".": {
22
28
  "import": {
23
29
  "types": "./mod.d.ts",