Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 8
Feat/uuidv5 generation#61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,44 @@ | ||
| { | ||
| "name": "w3id", | ||
| "version": "1.0.0", | ||
| "description": "", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1", | ||
| "dev": "tsc --watch", | ||
| "format": "npx @biomejs/biome format --write ./src", | ||
| "check-format": "npx @biomejs/biome format ./src", | ||
| "lint": "npx @biomejs/biome lint --write ./src", | ||
| "check-lint": "npx @biomejs/biome lint ./src", | ||
| "check": "npx @biomejs/biome check ./src", | ||
| "check-types": "tsc --noEmit", | ||
| "build": "npm run build:node && npm run build:browser", | ||
| "build:node": "tsc -p tsconfig.node.json", | ||
| "build:browser": "tsc -p tsconfig.browser.json", | ||
| "postinstall": "npm run build" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "dependencies": { | ||
| "@biomejs/biome": "^1.9.4", | ||
| "uuid": "^11.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "typescript": "^5.8.2" | ||
| }, | ||
| "main": "./dist/node/index.js", | ||
| "module": "./dist/browser/index.js", | ||
| "types": "./dist/types/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "require": "./dist/node/index.js", | ||
| "import": "./dist/browser/index.js", | ||
| "types": "./dist/types/index.d.ts" | ||
| }, | ||
| "./package.json": "./package.json" | ||
| }, | ||
| "files": ["dist/**/*"] | ||
| "name": "w3id", | ||
| "version": "1.0.0", | ||
| "description": "", | ||
| "scripts": { | ||
| "test": "vitest", | ||
| "dev": "tsc --watch", | ||
| "check-format": "prettier --check \"src/**/*.ts\"", | ||
| "format": "npx @biomejs/biome format --write ./src", | ||
| "lint": "npx @biomejs/biome lint --write ./src", | ||
| "check": "npx @biomejs/biome check --write ./src", | ||
| "check-types": "tsc --noEmit", | ||
| "build": "npm run build:node && npm run build:browser", | ||
| "build:node": "tsc -p tsconfig.node.json", | ||
| "build:browser": "tsc -p tsconfig.browser.json", | ||
| "postinstall": "npm run build" | ||
| }, | ||
| "keywords": [], | ||
| "author": "", | ||
| "license": "ISC", | ||
| "dependencies": { | ||
| "uuid": "^11.1.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@ngneat/falso": "^7.3.0", | ||
| "@types/node": "^22.13.10", | ||
| "typescript": "^5.8.2", | ||
| "vitest": "^3.0.9" | ||
| }, | ||
| "main": "./dist/node/index.js", | ||
| "module": "./dist/browser/index.js", | ||
| "types": "./dist/types/index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "require": "./dist/node/index.js", | ||
| "import": "./dist/browser/index.js", | ||
| "types": "./dist/types/index.d.ts" | ||
| }, | ||
| "./package.json": "./package.json" | ||
| }, | ||
| "files": [ | ||
| "dist/**/*" | ||
| ] | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { v4 as uuidv4, v5 as uuidv5 } from "uuid"; | ||
| /** | ||
| * Generates a UUIDv5 taking namespace from a random UUIDv4 and taking `name` | ||
| * part as entropy from the creator of the identifier | ||
| * | ||
| * @param {String} entropy | ||
| * @param {String} namespace - uuid namespace | ||
| * @returns string | ||
| */ | ||
| export function generateUuid( | ||
| entropy: string, | ||
| namespace: string = uuidv4(), | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think having this default behavior would just lead to mistakes | ||
| ): string { | ||
| return uuidv5(entropy, namespace); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { generateUuid } from "../../src/utils/uuid"; | ||
| import falso from "@ngneat/falso"; | ||
| import { describe, test, expect } from "vitest"; | ||
| describe("UUIDv5 Generation", () => { | ||
| test("Create UUID", () => { | ||
| const id = generateUuid(falso.randText()); | ||
| expect(id).toBeDefined(); | ||
| }); | ||
| test("UUID is deterministic", () => { | ||
| const namespace = falso.randUuid(); | ||
| const entropy = falso.randText(); | ||
| const id = generateUuid(entropy, namespace); | ||
| const id2 = generateUuid(entropy, namespace); | ||
| expect(id).toEqual(id2); | ||
| }); | ||
| }); |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
function name makes it seems like the function has a broad scope, but doc above mentions just v5, its just a nitpick but i think this can be named a little better