@hugoalh/adler32 0.1.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 ADDED
@@ -0,0 +1,35 @@
1
+ # MIT License
2
+
3
+ Copyright © 2024 hugoalh
4
+
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
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
11
+ ---
12
+
13
+ ## TLDR
14
+
15
+ This is a short and simple list that mostly concluded this license about the permissions, conditions, and limitations, this license content section shall prevail.
16
+
17
+ ### Permissions
18
+
19
+ - **Commercial Use:** The licensed material and derivatives may be used for commercial purposes.
20
+ - **Distribution:** The licensed material may be distributed.
21
+ - **Modification:** The licensed material may be modified.
22
+ - **Private Use:** The licensed material may be used and modified in private.
23
+
24
+ ### Conditions
25
+
26
+ - **License & Copyright Notice:** A copy of the license and copyright notice must be included with the licensed material.
27
+
28
+ ### Limitations
29
+
30
+ - **Liability:** This license includes a limitation of liability.
31
+ - **Warranty:** This license explicitly states that it does not provide any warranty.
32
+
33
+ ## Attribution
34
+
35
+ This license is adopted from [Choose A License](https://choosealicense.com/), available at [here](https://choosealicense.com/licenses/mit).
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # Adler32 (ES)
2
+
3
+ [**⚖️** MIT](./LICENSE.md)
4
+
5
+ [![GitHub: hugoalh/adler32-es](https://img.shields.io/github/v/release/hugoalh/adler32-es?label=hugoalh/adler32-es&labelColor=181717&logo=github&logoColor=ffffff&sort=semver&style=flat "GitHub: hugoalh/adler32-es")](https://github.com/hugoalh/adler32-es)
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
+ [![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
+
9
+ An ES (JavaScript & TypeScript) CLI and module to get the checksum of the data with algorithm Adler32.
10
+
11
+ ## 🔰 Begin
12
+
13
+ ### 🎯 Targets
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 | ❌ | ❓ | ✔️ |
21
+
22
+ > [!NOTE]
23
+ > - 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.
24
+
25
+ ### #️⃣ Resources Identifier
26
+
27
+ - **Remote - GitHub Raw:**
28
+ ```
29
+ https://raw.githubusercontent.com/hugoalh/adler32-es/{Tag}/mod.ts
30
+ ```
31
+ - **JSR:**
32
+ ```
33
+ [jsr:]@hugoalh/adler32[@{Tag}]
34
+ ```
35
+ - **NPM:**
36
+ ```
37
+ [npm:]@hugoalh/adler32[@{Tag}]
38
+ ```
39
+
40
+ > [!NOTE]
41
+ > - For usage of remote resources, it is recommended to import the entire module with the main path `mod.ts`, however it is also able to import part of the module with sub path if available, but do not import if:
42
+ >
43
+ > - it's path has an underscore prefix (e.g.: `_foo.ts`, `_util/bar.ts`), or
44
+ > - it is a benchmark or test file (e.g.: `foo.bench.ts`, `foo.test.ts`), or
45
+ > - it's symbol has an underscore prefix (e.g.: `_bar`, `_foo`).
46
+ >
47
+ > These elements are not considered part of the public API, thus no stability is guaranteed for them.
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
+ > - It is recommended to use this module with tag for immutability.
50
+
51
+ ### 🛡️ Require Runtime Permissions
52
+
53
+ *This module does not require any runtime permission.*
54
+
55
+ ## 🧩 APIs
56
+
57
+ - ```ts
58
+ class Adler32 {
59
+ constructor(data?: Adler32AcceptDataType);
60
+ hash(): bigint;
61
+ hashBase16(): string;
62
+ hashBase32Hex(): string;
63
+ hashBase36(): string;
64
+ hashHex(): string;
65
+ hashHexPadding(): string;
66
+ hashNumber(): number;
67
+ update(data: Adler32AcceptDataType): this;
68
+ static fromFile(filePath: string | URL): Promise<Adler32>;
69
+ static fromFileSync(filePath: string | URL): Adler32;
70
+ }
71
+ ```
72
+ - ```ts
73
+ type Adler32AcceptDataType = string | ArrayBuffer | BigInt64Array | BigUint64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array;
74
+ ```
75
+
76
+ > [!NOTE]
77
+ > - For the full or prettier documentation, can visit via:
78
+ > - [Deno CLI `deno doc`](https://docs.deno.com/runtime/reference/cli/documentation_generator/)
79
+ > - [JSR](https://jsr.io/@hugoalh/adler32)
80
+
81
+ ## 🧩 CLIs
82
+
83
+ **Entrypoint:** `cli.js`/`cli.ts`
84
+
85
+ - From argument; Output hex padding
86
+ ```ps1
87
+ adler32 {Data}
88
+ ```
89
+ - From file; Output hex padding
90
+ ```ps1
91
+ adler32 --file {FilePath}
92
+ ```
93
+ - From stdin; Output hex padding
94
+ ```ps1
95
+ adler32 --stdin
96
+ ```
97
+
98
+ ## ✍️ Examples
99
+
100
+ - ```ts
101
+ new Adler32("Wikipedia").hashHexPadding();
102
+ //=> "11E60398"
103
+ ```
@@ -0,0 +1,36 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,15 @@
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 {};
@@ -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
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import "./_dnt.polyfills.js";
3
+ //# sourceMappingURL=cli.d.ts.map
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"}
package/cli.js ADDED
@@ -0,0 +1,52 @@
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.6/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: ["file", "stdin"],
11
+ });
12
+ const fromFile = args.file;
13
+ const fromStdin = args.stdin;
14
+ const values = args._.map((value) => {
15
+ return String(value);
16
+ });
17
+ if (fromFile && fromStdin) {
18
+ throw new SyntaxError(`Unable to use the sources of file and stdin together!`);
19
+ }
20
+ if (fromFile) {
21
+ if (values.length === 0) {
22
+ throw new SyntaxError(`File path is not defined!`);
23
+ }
24
+ if (values.length !== 1) {
25
+ throw new SyntaxError(`Too many arguments! Expect: 1; Current: ${values.length}.`);
26
+ }
27
+ console.log((await Adler32.fromFile(values[0])).hashHexPadding());
28
+ }
29
+ else if (fromStdin) {
30
+ if (values.length !== 0) {
31
+ throw new SyntaxError(`Too many arguments! Expect: 0; Current: ${values.length}.`);
32
+ }
33
+ const stdinReader = dntShim.Deno.stdin.readable.getReader();
34
+ const instance = new Adler32();
35
+ while (true) {
36
+ const { done, value } = await stdinReader.read();
37
+ if (done) {
38
+ break;
39
+ }
40
+ instance.update(value);
41
+ }
42
+ console.log(instance.hashHexPadding());
43
+ }
44
+ else {
45
+ if (values.length === 0) {
46
+ throw new SyntaxError(`Data is not defined!`);
47
+ }
48
+ if (values.length !== 1) {
49
+ throw new SyntaxError(`Too many arguments! Expect: 1; Current: ${values.length}.`);
50
+ }
51
+ console.log(new Adler32(values[0]).hashHexPadding());
52
+ }
@@ -0,0 +1,229 @@
1
+ /**
2
+ * Command line arguments parser based on
3
+ * {@link https://github.com/minimistjs/minimist | minimist}.
4
+ *
5
+ * @example
6
+ * ```ts
7
+ * import { parseArgs } from "@std/cli/parse-args";
8
+ *
9
+ * console.dir(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
106
+ * ```ts
107
+ * // $ deno run example.ts -- a arg1
108
+ * import { parseArgs } from "@std/cli/parse-args";
109
+ * console.dir(parseArgs(Deno.args, { "--": false }));
110
+ * // output: { _: [ "a", "arg1" ] }
111
+ * console.dir(parseArgs(Deno.args, { "--": true }));
112
+ * // output: { _: [], --: [ "a", "arg1" ] }
113
+ * ```
114
+ */
115
+ "--"?: TDoubleDash;
116
+ /**
117
+ * An object mapping string names to strings or arrays of string argument
118
+ * names to use as aliases.
119
+ *
120
+ * @default {{}}
121
+ */
122
+ alias?: TAliases;
123
+ /**
124
+ * A boolean, string or array of strings to always treat as booleans. If
125
+ * `true` will treat all double hyphenated arguments without equal signs as
126
+ * `boolean` (e.g. affects `--foo`, not `-f` or `--foo=bar`).
127
+ * All `boolean` arguments will be set to `false` by default.
128
+ *
129
+ * @default {false}
130
+ */
131
+ boolean?: TBooleans | ReadonlyArray<Extract<TBooleans, string>>;
132
+ /**
133
+ * An object mapping string argument names to default values.
134
+ *
135
+ * @default {{}}
136
+ */
137
+ default?: TDefault & Defaults<TBooleans, TStrings>;
138
+ /**
139
+ * When `true`, populate the result `_` with everything after the first
140
+ * non-option.
141
+ *
142
+ * @default {false}
143
+ */
144
+ stopEarly?: boolean;
145
+ /**
146
+ * A string or array of strings argument names to always treat as strings.
147
+ *
148
+ * @default {[]}
149
+ */
150
+ string?: TStrings | ReadonlyArray<Extract<TStrings, string>>;
151
+ /**
152
+ * A string or array of strings argument names to always treat as arrays.
153
+ * Collectable options can be used multiple times. All values will be
154
+ * collected into one array. If a non-collectable option is used multiple
155
+ * times, the last value is used.
156
+ *
157
+ * @default {[]}
158
+ */
159
+ collect?: TCollectable | ReadonlyArray<Extract<TCollectable, string>>;
160
+ /**
161
+ * A string or array of strings argument names which can be negated
162
+ * by prefixing them with `--no-`, like `--no-config`.
163
+ *
164
+ * @default {[]}
165
+ */
166
+ negatable?: TNegatable | ReadonlyArray<Extract<TNegatable, string>>;
167
+ /**
168
+ * A function which is invoked with a command line parameter not defined in
169
+ * the `options` configuration object. If the function returns `false`, the
170
+ * unknown option is not added to `parsedArgs`.
171
+ *
172
+ * @default {unknown}
173
+ */
174
+ unknown?: (arg: string, key?: string, value?: unknown) => unknown;
175
+ }
176
+ /**
177
+ * Take a set of command line arguments, optionally with a set of options, and
178
+ * return an object representing the flags found in the passed arguments.
179
+ *
180
+ * By default, any arguments starting with `-` or `--` are considered boolean
181
+ * flags. If the argument name is followed by an equal sign (`=`) it is
182
+ * considered a key-value pair. Any arguments which could not be parsed are
183
+ * available in the `_` property of the returned object.
184
+ *
185
+ * By default, this module tries to determine the type of all arguments
186
+ * automatically and the return type of this function will have an index
187
+ * signature with `any` as value (`{ [x: string]: any }`).
188
+ *
189
+ * If the `string`, `boolean` or `collect` option is set, the return value of
190
+ * this function will be fully typed and the index signature of the return
191
+ * type will change to `{ [x: string]: unknown }`.
192
+ *
193
+ * Any arguments after `'--'` will not be parsed and will end up in `parsedArgs._`.
194
+ *
195
+ * Numeric-looking arguments will be returned as numbers unless `options.string`
196
+ * or `options.boolean` is set for that argument name.
197
+ *
198
+ * @param args An array of command line arguments.
199
+ * @param options Options for the parse function.
200
+ *
201
+ * @typeParam TArgs Type of result.
202
+ * @typeParam TDoubleDash Used by `TArgs` for the result.
203
+ * @typeParam TBooleans Used by `TArgs` for the result.
204
+ * @typeParam TStrings Used by `TArgs` for the result.
205
+ * @typeParam TCollectable Used by `TArgs` for the result.
206
+ * @typeParam TNegatable Used by `TArgs` for the result.
207
+ * @typeParam TDefaults Used by `TArgs` for the result.
208
+ * @typeParam TAliases Used by `TArgs` for the result.
209
+ * @typeParam TAliasArgNames Used by `TArgs` for the result.
210
+ * @typeParam TAliasNames Used by `TArgs` for the result.
211
+ *
212
+ * @return The parsed arguments.
213
+ *
214
+ * @example Usage
215
+ * ```ts
216
+ * import { parseArgs } from "@std/cli/parse-args";
217
+ * import { assertEquals } from "@std/assert";
218
+ *
219
+ * // For proper use, one should use `parseArgs(Deno.args)`
220
+ * assertEquals(parseArgs(["--foo", "--bar=baz", "./quux.txt"]), {
221
+ * foo: true,
222
+ * bar: "baz",
223
+ * _: ["./quux.txt"],
224
+ * });
225
+ * ```
226
+ */
227
+ 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>;
228
+ export {};
229
+ //# sourceMappingURL=parse_args.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parse_args.d.ts","sourceRoot":"","sources":["../../../../../../src/deps/jsr.io/@std/cli/1.0.6/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,SAAS,SAAS,WAAW,EAC7B,QAAQ,SAAS,UAAU,EAC3B,YAAY,SAAS,WAAW,IAC9B,SAAS,SAAS,CAClB,CAAC,KAAK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;;;;;;;;;;;;;;;;;;;;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"}
@@ -0,0 +1,305 @@
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
+ }
package/mod.d.ts ADDED
@@ -0,0 +1,68 @@
1
+ import "./_dnt.polyfills.js";
2
+ export type Adler32AcceptDataType = string | ArrayBuffer | BigInt64Array | BigUint64Array | Int8Array | Int16Array | Int32Array | Uint8Array | Uint16Array | Uint32Array;
3
+ /**
4
+ * Get the checksum of the data with algorithm Adler32.
5
+ */
6
+ export declare class Adler32 {
7
+ #private;
8
+ /**
9
+ * Initialize.
10
+ * @param {Adler32AcceptDataType} [data] Data. Can append later via the method {@linkcode Adler32.update}.
11
+ */
12
+ constructor(data?: Adler32AcceptDataType);
13
+ /**
14
+ * Get the checksum of the data, in big integer.
15
+ * @returns {bigint}
16
+ */
17
+ hash(): bigint;
18
+ /**
19
+ * Get the checksum of the data, in Base16.
20
+ * @returns {string}
21
+ */
22
+ hashBase16(): string;
23
+ /**
24
+ * Get the checksum of the data, in Base32Hex ({@link https://datatracker.ietf.org/doc/html/rfc4648#section-7 RFC 4648 §7}).
25
+ * @returns {string}
26
+ */
27
+ hashBase32Hex(): string;
28
+ /**
29
+ * Get the checksum of the data, in Base36.
30
+ * @returns {string}
31
+ */
32
+ hashBase36(): string;
33
+ /**
34
+ * Get the checksum of the data, in hex/hexadecimal without padding.
35
+ * @returns {string}
36
+ */
37
+ hashHex(): string;
38
+ /**
39
+ * Get the checksum of the data, in hex/hexadecimal with padding.
40
+ * @returns {string}
41
+ */
42
+ hashHexPadding(): string;
43
+ /**
44
+ * Get the checksum of the data, in number.
45
+ * @returns {number}
46
+ */
47
+ hashNumber(): number;
48
+ /**
49
+ * Append data.
50
+ * @param {Adler32AcceptDataType} data Data.
51
+ * @returns {this}
52
+ */
53
+ update(data: Adler32AcceptDataType): this;
54
+ /**
55
+ * Initialize from file, asynchronously.
56
+ * @param {string | URL} filePath Path of the file.
57
+ * @returns {Promise<Adler32>}
58
+ */
59
+ static fromFile(filePath: string | URL): Promise<Adler32>;
60
+ /**
61
+ * Initialize from file, synchronously.
62
+ * @param {string | URL} filePath Path of the file.
63
+ * @returns {Adler32}
64
+ */
65
+ static fromFileSync(filePath: string | URL): Adler32;
66
+ }
67
+ export default Adler32;
68
+ //# sourceMappingURL=mod.d.ts.map
package/mod.d.ts.map ADDED
@@ -0,0 +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"}
package/mod.js ADDED
@@ -0,0 +1,101 @@
1
+ import "./_dnt.polyfills.js";
2
+ import * as dntShim from "./_dnt.shims.js";
3
+ /**
4
+ * Get the checksum of the data with algorithm Adler32.
5
+ */
6
+ export class Adler32 {
7
+ #a = 1n;
8
+ #b = 0n;
9
+ #hash = null;
10
+ /**
11
+ * Initialize.
12
+ * @param {Adler32AcceptDataType} [data] Data. Can append later via the method {@linkcode Adler32.update}.
13
+ */
14
+ constructor(data) {
15
+ if (typeof data !== "undefined") {
16
+ this.update(data);
17
+ }
18
+ }
19
+ /**
20
+ * Get the checksum of the data, in big integer.
21
+ * @returns {bigint}
22
+ */
23
+ hash() {
24
+ if (this.#hash === null) {
25
+ this.#hash = (this.#b % 65521n) * 65536n + this.#a % 65521n;
26
+ }
27
+ return this.#hash;
28
+ }
29
+ /**
30
+ * Get the checksum of the data, in Base16.
31
+ * @returns {string}
32
+ */
33
+ hashBase16() {
34
+ return this.hashNumber().toString(16).toUpperCase();
35
+ }
36
+ /**
37
+ * Get the checksum of the data, in Base32Hex ({@link https://datatracker.ietf.org/doc/html/rfc4648#section-7 RFC 4648 §7}).
38
+ * @returns {string}
39
+ */
40
+ hashBase32Hex() {
41
+ return this.hashNumber().toString(32).toUpperCase();
42
+ }
43
+ /**
44
+ * Get the checksum of the data, in Base36.
45
+ * @returns {string}
46
+ */
47
+ hashBase36() {
48
+ return this.hashNumber().toString(36).toUpperCase();
49
+ }
50
+ /**
51
+ * Get the checksum of the data, in hex/hexadecimal without padding.
52
+ * @returns {string}
53
+ */
54
+ hashHex() {
55
+ return this.hashBase16();
56
+ }
57
+ /**
58
+ * Get the checksum of the data, in hex/hexadecimal with padding.
59
+ * @returns {string}
60
+ */
61
+ hashHexPadding() {
62
+ return this.hashHex().padStart(8, "0");
63
+ }
64
+ /**
65
+ * Get the checksum of the data, in number.
66
+ * @returns {number}
67
+ */
68
+ hashNumber() {
69
+ return Number(this.hash());
70
+ }
71
+ /**
72
+ * Append data.
73
+ * @param {Adler32AcceptDataType} data Data.
74
+ * @returns {this}
75
+ */
76
+ update(data) {
77
+ this.#hash = null;
78
+ for (const byte of new Uint32Array((typeof data === "string") ? new TextEncoder().encode(data) : data)) {
79
+ this.#a += BigInt(byte);
80
+ this.#b += this.#a;
81
+ }
82
+ return this;
83
+ }
84
+ /**
85
+ * Initialize from file, asynchronously.
86
+ * @param {string | URL} filePath Path of the file.
87
+ * @returns {Promise<Adler32>}
88
+ */
89
+ static async fromFile(filePath) {
90
+ return new Adler32(await dntShim.Deno.readFile(filePath));
91
+ }
92
+ /**
93
+ * Initialize from file, synchronously.
94
+ * @param {string | URL} filePath Path of the file.
95
+ * @returns {Adler32}
96
+ */
97
+ static fromFileSync(filePath) {
98
+ return new Adler32(dntShim.Deno.readFileSync(filePath));
99
+ }
100
+ }
101
+ export default Adler32;
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@hugoalh/adler32",
3
+ "version": "0.1.0",
4
+ "description": "A CLI and module to get the checksum of the data with algorithm Adler32.",
5
+ "keywords": [
6
+ "adler32"
7
+ ],
8
+ "homepage": "https://github.com/hugoalh/adler32-es#readme",
9
+ "bugs": {
10
+ "url": "https://github.com/hugoalh/adler32-es/issues"
11
+ },
12
+ "license": "MIT",
13
+ "author": "hugoalh",
14
+ "type": "module",
15
+ "bin": {
16
+ "adler32": "./cli.js"
17
+ },
18
+ "main": "./mod.js",
19
+ "module": "./mod.js",
20
+ "exports": {
21
+ ".": {
22
+ "import": {
23
+ "types": "./mod.d.ts",
24
+ "default": "./mod.js"
25
+ }
26
+ }
27
+ },
28
+ "types": "./mod.d.ts",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/hugoalh/adler32-es.git"
32
+ },
33
+ "scripts": {},
34
+ "dependencies": {
35
+ "@deno/shim-deno": "~0.18.0",
36
+ "@deno/shim-prompts": "~0.1.0",
37
+ "@deno/shim-timers": "~0.1.0"
38
+ },
39
+ "devDependencies": {
40
+ "@types/node": "^20.9.0"
41
+ },
42
+ "engines": {
43
+ "node": ">=16.13.0"
44
+ },
45
+ "private": false,
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "_generatedBy": "dnt@dev"
50
+ }