Skip to content

Commit 3bce97e

Browse files
author
Nic Bradley
committed
Updating
1 parent 412dfa6 commit 3bce97e

File tree

7 files changed

+93
-94
lines changed

7 files changed

+93
-94
lines changed

libUUID/0.0.1/index.d.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

libUUID/0.0.1/libUUID.js

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,62 @@
11
// 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.
2-
class libUUID {
3-
static base64Chars = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
4-
static base = 64;
5-
static previousTime = 0;
6-
static counter = new Array(12).fill(0);
7-
static toBase64(num, length) {
2+
var libUUID = (function () {
3+
'use strict';
4+
5+
const base64Chars = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
6+
const base = 64;
7+
let previousTime = 0;
8+
const counter = new Array(12).fill(0);
9+
function toBase64(num, length) {
810
let result = "";
911
for (let i = 0; i < length; i++) {
10-
result = this.base64Chars[num % this.base] + result;
11-
num = Math.floor(num / this.base);
12+
result = base64Chars[num % base] + result;
13+
num = Math.floor(num / base);
1214
}
1315
return result;
1416
}
15-
;
16-
static generateRandomBase64(length) {
17+
function generateRandomBase64(length) {
1718
let result = "";
1819
for (let i = 0; i < length; i++) {
19-
result += this.base64Chars[Math.floor(Math.random() * this.base)];
20+
result += base64Chars[Math.floor(Math.random() * base)];
2021
}
2122
return result;
2223
}
23-
;
24-
static generateUUID() {
24+
function generateUUID() {
2525
const currentTime = Date.now();
26-
const timeBase64 = this.toBase64(currentTime, 8);
26+
const timeBase64 = toBase64(currentTime, 8);
2727
let randomOrCounterBase64 = "";
28-
if (currentTime === this.previousTime) {
28+
if (currentTime === previousTime) {
2929
// Increment the counter
30-
for (let i = this.counter.length - 1; i >= 0; i--) {
31-
this.counter[i]++;
32-
if (this.counter[i] < this.base) {
30+
for (let i = counter.length - 1; i >= 0; i--) {
31+
counter[i]++;
32+
if (counter[i] < base) {
3333
break;
3434
}
3535
else {
36-
this.counter[i] = 0;
36+
counter[i] = 0;
3737
}
3838
}
39-
randomOrCounterBase64 = this.counter.map(index => this.base64Chars[index]).join("");
39+
randomOrCounterBase64 = counter.map(index => base64Chars[index]).join("");
4040
}
4141
else {
4242
// Generate new random values and initialize counter with random starting values
43-
randomOrCounterBase64 = this.generateRandomBase64(12);
43+
randomOrCounterBase64 = generateRandomBase64(12);
4444
// Initialize counter with random values instead of zeros to avoid hyphen-heavy sequences
45-
for (let i = 0; i < this.counter.length; i++) {
46-
this.counter[i] = Math.floor(Math.random() * this.base);
45+
for (let i = 0; i < counter.length; i++) {
46+
counter[i] = Math.floor(Math.random() * base);
4747
}
48-
this.previousTime = currentTime;
48+
previousTime = currentTime;
4949
}
5050
return timeBase64 + randomOrCounterBase64;
5151
}
52-
;
53-
static generateRowID() {
54-
return this.generateUUID().replace(/_/g, "Z");
52+
function generateRowID() {
53+
return generateUUID().replace(/_/g, "Z");
5554
}
56-
;
57-
}
55+
var index = {
56+
generateUUID,
57+
generateRowID,
58+
};
59+
60+
return index;
61+
62+
})();

libUUID/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "1.0.0",
44
"type": "module",
55
"main": "src/index.ts",
6-
"types": "0.0.1/index.d.ts",
6+
"types": "src/index.d.ts",
77
"scripts": {
88
"lint": "eslint",
99
"lint:fix": "eslint --fix",

libUUID/rollup.config.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,14 @@ export default defineConfig({
99

1010
output: {
1111
file: `${json.version}/${json.name}.js`,
12+
format: "iife",
1213
name: json.name,
1314
sourcemap: false,
1415
banner: `// ${json.name} v${json.version} by ${json.authors} | ${json.description}`,
1516
},
1617

1718
plugins: [
1819
del({ targets: `${json.version}/*`, runOnce: true }),
19-
typescript({
20-
declaration: true,
21-
declarationDir: `${json.version}`,
22-
}),
20+
typescript({}),
2321
]
2422
});

libUUID/src/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
declare namespace UUID {
2+
function generateUUID(): string;
3+
function generateRowID(): string;
4+
}

libUUID/src/index.ts

Lines changed: 50 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,59 @@
1-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2-
class libUUID {
3-
private static base64Chars = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
4-
private static base = 64;
5-
private static previousTime = 0;
6-
private static counter = new Array(12).fill(0);
1+
const base64Chars = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
2+
const base = 64;
3+
let previousTime = 0;
4+
const counter = new Array(12).fill(0);
75

8-
private static toBase64(num: number, length: number) {
9-
let result = "";
10-
for (let i = 0; i < length; i++) {
11-
result = this.base64Chars[num % this.base] + result;
12-
num = Math.floor(num / this.base);
13-
}
14-
return result;
15-
};
6+
function toBase64(num: number, length: number): string {
7+
let result = "";
8+
for (let i = 0; i < length; i++) {
9+
result = base64Chars[num % base] + result;
10+
num = Math.floor(num / base);
11+
}
12+
return result;
13+
}
1614

17-
private static generateRandomBase64(length: number) {
18-
let result = "";
19-
for (let i = 0; i < length; i++) {
20-
result += this.base64Chars[Math.floor(Math.random() * this.base)];
21-
}
22-
return result;
23-
};
15+
function generateRandomBase64(length: number): string {
16+
let result = "";
17+
for (let i = 0; i < length; i++) {
18+
result += base64Chars[Math.floor(Math.random() * base)];
19+
}
20+
return result;
21+
}
2422

25-
public static generateUUID(): string {
26-
const currentTime = Date.now();
27-
const timeBase64 = this.toBase64(currentTime, 8);
28-
let randomOrCounterBase64 = "";
23+
function generateUUID(): string {
24+
const currentTime = Date.now();
25+
const timeBase64 = toBase64(currentTime, 8);
26+
let randomOrCounterBase64 = "";
2927

30-
if (currentTime === this.previousTime) {
31-
// Increment the counter
32-
for (let i = this.counter.length - 1; i >= 0; i--) {
33-
this.counter[i]++;
34-
if (this.counter[i] < this.base) {
35-
break;
36-
} else {
37-
this.counter[i] = 0;
38-
}
39-
}
40-
randomOrCounterBase64 = this.counter.map(index => this.base64Chars[index]).join("");
41-
} else {
42-
// Generate new random values and initialize counter with random starting values
43-
randomOrCounterBase64 = this.generateRandomBase64(12);
44-
// Initialize counter with random values instead of zeros to avoid hyphen-heavy sequences
45-
for (let i = 0; i < this.counter.length; i++) {
46-
this.counter[i] = Math.floor(Math.random() * this.base);
28+
if (currentTime === previousTime) {
29+
// Increment the counter
30+
for (let i = counter.length - 1; i >= 0; i--) {
31+
counter[i]++;
32+
if (counter[i] < base) {
33+
break;
34+
} else {
35+
counter[i] = 0;
4736
}
48-
this.previousTime = currentTime;
4937
}
38+
randomOrCounterBase64 = counter.map(index => base64Chars[index]).join("");
39+
} else {
40+
// Generate new random values and initialize counter with random starting values
41+
randomOrCounterBase64 = generateRandomBase64(12);
42+
// Initialize counter with random values instead of zeros to avoid hyphen-heavy sequences
43+
for (let i = 0; i < counter.length; i++) {
44+
counter[i] = Math.floor(Math.random() * base);
45+
}
46+
previousTime = currentTime;
47+
}
48+
49+
return timeBase64 + randomOrCounterBase64;
50+
}
5051

51-
return timeBase64 + randomOrCounterBase64;
52-
};
52+
function generateRowID(): string {
53+
return generateUUID().replace(/_/g, "Z");
54+
}
5355

54-
public static generateRowID(): string {
55-
return this.generateUUID().replace(/_/g, "Z");
56-
};
56+
export default {
57+
generateUUID,
58+
generateRowID,
5759
};

libUUID/tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
"compilerOptions": {
44
"target": "ESNext",
55
"module": "ESNext",
6-
"moduleResolution": "node",
6+
"moduleResolution": "bundler",
77
"strict": true,
88
"esModuleInterop": true,
99
"skipLibCheck": true,
1010
"sourceMap": false
1111
},
1212
"include": ["src"],
13-
"exclude": ["node_modules", "dist", "**/*.test.ts"]
13+
"exclude": ["node_modules"]
1414
}

0 commit comments

Comments
 (0)