@yiuayiu/functions 0.0.1 → 0.0.3

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.
@@ -1,4 +1,2 @@
1
- /// <reference types="node" />
2
- import crypto from "crypto";
3
- export declare function sha1(string: crypto.BinaryLike): string;
4
- export declare function md5(string: crypto.BinaryLike): string;
1
+ export declare function sha1(string: string): Promise<string>;
2
+ export declare function md5(string: string): Promise<string>;
package/dist/functions.js CHANGED
@@ -1,7 +1,14 @@
1
- import crypto from "crypto";
2
- export function sha1(string) {
3
- return crypto.createHash("sha1").update(string).digest("hex");
1
+ const { subtle } = globalThis.crypto;
2
+ export async function sha1(string) {
3
+ const encoder = new TextEncoder();
4
+ const data = encoder.encode(string);
5
+ const hashBuffer = await subtle.digest("SHA-1", data);
6
+ return Array.from(new Uint8Array(hashBuffer))
7
+ .map((b) => b.toString(16).padStart(2, "0"))
8
+ .join("");
4
9
  }
5
- export function md5(string) {
6
- return crypto.createHash("md5").update(string).digest("hex");
10
+ export async function md5(string) {
11
+ // Web Crypto API doesn't support MD5 directly as it's considered insecure
12
+ // This would require a separate implementation or a library
13
+ throw new Error("MD5 is not supported by Web Crypto API due to security concerns");
7
14
  }
package/package.json CHANGED
@@ -1,11 +1,9 @@
1
1
  {
2
2
  "name": "@yiuayiu/functions",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "",
5
5
  "main": "dist/functions.js",
6
- "scripts": {
7
- "test": "echo \"Error: no test specified\" && exit 1"
8
- },
6
+ "type": "module",
9
7
  "keywords": [],
10
8
  "author": "AYiU <npm@ayiu.net>",
11
9
  "license": "ISC",
@@ -13,6 +11,10 @@
13
11
  "access": "public"
14
12
  },
15
13
  "devDependencies": {
16
- "@types/node": "^18.6.5"
14
+ "@types/node": "^22.15.23",
15
+ "vitest": "^3.1.4"
16
+ },
17
+ "scripts": {
18
+ "test": "vitest"
17
19
  }
18
- }
20
+ }
package/functions.ts DELETED
@@ -1,9 +0,0 @@
1
- import crypto from "crypto";
2
-
3
- export function sha1(string: crypto.BinaryLike) {
4
- return crypto.createHash("sha1").update(string).digest("hex");
5
- }
6
-
7
- export function md5(string: crypto.BinaryLike) {
8
- return crypto.createHash("md5").update(string).digest("hex");
9
- }
package/tsconfig.json DELETED
@@ -1,6 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./dist",
5
- }
6
- }