Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.DS_Store
.idea
**/node_modules
1 change: 1 addition & 0 deletions libUUID/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
nodejs 22.12.0
10 changes: 10 additions & 0 deletions libUUID/0.0.1/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
declare class libUUID {
private static base64Chars;
private static base;
private static previousTime;
private static counter;
private static toBase64;
private static generateRandomBase64;
static generateUUID(): string;
static generateRowID(): string;
}
57 changes: 57 additions & 0 deletions libUUID/0.0.1/libUUID.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// libUUID v0.0.1 by GUD Team | Tired of copying and pasting a UUID function over and over? Me too. This script provides a couple of functions to generate UUIDs.
class libUUID {
static base64Chars = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
static base = 64;
static previousTime = 0;
static counter = new Array(12).fill(0);
static toBase64(num, length) {
let result = "";
for (let i = 0; i < length; i++) {
result = this.base64Chars[num % this.base] + result;
num = Math.floor(num / this.base);
}
return result;
}
;
static generateRandomBase64(length) {
let result = "";
for (let i = 0; i < length; i++) {
result += this.base64Chars[Math.floor(Math.random() * this.base)];
}
return result;
}
;
static generateUUID() {
const currentTime = Date.now();
const timeBase64 = this.toBase64(currentTime, 8);
let randomOrCounterBase64 = "";
if (currentTime === this.previousTime) {
// Increment the counter
for (let i = this.counter.length - 1; i >= 0; i--) {
this.counter[i]++;
if (this.counter[i] < this.base) {
break;
}
else {
this.counter[i] = 0;
}
}
randomOrCounterBase64 = this.counter.map(index => this.base64Chars[index]).join("");
}
else {
// Generate new random values and initialize counter with random starting values
randomOrCounterBase64 = this.generateRandomBase64(12);
// Initialize counter with random values instead of zeros to avoid hyphen-heavy sequences
for (let i = 0; i < this.counter.length; i++) {
this.counter[i] = Math.floor(Math.random() * this.base);
}
this.previousTime = currentTime;
}
return timeBase64 + randomOrCounterBase64;
}
;
static generateRowID() {
return this.generateUUID().replace(/_/g, "Z");
}
;
}
22 changes: 22 additions & 0 deletions libUUID/eslint.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { defineConfig } from "eslint/config"; // While not strictly necessary, it's good practice.
import stylistic from "@stylistic/eslint-plugin";
import jslint from "@eslint/js";
import tslint from "typescript-eslint";

export default defineConfig(
{
ignores: ["**/[0-9]*.[0-9]*.[0-9]*/", "*.d.ts", "dist/**", "build/**", "node_modules/**"],
},
jslint.configs.recommended,
...tslint.configs.recommended,
{
plugins: {
"@stylistic": stylistic,
},
rules: {
"@stylistic/quotes": ["error", "double"],
"@stylistic/semi": ["error", "always"],
"@stylistic/indent": ["error", 2],
},
},
);
Loading
Loading