@hugoalh/adler32 0.5.0 → 0.6.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/LICENSE.md +1 -1
- package/README.md +53 -33
- package/_dnt.polyfills.d.ts +111 -0
- package/_dnt.polyfills.d.ts.map +1 -0
- package/_dnt.polyfills.js +141 -0
- package/_dnt.shims.d.ts +12 -0
- package/_dnt.shims.d.ts.map +1 -0
- package/_dnt.shims.js +70 -0
- package/cli.d.ts +3 -0
- package/cli.d.ts.map +1 -0
- package/cli.js +102 -0
- package/deps/jsr.io/@std/cli/1.0.32/parse_args.d.ts +343 -0
- package/deps/jsr.io/@std/cli/1.0.32/parse_args.d.ts.map +1 -0
- package/deps/jsr.io/@std/cli/1.0.32/parse_args.js +372 -0
- package/mod.d.ts +1 -0
- package/mod.d.ts.map +1 -1
- package/mod.js +10 -13
- package/package.json +17 -4
package/LICENSE.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# MIT License
|
|
2
2
|
|
|
3
|
-
Copyright © 2024\~
|
|
3
|
+
Copyright © 2024\~2026 HUGOALH
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
package/README.md
CHANGED
|
@@ -2,54 +2,53 @@
|
|
|
2
2
|
|
|
3
3
|
[**⚖️** MIT](./LICENSE.md)
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
[
|
|
7
|
-
[
|
|
5
|
+
🔗
|
|
6
|
+
[DistBoard @hugoalh](https://hugoalh.github.io/distboard/adler32_ecmascript)
|
|
7
|
+
● [GitHub](https://github.com/hugoalh/adler32-es)
|
|
8
|
+
● [JSR](https://jsr.io/@hugoalh/adler32)
|
|
9
|
+
● [NPM](https://www.npmjs.com/package/@hugoalh/adler32)
|
|
8
10
|
|
|
9
|
-
An ECMAScript
|
|
11
|
+
An ECMAScript module to get the checksum of the data with algorithm Adler32.
|
|
10
12
|
|
|
11
|
-
##
|
|
13
|
+
## 🎯 Runtime Targets
|
|
12
14
|
|
|
13
|
-
|
|
15
|
+
Any runtime which support ECMAScript should able to use this; These runtimes are officially supported:
|
|
14
16
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
| **[Deno](https://deno.land/)** >= v2.1.0 | ✔️ | ✔️ | ✔️ |
|
|
19
|
-
| **[NodeJS](https://nodejs.org/)** >= v20.9.0 | ❌ | ✔️ | ✔️ |
|
|
17
|
+
- **[Bun](https://bun.sh/)** >= v1.1.0
|
|
18
|
+
- **[Deno](https://deno.land/)** >= v2.1.0
|
|
19
|
+
- **[NodeJS](https://nodejs.org/)** >= v20.9.0
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
## 🛡️ Runtime Permissions
|
|
22
|
+
|
|
23
|
+
This does not request any runtime permission.
|
|
23
24
|
|
|
24
|
-
|
|
25
|
+
## #️⃣ Sources & Entrypoints
|
|
25
26
|
|
|
26
|
-
-
|
|
27
|
+
- GitHub Raw
|
|
27
28
|
```
|
|
28
29
|
https://raw.githubusercontent.com/hugoalh/adler32-es/{Tag}/mod.ts
|
|
29
30
|
```
|
|
30
|
-
-
|
|
31
|
+
- JSR
|
|
31
32
|
```
|
|
32
|
-
|
|
33
|
+
jsr:@hugoalh/adler32[@{Tag}]
|
|
33
34
|
```
|
|
34
|
-
-
|
|
35
|
+
- NPM
|
|
35
36
|
```
|
|
36
|
-
|
|
37
|
+
npm:@hugoalh/adler32[@{Tag}]
|
|
37
38
|
```
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
> - it is a benchmark or test file (e.g.: `foo.bench.ts`, `foo.test.ts`), or
|
|
44
|
-
> - it's symbol has an underscore prefix (e.g.: `_bar`, `_foo`).
|
|
45
|
-
>
|
|
46
|
-
> These elements are not considered part of the public API, thus no stability is guaranteed for them.
|
|
47
|
-
> - 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.
|
|
48
|
-
> - It is recommended to use this module with tag for immutability.
|
|
49
|
-
|
|
50
|
-
### 🛡️ Runtime Permissions
|
|
40
|
+
| **Name** | **Path** | **Description** |
|
|
41
|
+
|:--|:--|:--|
|
|
42
|
+
| `.` | `./mod.ts` | Default. |
|
|
43
|
+
| `./cli` | `./cli.ts` | CLI. |
|
|
51
44
|
|
|
52
|
-
|
|
45
|
+
> [!NOTE]
|
|
46
|
+
> - Different runtimes have vary support for the sources and entrypoints, visit the runtime documentation for more information.
|
|
47
|
+
> - It is recommended to include tag for immutability.
|
|
48
|
+
> - These are not part of the public APIs hence should not be used:
|
|
49
|
+
> - Benchmark/Test file (e.g.: `example.bench.ts`, `example.test.ts`).
|
|
50
|
+
> - Entrypoint name or path include any underscore prefix (e.g.: `_example.ts`, `foo/_example.ts`).
|
|
51
|
+
> - Identifier/Namespace/Symbol include any underscore prefix (e.g.: `_example`, `Foo._example`).
|
|
53
52
|
|
|
54
53
|
## 🧩 APIs
|
|
55
54
|
|
|
@@ -75,12 +74,33 @@ An ECMAScript (JavaScript & TypeScript) module to get the checksum of the data w
|
|
|
75
74
|
|
|
76
75
|
> [!NOTE]
|
|
77
76
|
> - For the full or prettier documentation, can visit via:
|
|
78
|
-
> - [Deno CLI `deno doc`](https://docs.deno.com/runtime/reference/cli/
|
|
77
|
+
> - [Deno CLI `deno doc`](https://docs.deno.com/runtime/reference/cli/doc/)
|
|
79
78
|
> - [JSR](https://jsr.io/@hugoalh/adler32)
|
|
80
79
|
|
|
80
|
+
## 🧩 CLIs
|
|
81
|
+
|
|
82
|
+
- ```powershell
|
|
83
|
+
adler32 $Context
|
|
84
|
+
```
|
|
85
|
+
- ```powershell
|
|
86
|
+
adler32 --file $FilePath
|
|
87
|
+
<# 🔀 Unordered Positions: `--file`, `$FilePath` #>
|
|
88
|
+
```
|
|
89
|
+
- ```powershell
|
|
90
|
+
adler32 --stdin
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
| **Argument** | **Type** | **Description** |
|
|
94
|
+
|:--|:--|:--|
|
|
95
|
+
| `file` | `switch` | Whether the resource is from file. |
|
|
96
|
+
| `stdin` | `switch` | Whether the resource is from standard stream input. |
|
|
97
|
+
|
|
81
98
|
## ✍️ Examples
|
|
82
99
|
|
|
83
100
|
- ```ts
|
|
84
101
|
new Adler32("Wikipedia").hashHex();
|
|
85
102
|
//=> "11E60398"
|
|
86
103
|
```
|
|
104
|
+
- ```powershell
|
|
105
|
+
adler32 'Wikipedia'
|
|
106
|
+
```
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
|
|
3
|
+
* but instead of using npm to install additional dependencies,
|
|
4
|
+
* this approach manually consolidates cjs/mjs/d.ts into a single file.
|
|
5
|
+
*
|
|
6
|
+
* Note that this code might be imported multiple times
|
|
7
|
+
* (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
|
|
8
|
+
* or Node.js might dynamically clear the cache and then force a require).
|
|
9
|
+
* Therefore, it's important to avoid redundant writes to global objects.
|
|
10
|
+
* Additionally, consider that commonjs is used alongside esm,
|
|
11
|
+
* so the two ponyfill functions are stored independently in two separate global objects.
|
|
12
|
+
*/
|
|
13
|
+
import { createRequire } from "node:module";
|
|
14
|
+
import { type URL } from "node:url";
|
|
15
|
+
declare global {
|
|
16
|
+
interface ImportMeta {
|
|
17
|
+
/** A string representation of the fully qualified module URL. When the
|
|
18
|
+
* module is loaded locally, the value will be a file URL (e.g.
|
|
19
|
+
* `file:///path/module.ts`).
|
|
20
|
+
*
|
|
21
|
+
* You can also parse the string as a URL to determine more information about
|
|
22
|
+
* how the current module was loaded. For example to determine if a module was
|
|
23
|
+
* local or not:
|
|
24
|
+
*
|
|
25
|
+
* ```ts
|
|
26
|
+
* const url = new URL(import.meta.url);
|
|
27
|
+
* if (url.protocol === "file:") {
|
|
28
|
+
* console.log("this module was loaded locally");
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
url: string;
|
|
33
|
+
/**
|
|
34
|
+
* A function that returns resolved specifier as if it would be imported
|
|
35
|
+
* using `import(specifier)`.
|
|
36
|
+
*
|
|
37
|
+
* ```ts
|
|
38
|
+
* console.log(import.meta.resolve("./foo.js"));
|
|
39
|
+
* // file:///dev/foo.js
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* @param specifier The module specifier to resolve relative to `parent`.
|
|
43
|
+
* @param parent The absolute parent module URL to resolve from.
|
|
44
|
+
* @returns The absolute (`file:`) URL string for the resolved module.
|
|
45
|
+
*/
|
|
46
|
+
resolve(specifier: string, parent?: string | URL | undefined): string;
|
|
47
|
+
/** A flag that indicates if the current module is the main module that was
|
|
48
|
+
* called when starting the program under Deno.
|
|
49
|
+
*
|
|
50
|
+
* ```ts
|
|
51
|
+
* if (import.meta.main) {
|
|
52
|
+
* // this was loaded as the main module, maybe do some bootstrapping
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
main: boolean;
|
|
57
|
+
/** The absolute path of the current module.
|
|
58
|
+
*
|
|
59
|
+
* This property is only provided for local modules (ie. using `file://` URLs).
|
|
60
|
+
*
|
|
61
|
+
* Example:
|
|
62
|
+
* ```
|
|
63
|
+
* // Unix
|
|
64
|
+
* console.log(import.meta.filename); // /home/alice/my_module.ts
|
|
65
|
+
*
|
|
66
|
+
* // Windows
|
|
67
|
+
* console.log(import.meta.filename); // C:\alice\my_module.ts
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
filename: string;
|
|
71
|
+
/** The absolute path of the directory containing the current module.
|
|
72
|
+
*
|
|
73
|
+
* This property is only provided for local modules (ie. using `file://` URLs).
|
|
74
|
+
*
|
|
75
|
+
* * Example:
|
|
76
|
+
* ```
|
|
77
|
+
* // Unix
|
|
78
|
+
* console.log(import.meta.dirname); // /home/alice
|
|
79
|
+
*
|
|
80
|
+
* // Windows
|
|
81
|
+
* console.log(import.meta.dirname); // C:\alice
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
dirname: string;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
type NodeRequest = ReturnType<typeof createRequire>;
|
|
88
|
+
type NodeModule = NonNullable<NodeRequest["main"]>;
|
|
89
|
+
interface ImportMetaPonyfillCommonjs {
|
|
90
|
+
(require: NodeRequest, module: NodeModule): ImportMeta;
|
|
91
|
+
}
|
|
92
|
+
interface ImportMetaPonyfillEsmodule {
|
|
93
|
+
(importMeta: ImportMeta): ImportMeta;
|
|
94
|
+
}
|
|
95
|
+
interface ImportMetaPonyfill extends ImportMetaPonyfillCommonjs, ImportMetaPonyfillEsmodule {
|
|
96
|
+
}
|
|
97
|
+
export declare let import_meta_ponyfill_commonjs: ImportMetaPonyfillCommonjs;
|
|
98
|
+
export declare let import_meta_ponyfill_esmodule: ImportMetaPonyfillEsmodule;
|
|
99
|
+
export declare let import_meta_ponyfill: ImportMetaPonyfill;
|
|
100
|
+
declare global {
|
|
101
|
+
interface Object {
|
|
102
|
+
/**
|
|
103
|
+
* Determines whether an object has a property with the specified name.
|
|
104
|
+
* @param o An object.
|
|
105
|
+
* @param v A property name.
|
|
106
|
+
*/
|
|
107
|
+
hasOwn(o: object, v: PropertyKey): boolean;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export {};
|
|
111
|
+
//# sourceMappingURL=_dnt.polyfills.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAE5C,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,UAAU,CAAC;AAGlE,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,UAAU;QAClB;;;;;;;;;;;;;;WAcG;QACH,GAAG,EAAE,MAAM,CAAC;QACZ;;;;;;;;;;;;WAYG;QACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,GAAG,MAAM,CAAC;QACtE;;;;;;;;WAQG;QACH,IAAI,EAAE,OAAO,CAAC;QAEd;;;;;;;;;;;;WAYG;QACH,QAAQ,EAAE,MAAM,CAAC;QAEjB;;;;;;;;;;;;WAYG;QACH,OAAO,EAAE,MAAM,CAAC;KACjB;CACF;AAED,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,KAAK,UAAU,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;AACnD,UAAU,0BAA0B;IAClC,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,UAAU,CAAC;CACxD;AACD,UAAU,0BAA0B;IAClC,CAAC,UAAU,EAAE,UAAU,GAAG,UAAU,CAAC;CACtC;AACD,UAAU,kBACR,SAAQ,0BAA0B,EAAE,0BAA0B;CAC/D;AAiBD,eAAO,IAAI,6BAA6B,EA2BnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,6BAA6B,EA4DnC,0BAA0B,CAAC;AAMhC,eAAO,IAAI,oBAAoB,EAoB1B,kBAAkB,CAAC;AAgBxB,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"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Based on [import-meta-ponyfill](https://github.com/gaubee/import-meta-ponyfill),
|
|
3
|
+
* but instead of using npm to install additional dependencies,
|
|
4
|
+
* this approach manually consolidates cjs/mjs/d.ts into a single file.
|
|
5
|
+
*
|
|
6
|
+
* Note that this code might be imported multiple times
|
|
7
|
+
* (for example, both dnt.test.polyfills.ts and dnt.polyfills.ts contain this code;
|
|
8
|
+
* or Node.js might dynamically clear the cache and then force a require).
|
|
9
|
+
* Therefore, it's important to avoid redundant writes to global objects.
|
|
10
|
+
* Additionally, consider that commonjs is used alongside esm,
|
|
11
|
+
* so the two ponyfill functions are stored independently in two separate global objects.
|
|
12
|
+
*/
|
|
13
|
+
//@ts-ignore
|
|
14
|
+
import { createRequire } from "node:module";
|
|
15
|
+
//@ts-ignore
|
|
16
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
17
|
+
//@ts-ignore
|
|
18
|
+
import { dirname } from "node:path";
|
|
19
|
+
const defineGlobalPonyfill = (symbolFor, fn) => {
|
|
20
|
+
if (!Reflect.has(globalThis, Symbol.for(symbolFor))) {
|
|
21
|
+
Object.defineProperty(globalThis, Symbol.for(symbolFor), {
|
|
22
|
+
configurable: true,
|
|
23
|
+
get() {
|
|
24
|
+
return fn;
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export let import_meta_ponyfill_commonjs = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-commonjs")) ??
|
|
30
|
+
(() => {
|
|
31
|
+
const moduleImportMetaWM = new WeakMap();
|
|
32
|
+
return (require, module) => {
|
|
33
|
+
let importMetaCache = moduleImportMetaWM.get(module);
|
|
34
|
+
if (importMetaCache == null) {
|
|
35
|
+
const importMeta = Object.assign(Object.create(null), {
|
|
36
|
+
url: pathToFileURL(module.filename).href,
|
|
37
|
+
main: require.main == module,
|
|
38
|
+
resolve: (specifier, parentURL = importMeta.url) => {
|
|
39
|
+
return pathToFileURL((importMeta.url === parentURL
|
|
40
|
+
? require
|
|
41
|
+
: createRequire(parentURL))
|
|
42
|
+
.resolve(specifier)).href;
|
|
43
|
+
},
|
|
44
|
+
filename: module.filename,
|
|
45
|
+
dirname: module.path,
|
|
46
|
+
});
|
|
47
|
+
moduleImportMetaWM.set(module, importMeta);
|
|
48
|
+
importMetaCache = importMeta;
|
|
49
|
+
}
|
|
50
|
+
return importMetaCache;
|
|
51
|
+
};
|
|
52
|
+
})());
|
|
53
|
+
defineGlobalPonyfill("import-meta-ponyfill-commonjs", import_meta_ponyfill_commonjs);
|
|
54
|
+
export let import_meta_ponyfill_esmodule = (Reflect.get(globalThis, Symbol.for("import-meta-ponyfill-esmodule")) ??
|
|
55
|
+
((importMeta) => {
|
|
56
|
+
const resolveFunStr = String(importMeta.resolve);
|
|
57
|
+
const shimWs = new WeakSet();
|
|
58
|
+
//@ts-ignore
|
|
59
|
+
const mainUrl = ("file:///" + process.argv[1].replace(/\\/g, "/"))
|
|
60
|
+
.replace(/\/{3,}/, "///");
|
|
61
|
+
const commonShim = (importMeta) => {
|
|
62
|
+
if (typeof importMeta.main !== "boolean") {
|
|
63
|
+
importMeta.main = importMeta.url === mainUrl;
|
|
64
|
+
}
|
|
65
|
+
if (typeof importMeta.filename !== "string") {
|
|
66
|
+
importMeta.filename = fileURLToPath(importMeta.url);
|
|
67
|
+
importMeta.dirname = dirname(importMeta.filename);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
if (
|
|
71
|
+
// v16.2.0+, v14.18.0+: Add support for WHATWG URL object to parentURL parameter.
|
|
72
|
+
resolveFunStr === "undefined" ||
|
|
73
|
+
// v20.0.0+, v18.19.0+"" This API now returns a string synchronously instead of a Promise.
|
|
74
|
+
resolveFunStr.startsWith("async")
|
|
75
|
+
// enable by --experimental-import-meta-resolve flag
|
|
76
|
+
) {
|
|
77
|
+
import_meta_ponyfill_esmodule = (importMeta) => {
|
|
78
|
+
if (!shimWs.has(importMeta)) {
|
|
79
|
+
shimWs.add(importMeta);
|
|
80
|
+
const importMetaUrlRequire = {
|
|
81
|
+
url: importMeta.url,
|
|
82
|
+
require: createRequire(importMeta.url),
|
|
83
|
+
};
|
|
84
|
+
importMeta.resolve = function resolve(specifier, parentURL = importMeta.url) {
|
|
85
|
+
return pathToFileURL((importMetaUrlRequire.url === parentURL
|
|
86
|
+
? importMetaUrlRequire.require
|
|
87
|
+
: createRequire(parentURL)).resolve(specifier)).href;
|
|
88
|
+
};
|
|
89
|
+
commonShim(importMeta);
|
|
90
|
+
}
|
|
91
|
+
return importMeta;
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
/// native support
|
|
96
|
+
import_meta_ponyfill_esmodule = (importMeta) => {
|
|
97
|
+
if (!shimWs.has(importMeta)) {
|
|
98
|
+
shimWs.add(importMeta);
|
|
99
|
+
commonShim(importMeta);
|
|
100
|
+
}
|
|
101
|
+
return importMeta;
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return import_meta_ponyfill_esmodule(importMeta);
|
|
105
|
+
}));
|
|
106
|
+
defineGlobalPonyfill("import-meta-ponyfill-esmodule", import_meta_ponyfill_esmodule);
|
|
107
|
+
export let import_meta_ponyfill = ((...args) => {
|
|
108
|
+
const _MODULE = (() => {
|
|
109
|
+
if (typeof require === "function" && typeof module === "object") {
|
|
110
|
+
return "commonjs";
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// eval("typeof import.meta");
|
|
114
|
+
return "esmodule";
|
|
115
|
+
}
|
|
116
|
+
})();
|
|
117
|
+
if (_MODULE === "commonjs") {
|
|
118
|
+
//@ts-ignore
|
|
119
|
+
import_meta_ponyfill = (r, m) => import_meta_ponyfill_commonjs(r, m);
|
|
120
|
+
}
|
|
121
|
+
else {
|
|
122
|
+
//@ts-ignore
|
|
123
|
+
import_meta_ponyfill = (im) => import_meta_ponyfill_esmodule(im);
|
|
124
|
+
}
|
|
125
|
+
//@ts-ignore
|
|
126
|
+
return import_meta_ponyfill(...args);
|
|
127
|
+
});
|
|
128
|
+
// https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
|
|
129
|
+
if (!Object.hasOwn) {
|
|
130
|
+
Object.defineProperty(Object, "hasOwn", {
|
|
131
|
+
value: function (object, property) {
|
|
132
|
+
if (object == null) {
|
|
133
|
+
throw new TypeError("Cannot convert undefined or null to object");
|
|
134
|
+
}
|
|
135
|
+
return Object.prototype.hasOwnProperty.call(Object(object), property);
|
|
136
|
+
},
|
|
137
|
+
configurable: true,
|
|
138
|
+
enumerable: false,
|
|
139
|
+
writable: true,
|
|
140
|
+
});
|
|
141
|
+
}
|
package/_dnt.shims.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
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
ADDED
package/cli.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
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.32/parse_args.js";
|
|
57
|
+
import { Adler32 } from "./mod.js";
|
|
58
|
+
if (!globalThis[Symbol.for("import-meta-ponyfill-esmodule")](import.meta).main) {
|
|
59
|
+
throw new Error(`This entrypoint is for command line 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 request resource from file and stdin together!`);
|
|
74
|
+
}
|
|
75
|
+
const expectArgumentsLength = fromStdin ? 0 : 1;
|
|
76
|
+
if (argsValues.length !== expectArgumentsLength) {
|
|
77
|
+
throw new SyntaxError(`Invalid arguments length! Expect: ${expectArgumentsLength}, Current: ${argsValues.length}.`);
|
|
78
|
+
}
|
|
79
|
+
const instance = new Adler32();
|
|
80
|
+
if (fromFile) {
|
|
81
|
+
const env_1 = { stack: [], error: void 0, hasError: false };
|
|
82
|
+
try {
|
|
83
|
+
const file = __addDisposableResource(env_1, await dntShim.Deno.open(argsValues[0]), true);
|
|
84
|
+
await instance.updateFromStream(file.readable);
|
|
85
|
+
}
|
|
86
|
+
catch (e_1) {
|
|
87
|
+
env_1.error = e_1;
|
|
88
|
+
env_1.hasError = true;
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
const result_1 = __disposeResources(env_1);
|
|
92
|
+
if (result_1)
|
|
93
|
+
await result_1;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else if (fromStdin) {
|
|
97
|
+
await instance.updateFromStream(dntShim.Deno.stdin.readable);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
instance.update(argsValues[0]);
|
|
101
|
+
}
|
|
102
|
+
console.log(instance.hashHex());
|