Skip to content
Open
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
10 changes: 0 additions & 10 deletions libUUID/0.0.1/index.d.ts

This file was deleted.

63 changes: 34 additions & 29 deletions libUUID/0.0.1/libUUID.js
Original file line number Diff line number Diff line change
@@ -1,57 +1,62 @@
// 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) {
var libUUID = (function () {
'use strict';

const base64Chars = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
const base = 64;
let previousTime = 0;
const counter = new Array(12).fill(0);
function 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);
result = base64Chars[num % base] + result;
num = Math.floor(num / base);
}
return result;
}
;
static generateRandomBase64(length) {
function generateRandomBase64(length) {
let result = "";
for (let i = 0; i < length; i++) {
result += this.base64Chars[Math.floor(Math.random() * this.base)];
result += base64Chars[Math.floor(Math.random() * base)];
}
return result;
}
;
static generateUUID() {
function generateUUID() {
const currentTime = Date.now();
const timeBase64 = this.toBase64(currentTime, 8);
const timeBase64 = toBase64(currentTime, 8);
let randomOrCounterBase64 = "";
if (currentTime === this.previousTime) {
if (currentTime === previousTime) {
// Increment the counter
for (let i = this.counter.length - 1; i >= 0; i--) {
this.counter[i]++;
if (this.counter[i] < this.base) {
for (let i = counter.length - 1; i >= 0; i--) {
counter[i]++;
if (counter[i] < base) {
break;
}
else {
this.counter[i] = 0;
counter[i] = 0;
}
}
randomOrCounterBase64 = this.counter.map(index => this.base64Chars[index]).join("");
randomOrCounterBase64 = counter.map(index => base64Chars[index]).join("");
}
else {
// Generate new random values and initialize counter with random starting values
randomOrCounterBase64 = this.generateRandomBase64(12);
randomOrCounterBase64 = 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);
for (let i = 0; i < counter.length; i++) {
counter[i] = Math.floor(Math.random() * base);
}
this.previousTime = currentTime;
previousTime = currentTime;
}
return timeBase64 + randomOrCounterBase64;
}
;
static generateRowID() {
return this.generateUUID().replace(/_/g, "Z");
function generateRowID() {
return generateUUID().replace(/_/g, "Z");
}
;
}
var index = {
generateUUID,
generateRowID,
};

return index;

})();
2 changes: 1 addition & 1 deletion libUUID/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "1.0.0",
"type": "module",
"main": "src/index.ts",
"types": "0.0.1/index.d.ts",
"types": "src/index.d.ts",
"scripts": {
"lint": "eslint",
"lint:fix": "eslint --fix",
Expand Down
6 changes: 2 additions & 4 deletions libUUID/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@ export default defineConfig({

output: {
file: `${json.version}/${json.name}.js`,
format: "iife",
name: json.name,
sourcemap: false,
banner: `// ${json.name} v${json.version} by ${json.authors} | ${json.description}`,
},

plugins: [
del({ targets: `${json.version}/*`, runOnce: true }),
typescript({
declaration: true,
declarationDir: `${json.version}`,
}),
typescript({}),
]
});
4 changes: 4 additions & 0 deletions libUUID/src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare namespace UUID {
function generateUUID(): string;
function generateRowID(): string;
}
98 changes: 50 additions & 48 deletions libUUID/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,57 +1,59 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
class libUUID {
private static base64Chars = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
private static base = 64;
private static previousTime = 0;
private static counter = new Array(12).fill(0);
const base64Chars = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
const base = 64;
let previousTime = 0;
const counter = new Array(12).fill(0);

private static toBase64(num: number, length: number) {
let result = "";
for (let i = 0; i < length; i++) {
result = this.base64Chars[num % this.base] + result;
num = Math.floor(num / this.base);
}
return result;
};
function toBase64(num: number, length: number): string {
let result = "";
for (let i = 0; i < length; i++) {
result = base64Chars[num % base] + result;
num = Math.floor(num / base);
}
return result;
}

private static generateRandomBase64(length: number) {
let result = "";
for (let i = 0; i < length; i++) {
result += this.base64Chars[Math.floor(Math.random() * this.base)];
}
return result;
};
function generateRandomBase64(length: number): string {
let result = "";
for (let i = 0; i < length; i++) {
result += base64Chars[Math.floor(Math.random() * base)];
}
return result;
}

public static generateUUID(): string {
const currentTime = Date.now();
const timeBase64 = this.toBase64(currentTime, 8);
let randomOrCounterBase64 = "";
function generateUUID(): string {
const currentTime = Date.now();
const timeBase64 = 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);
if (currentTime === previousTime) {
// Increment the counter
for (let i = counter.length - 1; i >= 0; i--) {
counter[i]++;
if (counter[i] < base) {
break;
} else {
counter[i] = 0;
}
this.previousTime = currentTime;
}
randomOrCounterBase64 = counter.map(index => base64Chars[index]).join("");
} else {
// Generate new random values and initialize counter with random starting values
randomOrCounterBase64 = generateRandomBase64(12);
// Initialize counter with random values instead of zeros to avoid hyphen-heavy sequences
for (let i = 0; i < counter.length; i++) {
counter[i] = Math.floor(Math.random() * base);
}
previousTime = currentTime;
}

return timeBase64 + randomOrCounterBase64;
}

return timeBase64 + randomOrCounterBase64;
};
function generateRowID(): string {
return generateUUID().replace(/_/g, "Z");
}

public static generateRowID(): string {
return this.generateUUID().replace(/_/g, "Z");
};
export default {
generateUUID,
generateRowID,
};
4 changes: 2 additions & 2 deletions libUUID/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"moduleResolution": "bundler",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"sourceMap": false
},
"include": ["src"],
"exclude": ["node_modules", "dist", "**/*.test.ts"]
"exclude": ["node_modules"]
}
Loading