cynx-lib 1.3.41 → 1.3.43

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.
@@ -0,0 +1,187 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var uid_exports = {};
19
+ __export(uid_exports, {
20
+ ALPHABETS: () => ALPHABETS,
21
+ createSequence: () => createSequence,
22
+ customAlphabet: () => customAlphabet,
23
+ default: () => uid_default,
24
+ genUid: () => genUid,
25
+ getRandomBytes: () => getRandomBytes,
26
+ isValidUID: () => isValidUID,
27
+ isValidUUID: () => isValidUUID,
28
+ nanoid: () => nanoid,
29
+ prefixedId: () => prefixedId,
30
+ seqId: () => seqId,
31
+ shortId: () => shortId,
32
+ timestampId: () => timestampId,
33
+ uid: () => uid,
34
+ uuid: () => uuid,
35
+ uuidv4: () => uuidv4
36
+ });
37
+ module.exports = __toCommonJS(uid_exports);
38
+ const ALPHABETS = {
39
+ urlSafe: "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLFGQZ_rich5hexURL",
40
+ alphanumeric: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
41
+ lowercase: "0123456789abcdefghijklmnopqrstuvwxyz",
42
+ uppercase: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",
43
+ numeric: "0123456789",
44
+ hex: "0123456789abcdef",
45
+ // Human-friendly alphabet without lookalikes (no 0, O, I, l, 1)
46
+ noLookalikes: "346789ABCDEFGHJKLMNPQRTUVWXYabcdefghijkmnpqrtwxyz"
47
+ };
48
+ function getCrypto() {
49
+ if (typeof globalThis !== "undefined" && globalThis.crypto) {
50
+ return globalThis.crypto;
51
+ }
52
+ if (typeof window !== "undefined" && window.crypto) {
53
+ return window.crypto;
54
+ }
55
+ if (typeof self !== "undefined" && self.crypto) {
56
+ return self.crypto;
57
+ }
58
+ return null;
59
+ }
60
+ function getRandomBytes(size = 16) {
61
+ const bytes = new Uint8Array(size);
62
+ const cryptoObj = getCrypto();
63
+ if (cryptoObj && typeof cryptoObj.getRandomValues === "function") {
64
+ cryptoObj.getRandomValues(bytes);
65
+ return bytes;
66
+ }
67
+ for (let i = 0; i < size; i++) {
68
+ const timeJitter = (Date.now() + (typeof performance !== "undefined" ? performance.now() : 0)) * 1e3 % 256;
69
+ bytes[i] = (Math.floor(Math.random() * 256) ^ Math.floor(timeJitter)) & 255;
70
+ }
71
+ return bytes;
72
+ }
73
+ function uuid() {
74
+ const cryptoObj = getCrypto();
75
+ if (cryptoObj && typeof cryptoObj.randomUUID === "function") {
76
+ return cryptoObj.randomUUID();
77
+ }
78
+ const bytes = getRandomBytes(16);
79
+ bytes[6] = bytes[6] & 15 | 64;
80
+ bytes[8] = bytes[8] & 63 | 128;
81
+ let out = "";
82
+ for (let i = 0; i < 16; i++) {
83
+ if (i === 4 || i === 6 || i === 8 || i === 10) out += "-";
84
+ out += bytes[i].toString(16).padStart(2, "0");
85
+ }
86
+ return out;
87
+ }
88
+ const uuidv4 = uuid;
89
+ function customAlphabet(alphabet = ALPHABETS.urlSafe, defaultSize = 21) {
90
+ const mask = (2 << 31 - Math.clz32(alphabet.length - 1 | 1)) - 1;
91
+ const step = Math.ceil(1.6 * mask * defaultSize / alphabet.length);
92
+ return function generate(size = defaultSize) {
93
+ let id = "";
94
+ while (true) {
95
+ const bytes = getRandomBytes(step);
96
+ for (let i = 0; i < step; i++) {
97
+ const byte = bytes[i] & mask;
98
+ if (alphabet[byte]) {
99
+ id += alphabet[byte];
100
+ if (id.length === size) return id;
101
+ }
102
+ }
103
+ }
104
+ };
105
+ }
106
+ function uid(size = 12, alphabet = ALPHABETS.urlSafe) {
107
+ if (alphabet === ALPHABETS.urlSafe) {
108
+ const bytes = getRandomBytes(size);
109
+ let id = "";
110
+ const len = alphabet.length;
111
+ for (let i = 0; i < size; i++) {
112
+ id += alphabet[bytes[i] % len];
113
+ }
114
+ return id;
115
+ }
116
+ return customAlphabet(alphabet, size)(size);
117
+ }
118
+ const nanoid = (size = 21) => uid(size, ALPHABETS.urlSafe);
119
+ const genUid = (size = 12) => uid(size, ALPHABETS.urlSafe);
120
+ function shortId(size = 8) {
121
+ return uid(size, ALPHABETS.alphanumeric);
122
+ }
123
+ function prefixedId(prefix = "id", size = 12, alphabet = ALPHABETS.alphanumeric) {
124
+ return `${prefix}_${uid(size, alphabet)}`;
125
+ }
126
+ function createSequence(prefix = "cynx") {
127
+ let counter = 0;
128
+ return function next(customPrefix = prefix) {
129
+ counter += 1;
130
+ return `${customPrefix}_${counter}`;
131
+ };
132
+ }
133
+ const seqId = createSequence("cynx");
134
+ function timestampId(prefix = "") {
135
+ const ts = Date.now().toString(36);
136
+ const rand = uid(8, ALPHABETS.lowercase);
137
+ return prefix ? `${prefix}_${ts}_${rand}` : `${ts}_${rand}`;
138
+ }
139
+ function isValidUUID(str) {
140
+ if (typeof str !== "string") return false;
141
+ return /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str);
142
+ }
143
+ function isValidUID(str, { minLength = 1, maxLength = 128, alphabet } = {}) {
144
+ if (typeof str !== "string") return false;
145
+ if (str.length < minLength || str.length > maxLength) return false;
146
+ if (alphabet) {
147
+ const chars = new Set(alphabet);
148
+ for (const char of str) {
149
+ if (!chars.has(char)) return false;
150
+ }
151
+ }
152
+ return true;
153
+ }
154
+ var uid_default = {
155
+ uuid,
156
+ uuidv4,
157
+ uid,
158
+ nanoid,
159
+ shortId,
160
+ prefixedId,
161
+ timestampId,
162
+ createSequence,
163
+ seqId,
164
+ customAlphabet,
165
+ getRandomBytes,
166
+ isValidUUID,
167
+ isValidUID,
168
+ ALPHABETS
169
+ };
170
+ // Annotate the CommonJS export names for ESM import in node:
171
+ 0 && (module.exports = {
172
+ ALPHABETS,
173
+ createSequence,
174
+ customAlphabet,
175
+ genUid,
176
+ getRandomBytes,
177
+ isValidUID,
178
+ isValidUUID,
179
+ nanoid,
180
+ prefixedId,
181
+ seqId,
182
+ shortId,
183
+ timestampId,
184
+ uid,
185
+ uuid,
186
+ uuidv4
187
+ });