Skip to content

Commit

Permalink
refactor: remove uuid dependency and replace with randomString for un…
Browse files Browse the repository at this point in the history
…ique key generation
  • Loading branch information
gabriel-logan committed Jan 20, 2025
1 parent 120d68e commit 3f14769
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 30 deletions.
Binary file modified .yarn/install-state.gz
Binary file not shown.
6 changes: 1 addition & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"devDependencies": {
"@types/jest": "^29.5.14",
"@types/node": "^22.10.7",
"@types/uuid": "^10.0.0",
"azure-translator-code": "^1.1.6",
"dotenv": "^16.4.7",
"eslint": "^8",
Expand All @@ -62,8 +61,5 @@
"ts-node": "^10.9.2",
"typescript": "^5.7.3"
},
"packageManager": "[email protected]",
"dependencies": {
"uuid": "^11"
}
"packageManager": "[email protected]"
}
3 changes: 3 additions & 0 deletions src/randomString/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function randomString() {
return (Math.random() * 3).toString(36);
}
5 changes: 2 additions & 3 deletions src/translate/translateText.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { v4 as uuidv4 } from "uuid";

import randomString from "../randomString";
import type { TranslationType } from "../types";

interface Translation {
Expand Down Expand Up @@ -54,7 +53,7 @@ export default async function translateText(
"Ocp-Apim-Subscription-Key": key,
"Ocp-Apim-Subscription-Region": location,
"Content-type": "application/json",
"X-ClientTraceId": uuidv4(),
"X-ClientTraceId": randomString(),
};

const response = await fetch(url, {
Expand Down
13 changes: 13 additions & 0 deletions tests/randomString/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import randomString from "../../src/randomString";

describe("randomString", () => {
it("should return a random string", () => {
const generateRandomString = randomString();

expect(typeof generateRandomString).toBe("string");
expect(generateRandomString).not.toBeNull();
expect(generateRandomString).not.toBeUndefined();
expect(generateRandomString).not.toBe("");
expect(generateRandomString.trim()).not.toBe("");
});
});
2 changes: 0 additions & 2 deletions tests/updateTranslationMulti/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
import { v4 as uuidv4 } from "uuid";

import { updateTranslationsMulti, type TranslationType } from "../../src";

Expand Down Expand Up @@ -53,7 +52,6 @@ describe("updateTranslationsMulti", () => {
],
} as Response);

key = uuidv4(); // Gera uma chave única para cada teste
jsonFile = {
[key]: "Welcome",
};
Expand Down
2 changes: 0 additions & 2 deletions tests/updateTranslationUnic/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
import { v4 as uuidv4 } from "uuid";

import { updateTranslationsUnic, type TranslationType } from "../../src";

Expand Down Expand Up @@ -53,7 +52,6 @@ describe("updateTranslationsUnic", () => {
],
} as Response);

key = uuidv4(); // Gera uma chave única para cada teste
jsonFile = {
[key]: "Welcome",
};
Expand Down
18 changes: 0 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1063,13 +1063,6 @@ __metadata:
languageName: node
linkType: hard

"@types/uuid@npm:^10.0.0":
version: 10.0.0
resolution: "@types/uuid@npm:10.0.0"
checksum: 10c0/9a1404bf287164481cb9b97f6bb638f78f955be57c40c6513b7655160beb29df6f84c915aaf4089a1559c216557dc4d2f79b48d978742d3ae10b937420ddac60
languageName: node
linkType: hard

"@types/yargs-parser@npm:*":
version: 21.0.3
resolution: "@types/yargs-parser@npm:21.0.3"
Expand Down Expand Up @@ -1540,7 +1533,6 @@ __metadata:
dependencies:
"@types/jest": "npm:^29.5.14"
"@types/node": "npm:^22.10.7"
"@types/uuid": "npm:^10.0.0"
azure-translator-code: "npm:^1.1.6"
dotenv: "npm:^16.4.7"
eslint: "npm:^8"
Expand All @@ -1551,7 +1543,6 @@ __metadata:
ts-jest: "npm:^29.2.5"
ts-node: "npm:^10.9.2"
typescript: "npm:^5.7.3"
uuid: "npm:^11"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -6119,15 +6110,6 @@ __metadata:
languageName: node
linkType: hard

"uuid@npm:^11":
version: 11.0.5
resolution: "uuid@npm:11.0.5"
bin:
uuid: dist/esm/bin/uuid
checksum: 10c0/6f59f0c605e02c14515401084ca124b9cb462b4dcac866916a49862bcf831874508a308588c23a7718269226ad11a92da29b39d761ad2b86e736623e3a33b6e7
languageName: node
linkType: hard

"v8-compile-cache-lib@npm:^3.0.1":
version: 3.0.1
resolution: "v8-compile-cache-lib@npm:3.0.1"
Expand Down

0 comments on commit 3f14769

Please sign in to comment.