@local-logic/types 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +138 -128
- package/dist/index.umd.cjs +2 -2
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,40 +1,40 @@
|
|
|
1
|
-
var
|
|
2
|
-
function
|
|
3
|
-
return
|
|
1
|
+
var F = /* @__PURE__ */ ((l) => (l.GET_STATE = "get-state", l.GET_STATE_RESPONSE = "get-state-response", l.SET_STATE = "set-state", l.ON_CHANGE = "on-change", l.RESIZE = "resize", l))(F || {});
|
|
2
|
+
function R(l) {
|
|
3
|
+
return l && l.__esModule && Object.prototype.hasOwnProperty.call(l, "default") ? l.default : l;
|
|
4
4
|
}
|
|
5
|
-
var
|
|
6
|
-
function
|
|
7
|
-
return
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
for (var
|
|
11
|
-
|
|
5
|
+
var E = { exports: {} }, L;
|
|
6
|
+
function z() {
|
|
7
|
+
return L || (L = 1, function(l) {
|
|
8
|
+
var U = (() => {
|
|
9
|
+
var f = Object.defineProperty, O = Object.getOwnPropertyDescriptor, j = Object.getOwnPropertyNames, I = Object.getOwnPropertySymbols, v = Object.prototype.hasOwnProperty, $ = Object.prototype.propertyIsEnumerable, y = (o, a, _) => a in o ? f(o, a, { enumerable: !0, configurable: !0, writable: !0, value: _ }) : o[a] = _, x = (o, a) => {
|
|
10
|
+
for (var _ in a || (a = {}))
|
|
11
|
+
v.call(a, _) && y(o, _, a[_]);
|
|
12
12
|
if (I)
|
|
13
|
-
for (var
|
|
14
|
-
|
|
15
|
-
return
|
|
16
|
-
},
|
|
17
|
-
for (var
|
|
18
|
-
|
|
19
|
-
},
|
|
20
|
-
if (
|
|
21
|
-
for (let d of
|
|
22
|
-
!
|
|
23
|
-
return
|
|
24
|
-
},
|
|
25
|
-
|
|
26
|
-
DEFAULT_OPTIONS: () =>
|
|
27
|
-
DEFAULT_UUID_LENGTH: () =>
|
|
28
|
-
default: () =>
|
|
13
|
+
for (var _ of I(a))
|
|
14
|
+
$.call(a, _) && y(o, _, a[_]);
|
|
15
|
+
return o;
|
|
16
|
+
}, q = (o, a) => {
|
|
17
|
+
for (var _ in a)
|
|
18
|
+
f(o, _, { get: a[_], enumerable: !0 });
|
|
19
|
+
}, N = (o, a, _, m) => {
|
|
20
|
+
if (a && typeof a == "object" || typeof a == "function")
|
|
21
|
+
for (let d of j(a))
|
|
22
|
+
!v.call(o, d) && d !== _ && f(o, d, { get: () => a[d], enumerable: !(m = O(a, d)) || m.enumerable });
|
|
23
|
+
return o;
|
|
24
|
+
}, P = (o) => N(f({}, "__esModule", { value: !0 }), o), i = (o, a, _) => y(o, typeof a != "symbol" ? a + "" : a, _), C = {};
|
|
25
|
+
q(C, {
|
|
26
|
+
DEFAULT_OPTIONS: () => M,
|
|
27
|
+
DEFAULT_UUID_LENGTH: () => b,
|
|
28
|
+
default: () => T
|
|
29
29
|
});
|
|
30
|
-
var
|
|
30
|
+
var B = "5.3.2", b = 6, M = {
|
|
31
31
|
dictionary: "alphanum",
|
|
32
32
|
shuffle: !0,
|
|
33
33
|
debug: !1,
|
|
34
|
-
length:
|
|
34
|
+
length: b,
|
|
35
35
|
counter: 0
|
|
36
|
-
},
|
|
37
|
-
constructor(
|
|
36
|
+
}, D = class {
|
|
37
|
+
constructor(o = {}) {
|
|
38
38
|
i(this, "counter"), i(this, "debug"), i(this, "dict"), i(this, "version"), i(this, "dictIndex", 0), i(this, "dictRange", []), i(this, "lowerBound", 0), i(this, "upperBound", 0), i(this, "dictLength", 0), i(this, "uuidLength"), i(this, "_digit_first_ascii", 48), i(this, "_digit_last_ascii", 58), i(this, "_alpha_lower_first_ascii", 97), i(this, "_alpha_lower_last_ascii", 123), i(this, "_hex_last_ascii", 103), i(this, "_alpha_upper_first_ascii", 65), i(this, "_alpha_upper_last_ascii", 91), i(this, "_number_dict_ranges", {
|
|
39
39
|
digits: [this._digit_first_ascii, this._digit_last_ascii]
|
|
40
40
|
}), i(this, "_alpha_dict_ranges", {
|
|
@@ -67,72 +67,93 @@ function F() {
|
|
|
67
67
|
_alphanum_upper_dict_ranges: this._alphanum_upper_dict_ranges,
|
|
68
68
|
_hex_dict_ranges: this._hex_dict_ranges
|
|
69
69
|
}), i(this, "log", (...t) => {
|
|
70
|
-
const
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
70
|
+
const e = [...t];
|
|
71
|
+
if (e[0] = "[short-unique-id] ".concat(t[0]), this.debug === !0 && typeof console < "u" && console !== null) {
|
|
72
|
+
console.log(...e);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
}), i(this, "_normalizeDictionary", (t, e) => {
|
|
76
|
+
let s;
|
|
75
77
|
if (t && Array.isArray(t) && t.length > 1)
|
|
76
|
-
|
|
78
|
+
s = t;
|
|
77
79
|
else {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
80
|
+
s = [], this.dictIndex = 0;
|
|
81
|
+
const n = "_".concat(t, "_dict_ranges"), r = this._dict_ranges[n];
|
|
82
|
+
let h = 0;
|
|
83
|
+
for (const [, g] of Object.entries(r)) {
|
|
84
|
+
const [c, w] = g;
|
|
85
|
+
h += Math.abs(w - c);
|
|
86
|
+
}
|
|
87
|
+
s = new Array(h);
|
|
88
|
+
let p = 0;
|
|
89
|
+
for (const [, g] of Object.entries(r)) {
|
|
90
|
+
this.dictRange = g, this.lowerBound = this.dictRange[0], this.upperBound = this.dictRange[1];
|
|
91
|
+
const c = this.lowerBound <= this.upperBound, w = this.lowerBound, S = this.upperBound;
|
|
92
|
+
if (c)
|
|
93
|
+
for (let u = w; u < S; u++)
|
|
94
|
+
s[p++] = String.fromCharCode(u), this.dictIndex = u;
|
|
95
|
+
else
|
|
96
|
+
for (let u = w; u > S; u--)
|
|
97
|
+
s[p++] = String.fromCharCode(u), this.dictIndex = u;
|
|
98
|
+
}
|
|
99
|
+
s.length = p;
|
|
87
100
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
101
|
+
if (e) {
|
|
102
|
+
const n = s.length;
|
|
103
|
+
for (let r = n - 1; r > 0; r--) {
|
|
104
|
+
const h = Math.floor(Math.random() * (r + 1));
|
|
105
|
+
[s[r], s[h]] = [s[h], s[r]];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return s;
|
|
109
|
+
}), i(this, "setDictionary", (t, e) => {
|
|
110
|
+
this.dict = this._normalizeDictionary(t, e), this.dictLength = this.dict.length, this.setCounter(0);
|
|
91
111
|
}), i(this, "seq", () => this.sequentialUUID()), i(this, "sequentialUUID", () => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
112
|
+
const t = this.dictLength, e = this.dict;
|
|
113
|
+
let s = this.counter;
|
|
114
|
+
const n = [];
|
|
115
|
+
do {
|
|
116
|
+
const h = s % t;
|
|
117
|
+
s = Math.trunc(s / t), n.push(e[h]);
|
|
118
|
+
} while (s !== 0);
|
|
119
|
+
const r = n.join("");
|
|
120
|
+
return this.counter += 1, r;
|
|
121
|
+
}), i(this, "rnd", (t = this.uuidLength || b) => this.randomUUID(t)), i(this, "randomUUID", (t = this.uuidLength || b) => {
|
|
100
122
|
if (t === null || typeof t > "u" || t < 1)
|
|
101
123
|
throw new Error("Invalid UUID Length Provided");
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return
|
|
108
|
-
}), i(this, "fmt", (t,
|
|
109
|
-
const
|
|
124
|
+
const e = new Array(t), s = this.dictLength, n = this.dict;
|
|
125
|
+
for (let r = 0; r < t; r++) {
|
|
126
|
+
const h = Math.floor(Math.random() * s);
|
|
127
|
+
e[r] = n[h];
|
|
128
|
+
}
|
|
129
|
+
return e.join("");
|
|
130
|
+
}), i(this, "fmt", (t, e) => this.formattedUUID(t, e)), i(this, "formattedUUID", (t, e) => {
|
|
131
|
+
const s = {
|
|
110
132
|
$r: this.randomUUID,
|
|
111
133
|
$s: this.sequentialUUID,
|
|
112
134
|
$t: this.stamp
|
|
113
135
|
};
|
|
114
|
-
return t.replace(
|
|
115
|
-
|
|
116
|
-
(r)
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
)
|
|
121
|
-
|
|
122
|
-
Math.
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
(this.approxMaxBeforeCollision(t) / this.availableUUIDs(s)).toFixed(20)
|
|
136
|
+
return t.replace(/\$[rs]\d{0,}|\$t0|\$t[1-9]\d{1,}/g, (n) => {
|
|
137
|
+
const r = n.slice(0, 2), h = Number.parseInt(n.slice(2), 10);
|
|
138
|
+
return r === "$s" ? s[r]().padStart(h, "0") : r === "$t" && e ? s[r](h, e) : s[r](h);
|
|
139
|
+
});
|
|
140
|
+
}), i(this, "availableUUIDs", (t = this.uuidLength) => Number.parseFloat(([...new Set(this.dict)].length ** t).toFixed(0))), i(this, "_collisionCache", /* @__PURE__ */ new Map()), i(this, "approxMaxBeforeCollision", (t = this.availableUUIDs(this.uuidLength)) => {
|
|
141
|
+
const e = t, s = this._collisionCache.get(e);
|
|
142
|
+
if (s !== void 0)
|
|
143
|
+
return s;
|
|
144
|
+
const n = Number.parseFloat(Math.sqrt(Math.PI / 2 * t).toFixed(20));
|
|
145
|
+
return this._collisionCache.set(e, n), n;
|
|
146
|
+
}), i(this, "collisionProbability", (t = this.availableUUIDs(this.uuidLength), e = this.uuidLength) => Number.parseFloat(
|
|
147
|
+
(this.approxMaxBeforeCollision(t) / this.availableUUIDs(e)).toFixed(20)
|
|
127
148
|
)), i(this, "uniqueness", (t = this.availableUUIDs(this.uuidLength)) => {
|
|
128
|
-
const
|
|
149
|
+
const e = Number.parseFloat(
|
|
129
150
|
(1 - this.approxMaxBeforeCollision(t) / t).toFixed(20)
|
|
130
151
|
);
|
|
131
|
-
return
|
|
132
|
-
}), i(this, "getVersion", () => this.version), i(this, "stamp", (t,
|
|
133
|
-
const
|
|
152
|
+
return e > 1 ? 1 : e < 0 ? 0 : e;
|
|
153
|
+
}), i(this, "getVersion", () => this.version), i(this, "stamp", (t, e) => {
|
|
154
|
+
const s = Math.floor(+(e || /* @__PURE__ */ new Date()) / 1e3).toString(16);
|
|
134
155
|
if (typeof t == "number" && t === 0)
|
|
135
|
-
return
|
|
156
|
+
return s;
|
|
136
157
|
if (typeof t != "number" || t < 10)
|
|
137
158
|
throw new Error(
|
|
138
159
|
[
|
|
@@ -141,60 +162,49 @@ function F() {
|
|
|
141
162
|
].join(`
|
|
142
163
|
`)
|
|
143
164
|
);
|
|
144
|
-
const
|
|
145
|
-
return
|
|
146
|
-
}), i(this, "parseStamp", (t,
|
|
147
|
-
if (
|
|
165
|
+
const n = t - 9, r = Math.round(Math.random() * (n > 15 ? 15 : n)), h = this.randomUUID(n);
|
|
166
|
+
return "".concat(h.substring(0, r)).concat(s).concat(h.substring(r)).concat(r.toString(16));
|
|
167
|
+
}), i(this, "parseStamp", (t, e) => {
|
|
168
|
+
if (e && !/t0|t[1-9]\d{1,}/.test(e))
|
|
148
169
|
throw new Error("Cannot extract date from a formated UUID with no timestamp in the format");
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
)
|
|
160
|
-
/^(.*?)(t{8,})(.*)$/g,
|
|
161
|
-
(o, l, u) => t.substring(l.length, l.length + u.length)
|
|
162
|
-
) : t;
|
|
163
|
-
if (a.length === 8)
|
|
164
|
-
return new Date(parseInt(a, 16) * 1e3);
|
|
165
|
-
if (a.length < 10)
|
|
170
|
+
const s = e ? e.replace(/\$[rs]\d{0,}|\$t0|\$t[1-9]\d{1,}/g, (r) => {
|
|
171
|
+
const h = {
|
|
172
|
+
$r: (c) => [...Array(c)].map(() => "r").join(""),
|
|
173
|
+
$s: (c) => [...Array(c)].map(() => "s").join(""),
|
|
174
|
+
$t: (c) => [...Array(c)].map(() => "t").join("")
|
|
175
|
+
}, p = r.slice(0, 2), g = Number.parseInt(r.slice(2), 10);
|
|
176
|
+
return h[p](g);
|
|
177
|
+
}).replace(/^(.*?)(t{8,})(.*)$/g, (r, h, p) => t.substring(h.length, h.length + p.length)) : t;
|
|
178
|
+
if (s.length === 8)
|
|
179
|
+
return new Date(Number.parseInt(s, 16) * 1e3);
|
|
180
|
+
if (s.length < 10)
|
|
166
181
|
throw new Error("Stamp length invalid");
|
|
167
|
-
const
|
|
168
|
-
return new Date(parseInt(
|
|
182
|
+
const n = Number.parseInt(s.substring(s.length - 1), 16);
|
|
183
|
+
return new Date(Number.parseInt(s.substring(n, n + 8), 16) * 1e3);
|
|
169
184
|
}), i(this, "setCounter", (t) => {
|
|
170
185
|
this.counter = t;
|
|
171
|
-
}), i(this, "validate", (t,
|
|
172
|
-
const
|
|
173
|
-
return t.split("").every((
|
|
186
|
+
}), i(this, "validate", (t, e) => {
|
|
187
|
+
const s = e ? this._normalizeDictionary(e) : this.dict;
|
|
188
|
+
return t.split("").every((n) => s.includes(n));
|
|
174
189
|
});
|
|
175
|
-
const
|
|
176
|
-
this.counter = 0, this.debug = !1, this.dict = [], this.version =
|
|
177
|
-
const {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
counter: T
|
|
182
|
-
} = e;
|
|
183
|
-
return this.uuidLength = d, this.setDictionary(h, f), this.setCounter(T), this.debug = e.debug, this.log(this.dict), this.log(
|
|
184
|
-
`Generator instantiated with Dictionary Size ${this.dictLength} and counter set to ${this.counter}`
|
|
185
|
-
), this.log = this.log.bind(this), this.setDictionary = this.setDictionary.bind(this), this.setCounter = this.setCounter.bind(this), this.seq = this.seq.bind(this), this.sequentialUUID = this.sequentialUUID.bind(this), this.rnd = this.rnd.bind(this), this.randomUUID = this.randomUUID.bind(this), this.fmt = this.fmt.bind(this), this.formattedUUID = this.formattedUUID.bind(this), this.availableUUIDs = this.availableUUIDs.bind(this), this.approxMaxBeforeCollision = this.approxMaxBeforeCollision.bind(this), this.collisionProbability = this.collisionProbability.bind(this), this.uniqueness = this.uniqueness.bind(this), this.getVersion = this.getVersion.bind(this), this.stamp = this.stamp.bind(this), this.parseStamp = this.parseStamp.bind(this), this;
|
|
190
|
+
const a = x(x({}, M), o);
|
|
191
|
+
this.counter = 0, this.debug = !1, this.dict = [], this.version = B;
|
|
192
|
+
const { dictionary: _, shuffle: m, length: d, counter: A } = a;
|
|
193
|
+
this.uuidLength = d, this.setDictionary(_, m), this.setCounter(A), this.debug = a.debug, this.log(this.dict), this.log(
|
|
194
|
+
"Generator instantiated with Dictionary Size ".concat(this.dictLength, " and counter set to ").concat(this.counter)
|
|
195
|
+
), this.log = this.log.bind(this), this.setDictionary = this.setDictionary.bind(this), this.setCounter = this.setCounter.bind(this), this.seq = this.seq.bind(this), this.sequentialUUID = this.sequentialUUID.bind(this), this.rnd = this.rnd.bind(this), this.randomUUID = this.randomUUID.bind(this), this.fmt = this.fmt.bind(this), this.formattedUUID = this.formattedUUID.bind(this), this.availableUUIDs = this.availableUUIDs.bind(this), this.approxMaxBeforeCollision = this.approxMaxBeforeCollision.bind(this), this.collisionProbability = this.collisionProbability.bind(this), this.uniqueness = this.uniqueness.bind(this), this.getVersion = this.getVersion.bind(this), this.stamp = this.stamp.bind(this), this.parseStamp = this.parseStamp.bind(this);
|
|
186
196
|
}
|
|
187
197
|
};
|
|
188
|
-
i(
|
|
189
|
-
var
|
|
190
|
-
return
|
|
198
|
+
i(D, "default", D);
|
|
199
|
+
var T = D;
|
|
200
|
+
return P(C);
|
|
191
201
|
})();
|
|
192
|
-
|
|
193
|
-
}(
|
|
202
|
+
l.exports = U.default, typeof window < "u" && (U = U.default);
|
|
203
|
+
}(E)), E.exports;
|
|
194
204
|
}
|
|
195
|
-
var
|
|
196
|
-
const
|
|
197
|
-
new
|
|
205
|
+
var G = z();
|
|
206
|
+
const V = /* @__PURE__ */ R(G);
|
|
207
|
+
new V({ length: 10 });
|
|
198
208
|
export {
|
|
199
|
-
|
|
209
|
+
F as ChannelEvents
|
|
200
210
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`));const
|
|
1
|
+
(function(g,f){typeof exports=="object"&&typeof module<"u"?f(exports):typeof define=="function"&&define.amd?define(["exports"],f):(g=typeof globalThis<"u"?globalThis:g||self,f(g.LL_Types={}))})(this,function(g){"use strict";var f=(_=>(_.GET_STATE="get-state",_.GET_STATE_RESPONSE="get-state-response",_.SET_STATE="set-state",_.ON_CHANGE="on-change",_.RESIZE="resize",_))(f||{});function T(_){return _&&_.__esModule&&Object.prototype.hasOwnProperty.call(_,"default")?_.default:_}var x={exports:{}},C;function P(){return C||(C=1,function(_){var D=(()=>{var m=Object.defineProperty,N=Object.getOwnPropertyDescriptor,B=Object.getOwnPropertyNames,S=Object.getOwnPropertySymbols,M=Object.prototype.hasOwnProperty,A=Object.prototype.propertyIsEnumerable,I=(o,a,l)=>a in o?m(o,a,{enumerable:!0,configurable:!0,writable:!0,value:l}):o[a]=l,L=(o,a)=>{for(var l in a||(a={}))M.call(a,l)&&I(o,l,a[l]);if(S)for(var l of S(a))A.call(a,l)&&I(o,l,a[l]);return o},F=(o,a)=>{for(var l in a)m(o,l,{get:a[l],enumerable:!0})},R=(o,a,l,U)=>{if(a&&typeof a=="object"||typeof a=="function")for(let d of B(a))!M.call(o,d)&&d!==l&&m(o,d,{get:()=>a[d],enumerable:!(U=N(a,d))||U.enumerable});return o},z=o=>R(m({},"__esModule",{value:!0}),o),i=(o,a,l)=>I(o,typeof a!="symbol"?a+"":a,l),E={};F(E,{DEFAULT_OPTIONS:()=>O,DEFAULT_UUID_LENGTH:()=>w,default:()=>V});var G="5.3.2",w=6,O={dictionary:"alphanum",shuffle:!0,debug:!1,length:w,counter:0},v=class{constructor(o={}){i(this,"counter"),i(this,"debug"),i(this,"dict"),i(this,"version"),i(this,"dictIndex",0),i(this,"dictRange",[]),i(this,"lowerBound",0),i(this,"upperBound",0),i(this,"dictLength",0),i(this,"uuidLength"),i(this,"_digit_first_ascii",48),i(this,"_digit_last_ascii",58),i(this,"_alpha_lower_first_ascii",97),i(this,"_alpha_lower_last_ascii",123),i(this,"_hex_last_ascii",103),i(this,"_alpha_upper_first_ascii",65),i(this,"_alpha_upper_last_ascii",91),i(this,"_number_dict_ranges",{digits:[this._digit_first_ascii,this._digit_last_ascii]}),i(this,"_alpha_dict_ranges",{lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]}),i(this,"_alpha_lower_dict_ranges",{lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii]}),i(this,"_alpha_upper_dict_ranges",{upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]}),i(this,"_alphanum_dict_ranges",{digits:[this._digit_first_ascii,this._digit_last_ascii],lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]}),i(this,"_alphanum_lower_dict_ranges",{digits:[this._digit_first_ascii,this._digit_last_ascii],lowerCase:[this._alpha_lower_first_ascii,this._alpha_lower_last_ascii]}),i(this,"_alphanum_upper_dict_ranges",{digits:[this._digit_first_ascii,this._digit_last_ascii],upperCase:[this._alpha_upper_first_ascii,this._alpha_upper_last_ascii]}),i(this,"_hex_dict_ranges",{decDigits:[this._digit_first_ascii,this._digit_last_ascii],alphaDigits:[this._alpha_lower_first_ascii,this._hex_last_ascii]}),i(this,"_dict_ranges",{_number_dict_ranges:this._number_dict_ranges,_alpha_dict_ranges:this._alpha_dict_ranges,_alpha_lower_dict_ranges:this._alpha_lower_dict_ranges,_alpha_upper_dict_ranges:this._alpha_upper_dict_ranges,_alphanum_dict_ranges:this._alphanum_dict_ranges,_alphanum_lower_dict_ranges:this._alphanum_lower_dict_ranges,_alphanum_upper_dict_ranges:this._alphanum_upper_dict_ranges,_hex_dict_ranges:this._hex_dict_ranges}),i(this,"log",(...t)=>{const e=[...t];if(e[0]="[short-unique-id] ".concat(t[0]),this.debug===!0&&typeof console<"u"&&console!==null){console.log(...e);return}}),i(this,"_normalizeDictionary",(t,e)=>{let s;if(t&&Array.isArray(t)&&t.length>1)s=t;else{s=[],this.dictIndex=0;const n="_".concat(t,"_dict_ranges"),r=this._dict_ranges[n];let h=0;for(const[,b]of Object.entries(r)){const[c,y]=b;h+=Math.abs(y-c)}s=new Array(h);let p=0;for(const[,b]of Object.entries(r)){this.dictRange=b,this.lowerBound=this.dictRange[0],this.upperBound=this.dictRange[1];const c=this.lowerBound<=this.upperBound,y=this.lowerBound,j=this.upperBound;if(c)for(let u=y;u<j;u++)s[p++]=String.fromCharCode(u),this.dictIndex=u;else for(let u=y;u>j;u--)s[p++]=String.fromCharCode(u),this.dictIndex=u}s.length=p}if(e){const n=s.length;for(let r=n-1;r>0;r--){const h=Math.floor(Math.random()*(r+1));[s[r],s[h]]=[s[h],s[r]]}}return s}),i(this,"setDictionary",(t,e)=>{this.dict=this._normalizeDictionary(t,e),this.dictLength=this.dict.length,this.setCounter(0)}),i(this,"seq",()=>this.sequentialUUID()),i(this,"sequentialUUID",()=>{const t=this.dictLength,e=this.dict;let s=this.counter;const n=[];do{const h=s%t;s=Math.trunc(s/t),n.push(e[h])}while(s!==0);const r=n.join("");return this.counter+=1,r}),i(this,"rnd",(t=this.uuidLength||w)=>this.randomUUID(t)),i(this,"randomUUID",(t=this.uuidLength||w)=>{if(t===null||typeof t>"u"||t<1)throw new Error("Invalid UUID Length Provided");const e=new Array(t),s=this.dictLength,n=this.dict;for(let r=0;r<t;r++){const h=Math.floor(Math.random()*s);e[r]=n[h]}return e.join("")}),i(this,"fmt",(t,e)=>this.formattedUUID(t,e)),i(this,"formattedUUID",(t,e)=>{const s={$r:this.randomUUID,$s:this.sequentialUUID,$t:this.stamp};return t.replace(/\$[rs]\d{0,}|\$t0|\$t[1-9]\d{1,}/g,n=>{const r=n.slice(0,2),h=Number.parseInt(n.slice(2),10);return r==="$s"?s[r]().padStart(h,"0"):r==="$t"&&e?s[r](h,e):s[r](h)})}),i(this,"availableUUIDs",(t=this.uuidLength)=>Number.parseFloat(([...new Set(this.dict)].length**t).toFixed(0))),i(this,"_collisionCache",new Map),i(this,"approxMaxBeforeCollision",(t=this.availableUUIDs(this.uuidLength))=>{const e=t,s=this._collisionCache.get(e);if(s!==void 0)return s;const n=Number.parseFloat(Math.sqrt(Math.PI/2*t).toFixed(20));return this._collisionCache.set(e,n),n}),i(this,"collisionProbability",(t=this.availableUUIDs(this.uuidLength),e=this.uuidLength)=>Number.parseFloat((this.approxMaxBeforeCollision(t)/this.availableUUIDs(e)).toFixed(20))),i(this,"uniqueness",(t=this.availableUUIDs(this.uuidLength))=>{const e=Number.parseFloat((1-this.approxMaxBeforeCollision(t)/t).toFixed(20));return e>1?1:e<0?0:e}),i(this,"getVersion",()=>this.version),i(this,"stamp",(t,e)=>{const s=Math.floor(+(e||new Date)/1e3).toString(16);if(typeof t=="number"&&t===0)return s;if(typeof t!="number"||t<10)throw new Error(["Param finalLength must be a number greater than or equal to 10,","or 0 if you want the raw hexadecimal timestamp"].join(`
|
|
2
|
+
`));const n=t-9,r=Math.round(Math.random()*(n>15?15:n)),h=this.randomUUID(n);return"".concat(h.substring(0,r)).concat(s).concat(h.substring(r)).concat(r.toString(16))}),i(this,"parseStamp",(t,e)=>{if(e&&!/t0|t[1-9]\d{1,}/.test(e))throw new Error("Cannot extract date from a formated UUID with no timestamp in the format");const s=e?e.replace(/\$[rs]\d{0,}|\$t0|\$t[1-9]\d{1,}/g,r=>{const h={$r:c=>[...Array(c)].map(()=>"r").join(""),$s:c=>[...Array(c)].map(()=>"s").join(""),$t:c=>[...Array(c)].map(()=>"t").join("")},p=r.slice(0,2),b=Number.parseInt(r.slice(2),10);return h[p](b)}).replace(/^(.*?)(t{8,})(.*)$/g,(r,h,p)=>t.substring(h.length,h.length+p.length)):t;if(s.length===8)return new Date(Number.parseInt(s,16)*1e3);if(s.length<10)throw new Error("Stamp length invalid");const n=Number.parseInt(s.substring(s.length-1),16);return new Date(Number.parseInt(s.substring(n,n+8),16)*1e3)}),i(this,"setCounter",t=>{this.counter=t}),i(this,"validate",(t,e)=>{const s=e?this._normalizeDictionary(e):this.dict;return t.split("").every(n=>s.includes(n))});const a=L(L({},O),o);this.counter=0,this.debug=!1,this.dict=[],this.version=G;const{dictionary:l,shuffle:U,length:d,counter:H}=a;this.uuidLength=d,this.setDictionary(l,U),this.setCounter(H),this.debug=a.debug,this.log(this.dict),this.log("Generator instantiated with Dictionary Size ".concat(this.dictLength," and counter set to ").concat(this.counter)),this.log=this.log.bind(this),this.setDictionary=this.setDictionary.bind(this),this.setCounter=this.setCounter.bind(this),this.seq=this.seq.bind(this),this.sequentialUUID=this.sequentialUUID.bind(this),this.rnd=this.rnd.bind(this),this.randomUUID=this.randomUUID.bind(this),this.fmt=this.fmt.bind(this),this.formattedUUID=this.formattedUUID.bind(this),this.availableUUIDs=this.availableUUIDs.bind(this),this.approxMaxBeforeCollision=this.approxMaxBeforeCollision.bind(this),this.collisionProbability=this.collisionProbability.bind(this),this.uniqueness=this.uniqueness.bind(this),this.getVersion=this.getVersion.bind(this),this.stamp=this.stamp.bind(this),this.parseStamp=this.parseStamp.bind(this)}};i(v,"default",v);var V=v;return z(E)})();_.exports=D.default,typeof window<"u"&&(D=D.default)}(x)),x.exports}var $=P();const q=T($);new q({length:10}),g.ChannelEvents=f,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@local-logic/types",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"author": "Local Logic",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"@local-logic/eslint-config": "*",
|
|
27
27
|
"@local-logic/sdks-app": "*",
|
|
28
28
|
"eslint": "^8.57.1",
|
|
29
|
-
"prettier": "^3.
|
|
30
|
-
"rollup-plugin-visualizer": "^5.
|
|
29
|
+
"prettier": "^3.6.2",
|
|
30
|
+
"rollup-plugin-visualizer": "^5.14.0",
|
|
31
31
|
"tsconfig": "*",
|
|
32
|
-
"typescript": "^5.
|
|
33
|
-
"vite": "^6.
|
|
34
|
-
"vite-plugin-dts": "^4.
|
|
32
|
+
"typescript": "^5.9.2",
|
|
33
|
+
"vite": "^6.3.5",
|
|
34
|
+
"vite-plugin-dts": "^4.5.4",
|
|
35
35
|
"vitest": "^2.1.9"
|
|
36
36
|
}
|
|
37
37
|
}
|