Skip to content

Commit 412dfa6

Browse files
author
Nic Bradley
committed
improve rollup build
1 parent 0f1c7b2 commit 412dfa6

File tree

4 files changed

+52
-59
lines changed

4 files changed

+52
-59
lines changed

libUUID/0.0.1/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export default class libUUID {
1+
declare class libUUID {
22
private static base64Chars;
33
private static base;
44
private static previousTime;

libUUID/0.0.1/libUUID.js

Lines changed: 48 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,57 @@
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-
var libUUID = (function () {
3-
'use strict';
4-
5-
class libUUID {
6-
static base64Chars = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
7-
static base = 64;
8-
static previousTime = 0;
9-
static counter = new Array(12).fill(0);
10-
static toBase64(num, length) {
11-
let result = "";
12-
for (let i = 0; i < length; i++) {
13-
result = this.base64Chars[num % this.base] + result;
14-
num = Math.floor(num / this.base);
15-
}
16-
return result;
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) {
8+
let result = "";
9+
for (let i = 0; i < length; i++) {
10+
result = this.base64Chars[num % this.base] + result;
11+
num = Math.floor(num / this.base);
1712
}
18-
;
19-
static generateRandomBase64(length) {
20-
let result = "";
21-
for (let i = 0; i < length; i++) {
22-
result += this.base64Chars[Math.floor(Math.random() * this.base)];
23-
}
24-
return result;
13+
return result;
14+
}
15+
;
16+
static generateRandomBase64(length) {
17+
let result = "";
18+
for (let i = 0; i < length; i++) {
19+
result += this.base64Chars[Math.floor(Math.random() * this.base)];
2520
}
26-
;
27-
static generateUUID() {
28-
const currentTime = Date.now();
29-
const timeBase64 = this.toBase64(currentTime, 8);
30-
let randomOrCounterBase64 = "";
31-
if (currentTime === this.previousTime) {
32-
// Increment the counter
33-
for (let i = this.counter.length - 1; i >= 0; i--) {
34-
this.counter[i]++;
35-
if (this.counter[i] < this.base) {
36-
break;
37-
}
38-
else {
39-
this.counter[i] = 0;
40-
}
21+
return result;
22+
}
23+
;
24+
static generateUUID() {
25+
const currentTime = Date.now();
26+
const timeBase64 = this.toBase64(currentTime, 8);
27+
let randomOrCounterBase64 = "";
28+
if (currentTime === this.previousTime) {
29+
// 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) {
33+
break;
4134
}
42-
randomOrCounterBase64 = this.counter.map(index => this.base64Chars[index]).join("");
43-
}
44-
else {
45-
// Generate new random values and initialize counter with random starting values
46-
randomOrCounterBase64 = this.generateRandomBase64(12);
47-
// Initialize counter with random values instead of zeros to avoid hyphen-heavy sequences
48-
for (let i = 0; i < this.counter.length; i++) {
49-
this.counter[i] = Math.floor(Math.random() * this.base);
35+
else {
36+
this.counter[i] = 0;
5037
}
51-
this.previousTime = currentTime;
5238
}
53-
return timeBase64 + randomOrCounterBase64;
39+
randomOrCounterBase64 = this.counter.map(index => this.base64Chars[index]).join("");
5440
}
55-
;
56-
static generateRowID() {
57-
return this.generateUUID().replace(/_/g, "Z");
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);
47+
}
48+
this.previousTime = currentTime;
5849
}
59-
;
50+
return timeBase64 + randomOrCounterBase64;
51+
}
52+
;
53+
static generateRowID() {
54+
return this.generateUUID().replace(/_/g, "Z");
6055
}
61-
62-
return libUUID;
63-
64-
})();
56+
;
57+
}

libUUID/rollup.config.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineConfig } from "rollup"; // 💡 Import defineConfig and RollupOptions
1+
import { defineConfig } from "rollup";
22
import typescript from "@rollup/plugin-typescript";
33
import del from "rollup-plugin-delete";
44
import json from "./script.json" with { type: "json" };
@@ -9,7 +9,6 @@ export default defineConfig({
99

1010
output: {
1111
file: `${json.version}/${json.name}.js`,
12-
format: "iife",
1312
name: json.name,
1413
sourcemap: false,
1514
banner: `// ${json.name} v${json.version} by ${json.authors} | ${json.description}`,

libUUID/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
export default class libUUID {
1+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2+
class libUUID {
23
private static base64Chars = "-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
34
private static base = 64;
45
private static previousTime = 0;

0 commit comments

Comments
 (0)