-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move the build system to Deno, export both to npm and deno/x
- Loading branch information
1 parent
6ebc3df
commit de3ff95
Showing
16 changed files
with
162 additions
and
9,911 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,2 @@ | ||
node_modules | ||
coverage | ||
.nyc_output | ||
.DS_Store | ||
*.log | ||
.vscode | ||
.idea | ||
dist | ||
compiled | ||
.awcache | ||
.rpt2_cache | ||
docs | ||
# NPM build directory | ||
npm |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"deno.enable": true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import nhash from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
// Create a uuid | ||
// RFC 4122 Version 4 compliant pattern | ||
const from = (h: () => string): string => | ||
"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx" | ||
.replace(/x/g, h) | ||
.replace(/y/g, () => | ||
Math.floor((parseInt(h(), 16) / 16) * 4 + 8).toString(16) | ||
); | ||
|
||
// Uuid regex | ||
const pattern = | ||
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i; | ||
|
||
// Check if it is a uuid | ||
export const check = (uuid: string): boolean => pattern.test(uuid); | ||
|
||
// Create a random uuid | ||
export const create = (): string => | ||
from(() => Math.floor(Math.random() * 16).toString(16)); | ||
|
||
// Create a uuid hash | ||
export const hash = (s: string): string => { | ||
// Create a hash | ||
const h = nhash(s, { size: 128 }).hex(); | ||
|
||
// Return the hash | ||
let i = 0; | ||
return from(() => h[i++]); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { | ||
assertEquals, | ||
assertNotEquals, | ||
} from "https://deno.land/[email protected]/testing/asserts.ts"; | ||
import { check, create, hash } from "./mod.ts"; | ||
|
||
// Check | ||
Deno.test("Check", async (t) => { | ||
// Valid UUID | ||
const vuuid = "01234567-abcd-4abc-8def-0123456789ab"; | ||
const iuuid = "01234567-abcd-4abc-4def-0123456789ab"; | ||
|
||
// Valid UUID should pass the check | ||
await t.step("Valid UUID should pass the check", () => { | ||
// Check the valid uuid | ||
const v = check(vuuid); | ||
|
||
// Expect rules | ||
assertEquals(v, true); | ||
}); | ||
|
||
// Invaid UUID should not pass the check | ||
await t.step("Inalid UUID should not pass the check", () => { | ||
// Check invalid uuid | ||
const v = check(iuuid); | ||
|
||
// Expect rules | ||
assertEquals(v, false); | ||
}); | ||
}); | ||
|
||
// Random | ||
Deno.test("Random", async (t) => { | ||
// UUID should be between a valid UUID | ||
await t.step("Random UUID should be a valid UUID", () => { | ||
// Check random uuid | ||
const u = create(); | ||
const v = check(u); | ||
|
||
// Expect rules | ||
assertEquals(v, true); | ||
}); | ||
|
||
// Two random UUIDs should be different | ||
await t.step("Two random UUIDs should be different", () => { | ||
// Check random uuids | ||
const u1 = create(); | ||
const u2 = create(); | ||
|
||
// Expect rules | ||
assertNotEquals(u1, u2); | ||
}); | ||
}); | ||
|
||
// Hash | ||
Deno.test("Hash", async (t) => { | ||
// Hashed UUID should be between a valid UUID | ||
await t.step("Hashed UUID should be a valid UUID", () => { | ||
// Get a hashed uuid | ||
const u = hash("Hash"); | ||
const v = check(u); | ||
|
||
// Expect rules | ||
assertEquals(v, true); | ||
}); | ||
|
||
// Same hashed input should generate same UUID | ||
await t.step("Same hashed input should generate same UUID", () => { | ||
// Get hashed uuids | ||
const u1 = hash("Hash"); | ||
const u2 = hash("Hash"); | ||
|
||
// Expect rules | ||
assertEquals(u1, u2); | ||
}); | ||
|
||
// Different hashed input should generate different UUIDs | ||
await t.step("Different hashed input should generate different UUIDs", () => { | ||
// Get hashed uuids | ||
const u1 = hash("Hash1"); | ||
const u2 = hash("Hash2"); | ||
|
||
// Expect rules | ||
assertNotEquals(u1, u2); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { build, emptyDir } from "https://deno.land/x/[email protected]/mod.ts"; | ||
|
||
await emptyDir("./npm"); | ||
|
||
await build({ | ||
entryPoints: ["./mod.ts"], | ||
outDir: "./npm", | ||
shims: { | ||
// see JS docs for overview and more options | ||
deno: { | ||
test: "dev", | ||
}, | ||
}, | ||
compilerOptions: { | ||
lib: ["es2021", "dom"], | ||
}, | ||
package: { | ||
// package.json properties | ||
name: "huid", | ||
version: Deno.args[0], | ||
description: "Utility for generating, checking or hashing UUIDs.", | ||
license: "MIT", | ||
keywords: ["uuid", "guid", "hash", "hashing"], | ||
author: "Claudiu Andrei <[email protected]>", | ||
repository: { | ||
type: "git", | ||
url: "git+https://github.com/claudiuandrei/huid.git", | ||
}, | ||
bugs: { | ||
url: "https://github.com/claudiuandrei/huid/issues", | ||
}, | ||
engines: { | ||
node: ">=11.0.0", | ||
}, | ||
}, | ||
}); | ||
|
||
// post build steps | ||
Deno.copyFileSync("LICENSE", "npm/LICENSE"); | ||
Deno.copyFileSync("README.md", "npm/README.md"); |
Oops, something went wrong.