diff --git a/libUUID/0.0.1/index.d.ts b/libUUID/0.0.1/index.d.ts deleted file mode 100644 index 72c7b0ba9..000000000 --- a/libUUID/0.0.1/index.d.ts +++ /dev/null @@ -1,10 +0,0 @@ -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; -} diff --git a/libUUID/0.0.1/libUUID.js b/libUUID/0.0.1/libUUID.js index 46f44e7e4..ea0a5d740 100644 --- a/libUUID/0.0.1/libUUID.js +++ b/libUUID/0.0.1/libUUID.js @@ -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; + +})(); diff --git a/libUUID/package.json b/libUUID/package.json index 4622ee026..934f32551 100644 --- a/libUUID/package.json +++ b/libUUID/package.json @@ -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", diff --git a/libUUID/rollup.config.ts b/libUUID/rollup.config.ts index 0f5b1bdaf..70724f495 100644 --- a/libUUID/rollup.config.ts +++ b/libUUID/rollup.config.ts @@ -9,6 +9,7 @@ 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}`, @@ -16,9 +17,6 @@ export default defineConfig({ plugins: [ del({ targets: `${json.version}/*`, runOnce: true }), - typescript({ - declaration: true, - declarationDir: `${json.version}`, - }), + typescript({}), ] }); \ No newline at end of file diff --git a/libUUID/src/index.d.ts b/libUUID/src/index.d.ts new file mode 100644 index 000000000..ab50df846 --- /dev/null +++ b/libUUID/src/index.d.ts @@ -0,0 +1,4 @@ +declare namespace UUID { + function generateUUID(): string; + function generateRowID(): string; +} \ No newline at end of file diff --git a/libUUID/src/index.ts b/libUUID/src/index.ts index 8e808fc19..e451889bf 100644 --- a/libUUID/src/index.ts +++ b/libUUID/src/index.ts @@ -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, }; \ No newline at end of file diff --git a/libUUID/tsconfig.json b/libUUID/tsconfig.json index ddf9ff2a6..340004e04 100644 --- a/libUUID/tsconfig.json +++ b/libUUID/tsconfig.json @@ -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"] }