@yiuayiu/functions 0.1.0 → 0.1.2
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/dist/functions.d.ts +4 -2
- package/dist/functions.js +11 -4
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +4 -1
package/dist/functions.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export declare function sha1(string: string): Promise<string>;
|
|
2
|
-
export declare function
|
|
1
|
+
export declare function sha1(string: string | Buffer): Promise<string>;
|
|
2
|
+
export declare function sha512(input: string | Buffer): Promise<string>;
|
|
3
|
+
export declare function digest(input: string | Buffer, algorithm: "SHA-1" | "SHA-512"): Promise<string>;
|
|
4
|
+
export declare function md5(_string: string): Promise<string>;
|
package/dist/functions.js
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
const { subtle } = globalThis.crypto;
|
|
2
2
|
export async function sha1(string) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
return digest(string, "SHA-1");
|
|
4
|
+
}
|
|
5
|
+
export async function sha512(input) {
|
|
6
|
+
return digest(input, "SHA-512");
|
|
7
|
+
}
|
|
8
|
+
export async function digest(input, algorithm) {
|
|
9
|
+
const inputData = typeof input === "string"
|
|
10
|
+
? new TextEncoder().encode(input)
|
|
11
|
+
: new Uint8Array(input);
|
|
12
|
+
const hashBuffer = await subtle.digest(algorithm, inputData);
|
|
6
13
|
return Array.from(new Uint8Array(hashBuffer))
|
|
7
14
|
.map((b) => b.toString(16).padStart(2, "0"))
|
|
8
15
|
.join("");
|
|
9
16
|
}
|
|
10
|
-
export async function md5(
|
|
17
|
+
export async function md5(_string) {
|
|
11
18
|
// Web Crypto API doesn't support MD5 directly as it's considered insecure
|
|
12
19
|
// This would require a separate implementation or a library
|
|
13
20
|
throw new Error("MD5 is not supported by Web Crypto API due to security concerns");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../src/functions.test.ts","../src/functions.ts"],"version":"5.9.3"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yiuayiu/functions",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/functions.js",
|
|
6
6
|
"type": "module",
|
|
@@ -12,9 +12,12 @@
|
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@types/node": "^25.1.0",
|
|
15
|
+
"typescript": "^5.9.3",
|
|
15
16
|
"vitest": "^4.0.18"
|
|
16
17
|
},
|
|
17
18
|
"scripts": {
|
|
19
|
+
"build": "tsc -b",
|
|
20
|
+
"dev": "tsc -b --watch",
|
|
18
21
|
"test": "vitest"
|
|
19
22
|
}
|
|
20
23
|
}
|