@yiuayiu/functions 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/dist/functions.d.ts +3 -1
- package/dist/functions.js +10 -1
- package/package.json +2 -1
package/dist/functions.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
1
|
export declare function sha1(string: string): Promise<string>;
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function sha512(str: string): Promise<string>;
|
|
3
|
+
export declare function hashToString(hashBuffer: ArrayBuffer): Promise<string>;
|
|
4
|
+
export declare function md5(_string: string): Promise<string>;
|
package/dist/functions.js
CHANGED
|
@@ -3,11 +3,20 @@ export async function sha1(string) {
|
|
|
3
3
|
const encoder = new TextEncoder();
|
|
4
4
|
const data = encoder.encode(string);
|
|
5
5
|
const hashBuffer = await subtle.digest("SHA-1", data);
|
|
6
|
+
return hashToString(hashBuffer);
|
|
7
|
+
}
|
|
8
|
+
export async function sha512(str) {
|
|
9
|
+
const encoder = new TextEncoder();
|
|
10
|
+
const data = encoder.encode(str);
|
|
11
|
+
const hashBuffer = await subtle.digest("SHA-512", data);
|
|
12
|
+
return hashToString(hashBuffer);
|
|
13
|
+
}
|
|
14
|
+
export async function hashToString(hashBuffer) {
|
|
6
15
|
return Array.from(new Uint8Array(hashBuffer))
|
|
7
16
|
.map((b) => b.toString(16).padStart(2, "0"))
|
|
8
17
|
.join("");
|
|
9
18
|
}
|
|
10
|
-
export async function md5(
|
|
19
|
+
export async function md5(_string) {
|
|
11
20
|
// Web Crypto API doesn't support MD5 directly as it's considered insecure
|
|
12
21
|
// This would require a separate implementation or a library
|
|
13
22
|
throw new Error("MD5 is not supported by Web Crypto API due to security concerns");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yiuayiu/functions",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/functions.js",
|
|
6
6
|
"type": "module",
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"vitest": "^4.0.18"
|
|
16
16
|
},
|
|
17
17
|
"scripts": {
|
|
18
|
+
"build": "tsc -b",
|
|
18
19
|
"test": "vitest"
|
|
19
20
|
}
|
|
20
21
|
}
|