@pol-studios/utils 1.0.0
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/array/index.d.ts +1 -0
- package/dist/array/index.js +136 -0
- package/dist/async/index.d.ts +1 -0
- package/dist/async/index.js +67 -0
- package/dist/cache/index.d.ts +1 -0
- package/dist/cache/index.js +42 -0
- package/dist/color/index.d.ts +1 -0
- package/dist/color/index.js +16 -0
- package/dist/date/index.d.ts +2 -0
- package/dist/date/index.js +102 -0
- package/dist/dev/index.d.ts +1 -0
- package/dist/dev/index.js +21 -0
- package/dist/device/index.d.ts +1 -0
- package/dist/device/index.js +31 -0
- package/dist/enum/index.d.ts +1 -0
- package/dist/enum/index.js +19 -0
- package/dist/error/index.d.ts +1 -0
- package/dist/error/index.js +198 -0
- package/dist/format/index.d.ts +1 -0
- package/dist/format/index.js +36 -0
- package/dist/index-B2oAfh_i.d.ts +63 -0
- package/dist/index-BDWEMkWa.d.ts +56 -0
- package/dist/index-BSNY-QEc.d.ts +15 -0
- package/dist/index-BaA8cg0E.d.ts +100 -0
- package/dist/index-Btn_GVfm.d.ts +13 -0
- package/dist/index-BxUoIlv_.d.ts +39 -0
- package/dist/index-ByjfWGR4.d.ts +151 -0
- package/dist/index-C-YwC08Y.d.ts +45 -0
- package/dist/index-C062CkPL.d.ts +31 -0
- package/dist/index-C8CxeaqZ.d.ts +24 -0
- package/dist/index-CZbs1QQN.d.ts +102 -0
- package/dist/index-Cp7KyTeB.d.ts +23 -0
- package/dist/index-CrplC0qf.d.ts +29 -0
- package/dist/index-Cvl_0aDq.d.ts +14 -0
- package/dist/index-D_IvPWYI.d.ts +77 -0
- package/dist/index-DdaZnk7j.d.ts +28 -0
- package/dist/index-vLuR45Km.d.ts +27 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +1279 -0
- package/dist/object/index.d.ts +1 -0
- package/dist/object/index.js +115 -0
- package/dist/state/index.d.ts +1 -0
- package/dist/state/index.js +17 -0
- package/dist/string/index.d.ts +1 -0
- package/dist/string/index.js +55 -0
- package/dist/tailwind/index.d.ts +2 -0
- package/dist/tailwind/index.js +9 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +37 -0
- package/dist/uuid/index.d.ts +1 -0
- package/dist/uuid/index.js +10 -0
- package/dist/validation/index.d.ts +1 -0
- package/dist/validation/index.js +123 -0
- package/package.json +50 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1279 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/string/index.ts
|
|
8
|
+
var string_exports = {};
|
|
9
|
+
__export(string_exports, {
|
|
10
|
+
camelize: () => camelize,
|
|
11
|
+
generateSlug: () => generateSlug,
|
|
12
|
+
isBlank: () => isBlank,
|
|
13
|
+
isNullOrWhitespace: () => isNullOrWhitespace,
|
|
14
|
+
pascalize: () => pascalize,
|
|
15
|
+
pascalizeWithSpaces: () => pascalizeWithSpaces,
|
|
16
|
+
sanitizeInput: () => sanitizeInput,
|
|
17
|
+
slugify: () => slugify
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// src/string/camelize.ts
|
|
21
|
+
function camelize(str) {
|
|
22
|
+
return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) {
|
|
23
|
+
return index === 0 ? word.toLowerCase() : word.toUpperCase();
|
|
24
|
+
}).replace(/\s+/g, "");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// src/internal/isUsable.ts
|
|
28
|
+
function isUsable(value) {
|
|
29
|
+
return value !== void 0 && value !== null && (typeof value !== "number" || isNaN(value) === false);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// src/string/pascalize.ts
|
|
33
|
+
function pascalize(str) {
|
|
34
|
+
return str.replace(/(\w)(\w*)/g, function(g0, g1, g2) {
|
|
35
|
+
return g1.toUpperCase() + g2.toLowerCase();
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function pascalizeWithSpaces(input) {
|
|
39
|
+
if (isUsable(input) === false) return input;
|
|
40
|
+
return input.replace(/([a-z0-9])([A-Z])/g, "$1 $2").split(/[^A-Za-z0-9]+/).filter(Boolean).map((w) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase()).join(" ");
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/string/slugify.ts
|
|
44
|
+
function slugify(text) {
|
|
45
|
+
return text.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
|
|
46
|
+
}
|
|
47
|
+
var generateSlug = slugify;
|
|
48
|
+
|
|
49
|
+
// src/string/sanitize.ts
|
|
50
|
+
function sanitizeInput(value) {
|
|
51
|
+
return value.replace(/"/g, '""').replace(/'/g, "''");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/string/isBlank.ts
|
|
55
|
+
function isBlank(value) {
|
|
56
|
+
if (value === null || value === void 0) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (typeof value === "string" && value.trim().length === 0) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
var isNullOrWhitespace = isBlank;
|
|
65
|
+
|
|
66
|
+
// src/array/index.ts
|
|
67
|
+
var array_exports = {};
|
|
68
|
+
__export(array_exports, {
|
|
69
|
+
chunk: () => chunk,
|
|
70
|
+
chunkArray: () => chunkArray,
|
|
71
|
+
convertArrayToObject: () => convertArrayToObject,
|
|
72
|
+
getAverage: () => getAverage,
|
|
73
|
+
groupBy: () => groupBy,
|
|
74
|
+
groupByMultipleCriteria: () => groupByMultipleCriteria,
|
|
75
|
+
mapUnique: () => mapUnique,
|
|
76
|
+
mapUnqiue: () => mapUnqiue,
|
|
77
|
+
range: () => range,
|
|
78
|
+
selectByMin: () => selectByMin,
|
|
79
|
+
sort: () => sort,
|
|
80
|
+
sortBy: () => sortBy,
|
|
81
|
+
tryGetAverage: () => tryGetAverage,
|
|
82
|
+
tryGetSum: () => tryGetSum,
|
|
83
|
+
unique: () => unique
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
// src/array/sortBy.ts
|
|
87
|
+
function sortBy(items, property, isAscending = false) {
|
|
88
|
+
if (items === null || items === void 0) return [];
|
|
89
|
+
return [...items]?.sort((a, b) => {
|
|
90
|
+
const aProp = a[property];
|
|
91
|
+
const bProp = b[property];
|
|
92
|
+
if (isAscending) {
|
|
93
|
+
return aProp === bProp ? 0 : aProp < bProp ? 1 : -1;
|
|
94
|
+
}
|
|
95
|
+
return aProp === bProp ? 0 : aProp < bProp ? -1 : 1;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
function sort(items, func, isAscending = false) {
|
|
99
|
+
const startingValue = isAscending ? 1 : -1;
|
|
100
|
+
const endingValue = isAscending ? -1 : 1;
|
|
101
|
+
return [...items].sort(
|
|
102
|
+
(a, b) => func(a) === func(b) ? 0 : func(a) < func(b) ? startingValue : endingValue
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
function selectByMin(items, action) {
|
|
106
|
+
return items.reduce((min, current) => {
|
|
107
|
+
return action(current) < action(min) ? current : min;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// src/array/groupBy.ts
|
|
112
|
+
function groupBy(list, key) {
|
|
113
|
+
const map = /* @__PURE__ */ new Map();
|
|
114
|
+
if (isUsable(list) === false) return map;
|
|
115
|
+
list.forEach((item) => {
|
|
116
|
+
const keyValue = typeof key === "function" ? key(item) : item[key];
|
|
117
|
+
const collection = map.get(keyValue);
|
|
118
|
+
if (!collection) {
|
|
119
|
+
map.set(keyValue, [item]);
|
|
120
|
+
} else {
|
|
121
|
+
collection.push(item);
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
return map;
|
|
125
|
+
}
|
|
126
|
+
function groupByMultipleCriteria(items, criteria) {
|
|
127
|
+
if (isUsable(items) === false) return [];
|
|
128
|
+
const grouped = {};
|
|
129
|
+
items.forEach((item) => {
|
|
130
|
+
const key = criteria.map((criterion) => item[criterion]).join("|");
|
|
131
|
+
if (!grouped[key]) {
|
|
132
|
+
grouped[key] = [];
|
|
133
|
+
}
|
|
134
|
+
grouped[key].push(item);
|
|
135
|
+
});
|
|
136
|
+
const results = Object.values(grouped).map((group) => ({
|
|
137
|
+
items: Array.isArray(group) ? group : []
|
|
138
|
+
}));
|
|
139
|
+
return results;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// src/array/chunk.ts
|
|
143
|
+
function chunk(array, chunkSize) {
|
|
144
|
+
if (chunkSize <= 0) throw new Error("chunkSize must be greater than 0");
|
|
145
|
+
const chunks = [];
|
|
146
|
+
for (let i = 0; i < array.length; i += chunkSize) {
|
|
147
|
+
chunks.push(array.slice(i, i + chunkSize));
|
|
148
|
+
}
|
|
149
|
+
return chunks;
|
|
150
|
+
}
|
|
151
|
+
var chunkArray = chunk;
|
|
152
|
+
|
|
153
|
+
// src/array/unique.ts
|
|
154
|
+
function unique(array, key) {
|
|
155
|
+
if (isUsable(array) === false) return [];
|
|
156
|
+
return Array.from(new Set(array.map((x) => x[key])));
|
|
157
|
+
}
|
|
158
|
+
var mapUnique = unique;
|
|
159
|
+
var mapUnqiue = unique;
|
|
160
|
+
|
|
161
|
+
// src/array/range.ts
|
|
162
|
+
function range(size, startAt = 0) {
|
|
163
|
+
return [...Array(size).keys()].map((i, index) => index + startAt);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// src/array/sum.ts
|
|
167
|
+
function tryGetSum(itemsArray, defaultValue = 0) {
|
|
168
|
+
if (isUsable(itemsArray) === false) return defaultValue;
|
|
169
|
+
if (itemsArray.length === 0) return defaultValue;
|
|
170
|
+
const results = itemsArray.reduce((a, b) => a + b, defaultValue);
|
|
171
|
+
if (Number.isNaN(results)) {
|
|
172
|
+
return defaultValue;
|
|
173
|
+
}
|
|
174
|
+
return results;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// src/array/average.ts
|
|
178
|
+
function tryGetAverage(items, defaultValue = 0) {
|
|
179
|
+
if (isUsable(items) === false) return defaultValue;
|
|
180
|
+
if (items.length === 0) return defaultValue;
|
|
181
|
+
const sum = tryGetSum(items, defaultValue);
|
|
182
|
+
const response = sum / items.length;
|
|
183
|
+
return response;
|
|
184
|
+
}
|
|
185
|
+
function getAverage(arr) {
|
|
186
|
+
const sum = arr.reduce((acc, curr) => acc + curr, 0);
|
|
187
|
+
return sum / arr.length;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// src/array/convertToObject.ts
|
|
191
|
+
function convertArrayToObject(array, key) {
|
|
192
|
+
return array?.reduce(
|
|
193
|
+
(obj, item) => {
|
|
194
|
+
obj[item[key]] = item;
|
|
195
|
+
return obj;
|
|
196
|
+
},
|
|
197
|
+
{}
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
// src/object/index.ts
|
|
202
|
+
var object_exports = {};
|
|
203
|
+
__export(object_exports, {
|
|
204
|
+
deepEquals: () => deepEquals,
|
|
205
|
+
diff: () => diff,
|
|
206
|
+
getPath: () => getPath,
|
|
207
|
+
getValueByPath: () => getValueByPath,
|
|
208
|
+
includeOnly: () => includeOnly,
|
|
209
|
+
isDeepEqual: () => isDeepEqual,
|
|
210
|
+
omit: () => omit,
|
|
211
|
+
pick: () => pick,
|
|
212
|
+
setPath: () => setPath,
|
|
213
|
+
setValueByPath: () => setValueByPath
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
// src/object/omit.ts
|
|
217
|
+
function omit(obj, keys) {
|
|
218
|
+
const keysArray = Array.isArray(keys) ? keys : [keys];
|
|
219
|
+
const newObj = { ...obj };
|
|
220
|
+
keysArray.forEach((key) => {
|
|
221
|
+
if (key in newObj) {
|
|
222
|
+
delete newObj[key];
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
return newObj;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// src/object/pick.ts
|
|
229
|
+
function pick(obj, keys) {
|
|
230
|
+
const newValue = {};
|
|
231
|
+
keys.forEach((key) => {
|
|
232
|
+
if (key in obj) {
|
|
233
|
+
newValue[key] = obj[key];
|
|
234
|
+
}
|
|
235
|
+
});
|
|
236
|
+
return newValue;
|
|
237
|
+
}
|
|
238
|
+
var includeOnly = pick;
|
|
239
|
+
|
|
240
|
+
// src/object/diff.ts
|
|
241
|
+
function diff(oldValue, newValue) {
|
|
242
|
+
if (isUsable(oldValue) === false) {
|
|
243
|
+
return { ...newValue };
|
|
244
|
+
}
|
|
245
|
+
const result = {};
|
|
246
|
+
function compare(o1, o2, res) {
|
|
247
|
+
for (const key in o1) {
|
|
248
|
+
if (o1.hasOwnProperty(key)) {
|
|
249
|
+
if (typeof o1[key] === "object" && o1[key] !== null && typeof o2[key] === "object" && o2[key] !== null) {
|
|
250
|
+
const nestedDiff = diff(o1[key], o2[key]);
|
|
251
|
+
if (Object.keys(nestedDiff).length > 0) {
|
|
252
|
+
res[key] = nestedDiff;
|
|
253
|
+
}
|
|
254
|
+
} else if (o1[key] !== o2[key]) {
|
|
255
|
+
res[key] = o2[key];
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
for (const key in o2) {
|
|
260
|
+
if (o2.hasOwnProperty(key) && !o1.hasOwnProperty(key)) {
|
|
261
|
+
res[key] = o2[key];
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
compare(oldValue, newValue, result);
|
|
266
|
+
return result;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// src/object/getPath.ts
|
|
270
|
+
function getPath(obj, path) {
|
|
271
|
+
const keys = path.split(".");
|
|
272
|
+
let current = obj;
|
|
273
|
+
for (const key of keys) {
|
|
274
|
+
if (current[key] === void 0) {
|
|
275
|
+
return void 0;
|
|
276
|
+
}
|
|
277
|
+
current = current[key];
|
|
278
|
+
}
|
|
279
|
+
return current;
|
|
280
|
+
}
|
|
281
|
+
var getValueByPath = getPath;
|
|
282
|
+
|
|
283
|
+
// src/object/setPath.ts
|
|
284
|
+
function setPath(obj, path, value) {
|
|
285
|
+
const keys = path.split(".");
|
|
286
|
+
let current = obj;
|
|
287
|
+
for (let i = 0; i < keys.length - 1; i++) {
|
|
288
|
+
const key = keys[i];
|
|
289
|
+
if (current[key] === void 0) {
|
|
290
|
+
current[key] = {};
|
|
291
|
+
}
|
|
292
|
+
current = current[key];
|
|
293
|
+
}
|
|
294
|
+
const lastKey = keys[keys.length - 1];
|
|
295
|
+
current[lastKey] = value;
|
|
296
|
+
}
|
|
297
|
+
var setValueByPath = setPath;
|
|
298
|
+
|
|
299
|
+
// src/object/deepEqual.ts
|
|
300
|
+
function deepEquals(obj1, obj2) {
|
|
301
|
+
const keys1 = Object.keys(obj1);
|
|
302
|
+
const keys2 = Object.keys(obj2);
|
|
303
|
+
if (keys1.length !== keys2.length) {
|
|
304
|
+
return false;
|
|
305
|
+
}
|
|
306
|
+
for (const key of keys1) {
|
|
307
|
+
if (obj1[key] !== obj2[key]) {
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
return true;
|
|
312
|
+
}
|
|
313
|
+
var isDeepEqual = deepEquals;
|
|
314
|
+
|
|
315
|
+
// src/date/index.ts
|
|
316
|
+
var date_exports = {};
|
|
317
|
+
__export(date_exports, {
|
|
318
|
+
addDates: () => addDates,
|
|
319
|
+
addDays: () => addDays,
|
|
320
|
+
areDatesEqual: () => areDatesEqual,
|
|
321
|
+
dateReviver: () => dateReviver,
|
|
322
|
+
getUtcDate: () => getUtcDate,
|
|
323
|
+
getUtcMoment: () => getUtcMoment,
|
|
324
|
+
isValidDate: () => isValidDate,
|
|
325
|
+
parseWithDate: () => parseWithDate,
|
|
326
|
+
toUtcDate: () => toUtcDate
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// src/date/utc.ts
|
|
330
|
+
import moment from "moment";
|
|
331
|
+
function getUtcDate() {
|
|
332
|
+
const now = /* @__PURE__ */ new Date();
|
|
333
|
+
return new Date(
|
|
334
|
+
Date.UTC(
|
|
335
|
+
now.getUTCFullYear(),
|
|
336
|
+
now.getUTCMonth(),
|
|
337
|
+
now.getUTCDate(),
|
|
338
|
+
now.getUTCHours(),
|
|
339
|
+
now.getUTCMinutes(),
|
|
340
|
+
now.getUTCSeconds()
|
|
341
|
+
)
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
function toUtcDate(date) {
|
|
345
|
+
if (isUsable(date) === false) return null;
|
|
346
|
+
return new Date(
|
|
347
|
+
Date.UTC(
|
|
348
|
+
date.getUTCFullYear(),
|
|
349
|
+
date.getUTCMonth(),
|
|
350
|
+
date.getUTCDate(),
|
|
351
|
+
date.getUTCHours(),
|
|
352
|
+
date.getUTCMinutes(),
|
|
353
|
+
date.getUTCSeconds()
|
|
354
|
+
)
|
|
355
|
+
);
|
|
356
|
+
}
|
|
357
|
+
function getUtcMoment() {
|
|
358
|
+
return moment.utc(moment.now());
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
// src/date/compare.ts
|
|
362
|
+
function areDatesEqual(date1, date2) {
|
|
363
|
+
return date1 === date2;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
// src/date/parse.ts
|
|
367
|
+
import moment2 from "moment";
|
|
368
|
+
function dateReviver(key, value) {
|
|
369
|
+
if (typeof value !== "string") return value;
|
|
370
|
+
const isUtcOrLocalDate = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,7})?(Z)?$/.test(value);
|
|
371
|
+
if (isUtcOrLocalDate) {
|
|
372
|
+
return moment2.utc(value);
|
|
373
|
+
} else {
|
|
374
|
+
const isTimeZoneDate = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,7})?[+-]\d{2}:\d{2}$/.test(
|
|
375
|
+
value
|
|
376
|
+
);
|
|
377
|
+
if (isTimeZoneDate) {
|
|
378
|
+
return moment2(value);
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
return value;
|
|
382
|
+
}
|
|
383
|
+
function parseWithDate(key, value) {
|
|
384
|
+
if (typeof value !== "string") return value;
|
|
385
|
+
const isUtcOrLocalDate = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,7})?(Z)?$/.test(value);
|
|
386
|
+
if (isUtcOrLocalDate) {
|
|
387
|
+
return new Date(value);
|
|
388
|
+
} else {
|
|
389
|
+
const isTimeZoneDate = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,7})?[+-]\d{2}:\d{2}$/.test(
|
|
390
|
+
value
|
|
391
|
+
);
|
|
392
|
+
if (isTimeZoneDate) {
|
|
393
|
+
return new Date(value);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return value;
|
|
397
|
+
}
|
|
398
|
+
function isValidDate(date) {
|
|
399
|
+
if (isUsable(date) === false) return false;
|
|
400
|
+
return date.getTime() === date.getTime();
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// src/date/add.ts
|
|
404
|
+
import moment3 from "moment";
|
|
405
|
+
function addDates(date1, date2) {
|
|
406
|
+
const duration = moment3.duration(date2.diff(date1));
|
|
407
|
+
return date1.add(duration);
|
|
408
|
+
}
|
|
409
|
+
function addDays(date1, days) {
|
|
410
|
+
const newDate = date1.add(days, "days");
|
|
411
|
+
return newDate;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// src/async/index.ts
|
|
415
|
+
var async_exports = {};
|
|
416
|
+
__export(async_exports, {
|
|
417
|
+
Semaphore: () => Semaphore,
|
|
418
|
+
concurrent: () => concurrent,
|
|
419
|
+
debounce: () => debounce,
|
|
420
|
+
delay: () => delay,
|
|
421
|
+
promiseAllWithConcurrencyLimit: () => promiseAllWithConcurrencyLimit
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
// src/async/delay.ts
|
|
425
|
+
function delay(ms) {
|
|
426
|
+
return new Promise((resolve) => {
|
|
427
|
+
setTimeout(resolve, ms);
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
// src/async/debounce.ts
|
|
432
|
+
var timeoutId = null;
|
|
433
|
+
function debounce(func, wait) {
|
|
434
|
+
if (timeoutId !== null) {
|
|
435
|
+
clearTimeout(timeoutId);
|
|
436
|
+
}
|
|
437
|
+
timeoutId = setTimeout(() => {
|
|
438
|
+
func();
|
|
439
|
+
}, wait);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// src/async/concurrent.ts
|
|
443
|
+
async function concurrent(tasks, concurrency) {
|
|
444
|
+
const results = [];
|
|
445
|
+
let current = 0;
|
|
446
|
+
async function worker() {
|
|
447
|
+
while (current < tasks.length) {
|
|
448
|
+
const index = current++;
|
|
449
|
+
results[index] = await tasks[index]();
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
const workers = [];
|
|
453
|
+
for (let i = 0; i < concurrency; i++) {
|
|
454
|
+
workers.push(worker());
|
|
455
|
+
}
|
|
456
|
+
await Promise.all(workers);
|
|
457
|
+
return results;
|
|
458
|
+
}
|
|
459
|
+
var promiseAllWithConcurrencyLimit = concurrent;
|
|
460
|
+
|
|
461
|
+
// src/async/semaphore.ts
|
|
462
|
+
var Semaphore = class {
|
|
463
|
+
constructor(count) {
|
|
464
|
+
this.tasks = [];
|
|
465
|
+
this.count = count;
|
|
466
|
+
}
|
|
467
|
+
acquire() {
|
|
468
|
+
if (this.count > 0) {
|
|
469
|
+
this.count--;
|
|
470
|
+
return Promise.resolve();
|
|
471
|
+
} else {
|
|
472
|
+
return new Promise((resolve) => this.tasks.push(resolve));
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
release() {
|
|
476
|
+
if (this.tasks.length > 0) {
|
|
477
|
+
const resolve = this.tasks.shift();
|
|
478
|
+
if (resolve) resolve();
|
|
479
|
+
} else {
|
|
480
|
+
this.count++;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
};
|
|
484
|
+
|
|
485
|
+
// src/format/index.ts
|
|
486
|
+
var format_exports = {};
|
|
487
|
+
__export(format_exports, {
|
|
488
|
+
formatCurrency: () => formatCurrency,
|
|
489
|
+
toDecimalString: () => toDecimalString,
|
|
490
|
+
toNumberString: () => toNumberString,
|
|
491
|
+
toUsdString: () => toUsdString
|
|
492
|
+
});
|
|
493
|
+
|
|
494
|
+
// src/format/currency.ts
|
|
495
|
+
function formatCurrency(value) {
|
|
496
|
+
if (isUsable(value) === false) return "";
|
|
497
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
498
|
+
style: "currency",
|
|
499
|
+
currency: "USD"
|
|
500
|
+
});
|
|
501
|
+
return formatter.format(value);
|
|
502
|
+
}
|
|
503
|
+
var toUsdString = formatCurrency;
|
|
504
|
+
function toNumberString(value) {
|
|
505
|
+
const formatter = new Intl.NumberFormat("en-US", {
|
|
506
|
+
maximumFractionDigits: 2
|
|
507
|
+
});
|
|
508
|
+
return formatter.format(value);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
// src/format/decimal.ts
|
|
512
|
+
function toDecimalString(num, decimalPlaces) {
|
|
513
|
+
if (isUsable(num) === false) return "";
|
|
514
|
+
return num.toLocaleString("en-US", {
|
|
515
|
+
minimumFractionDigits: decimalPlaces,
|
|
516
|
+
maximumFractionDigits: decimalPlaces
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// src/tailwind/index.ts
|
|
521
|
+
var tailwind_exports = {};
|
|
522
|
+
__export(tailwind_exports, {
|
|
523
|
+
cn: () => cn
|
|
524
|
+
});
|
|
525
|
+
import { clsx } from "clsx";
|
|
526
|
+
import { twMerge } from "tailwind-merge";
|
|
527
|
+
function cn(...inputs) {
|
|
528
|
+
return twMerge(clsx(inputs));
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
// src/cache/index.ts
|
|
532
|
+
var cache_exports = {};
|
|
533
|
+
__export(cache_exports, {
|
|
534
|
+
cacheFunction: () => cacheFunction,
|
|
535
|
+
clearAllCache: () => clearAllCache,
|
|
536
|
+
clearCache: () => clearCache
|
|
537
|
+
});
|
|
538
|
+
var cacheStore = /* @__PURE__ */ new Map();
|
|
539
|
+
async function cacheFunction(key, fn, duration) {
|
|
540
|
+
const now = Date.now();
|
|
541
|
+
const cached = cacheStore.get(key);
|
|
542
|
+
if (cached) {
|
|
543
|
+
if (now < cached.expiresAt) {
|
|
544
|
+
return cached.data;
|
|
545
|
+
}
|
|
546
|
+
if (cached.promise) {
|
|
547
|
+
return cached.promise;
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
const promise = fn().then((result) => {
|
|
551
|
+
cacheStore.set(key, {
|
|
552
|
+
data: result,
|
|
553
|
+
expiresAt: Date.now() + duration
|
|
554
|
+
});
|
|
555
|
+
return result;
|
|
556
|
+
}).catch((error) => {
|
|
557
|
+
cacheStore.delete(key);
|
|
558
|
+
throw error;
|
|
559
|
+
});
|
|
560
|
+
cacheStore.set(key, {
|
|
561
|
+
data: cached?.data,
|
|
562
|
+
// Retain existing data until new data is fetched
|
|
563
|
+
expiresAt: cached?.expiresAt || now,
|
|
564
|
+
promise
|
|
565
|
+
});
|
|
566
|
+
return promise;
|
|
567
|
+
}
|
|
568
|
+
function clearCache(key) {
|
|
569
|
+
cacheStore.delete(key);
|
|
570
|
+
}
|
|
571
|
+
function clearAllCache() {
|
|
572
|
+
cacheStore.clear();
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
// src/types/index.ts
|
|
576
|
+
var types_exports = {};
|
|
577
|
+
__export(types_exports, {
|
|
578
|
+
getContentType: () => getContentType,
|
|
579
|
+
isImageType: () => isImageType,
|
|
580
|
+
isPdfType: () => isPdfType,
|
|
581
|
+
isRenderableType: () => isRenderableType,
|
|
582
|
+
isUsable: () => isUsable2,
|
|
583
|
+
isVideoType: () => isVideoType
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
// src/types/guards.ts
|
|
587
|
+
function isUsable2(value) {
|
|
588
|
+
return value !== void 0 && value !== null && (typeof value !== "number" || isNaN(value) === false);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// src/types/StorageObjectMetadata.ts
|
|
592
|
+
function getContentType(metadata, path) {
|
|
593
|
+
if (metadata?.contentType) {
|
|
594
|
+
return metadata.contentType;
|
|
595
|
+
}
|
|
596
|
+
const ext = path.split(".").pop()?.toUpperCase();
|
|
597
|
+
return ext || "Unknown";
|
|
598
|
+
}
|
|
599
|
+
function isImageType(contentType) {
|
|
600
|
+
return ["JPEG", "JPG", "PNG", "GIF", "WEBP", "SVG", "HEIC", "HEIF"].includes(
|
|
601
|
+
contentType.toUpperCase()
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
function isVideoType(contentType) {
|
|
605
|
+
return ["MP4", "QUICKTIME", "MOV", "WEBM", "AVI", "MKV"].includes(
|
|
606
|
+
contentType.toUpperCase()
|
|
607
|
+
);
|
|
608
|
+
}
|
|
609
|
+
function isPdfType(contentType) {
|
|
610
|
+
return contentType.toUpperCase() === "PDF";
|
|
611
|
+
}
|
|
612
|
+
function isRenderableType(contentType) {
|
|
613
|
+
return isImageType(contentType) || isVideoType(contentType) || isPdfType(contentType);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
// src/color/index.ts
|
|
617
|
+
var color_exports = {};
|
|
618
|
+
__export(color_exports, {
|
|
619
|
+
isDarkColor: () => isDarkColor
|
|
620
|
+
});
|
|
621
|
+
function isDarkColor(c) {
|
|
622
|
+
c = c.substring(1);
|
|
623
|
+
const rgb = parseInt(c, 16);
|
|
624
|
+
const r = rgb >> 16 & 255;
|
|
625
|
+
const g = rgb >> 8 & 255;
|
|
626
|
+
const b = rgb >> 0 & 255;
|
|
627
|
+
const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
628
|
+
if (luma < 70) {
|
|
629
|
+
return true;
|
|
630
|
+
}
|
|
631
|
+
return false;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
// src/validation/index.ts
|
|
635
|
+
var validation_exports = {};
|
|
636
|
+
__export(validation_exports, {
|
|
637
|
+
calculatePasswordStrength: () => calculatePasswordStrength,
|
|
638
|
+
validateEmail: () => validateEmail,
|
|
639
|
+
validateMaxLength: () => validateMaxLength,
|
|
640
|
+
validateMinLength: () => validateMinLength,
|
|
641
|
+
validatePattern: () => validatePattern,
|
|
642
|
+
validateRequired: () => validateRequired,
|
|
643
|
+
validateValue: () => validateValue
|
|
644
|
+
});
|
|
645
|
+
|
|
646
|
+
// src/validation/validators.ts
|
|
647
|
+
function validateValue(value, rules) {
|
|
648
|
+
for (const rule of rules) {
|
|
649
|
+
if (!rule.validate(value)) {
|
|
650
|
+
return { isValid: false, error: rule.message };
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
return { isValid: true };
|
|
654
|
+
}
|
|
655
|
+
function validateEmail(email) {
|
|
656
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
657
|
+
if (!email || email.trim().length === 0) {
|
|
658
|
+
return { isValid: false, error: "Email is required" };
|
|
659
|
+
}
|
|
660
|
+
if (!emailRegex.test(email)) {
|
|
661
|
+
return { isValid: false, error: "Please enter a valid email address" };
|
|
662
|
+
}
|
|
663
|
+
return { isValid: true };
|
|
664
|
+
}
|
|
665
|
+
function validateRequired(value) {
|
|
666
|
+
if (value === null || value === void 0 || value === "") {
|
|
667
|
+
return { isValid: false, error: "This field is required" };
|
|
668
|
+
}
|
|
669
|
+
if (typeof value === "string" && value.trim().length === 0) {
|
|
670
|
+
return { isValid: false, error: "This field is required" };
|
|
671
|
+
}
|
|
672
|
+
return { isValid: true };
|
|
673
|
+
}
|
|
674
|
+
function validateMinLength(min) {
|
|
675
|
+
return (value) => {
|
|
676
|
+
if (!value || value.length < min) {
|
|
677
|
+
return {
|
|
678
|
+
isValid: false,
|
|
679
|
+
error: `Must be at least ${min} characters`
|
|
680
|
+
};
|
|
681
|
+
}
|
|
682
|
+
return { isValid: true };
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
function validateMaxLength(max) {
|
|
686
|
+
return (value) => {
|
|
687
|
+
if (value && value.length > max) {
|
|
688
|
+
return {
|
|
689
|
+
isValid: false,
|
|
690
|
+
error: `Must be no more than ${max} characters`
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
return { isValid: true };
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
function validatePattern(pattern, message) {
|
|
697
|
+
return (value) => {
|
|
698
|
+
if (value && !pattern.test(value)) {
|
|
699
|
+
return { isValid: false, error: message };
|
|
700
|
+
}
|
|
701
|
+
return { isValid: true };
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// src/validation/password.ts
|
|
706
|
+
function calculatePasswordStrength(password) {
|
|
707
|
+
if (!password || password.length === 0) {
|
|
708
|
+
return {
|
|
709
|
+
strength: "weak",
|
|
710
|
+
score: 0,
|
|
711
|
+
feedback: []
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
let score = 0;
|
|
715
|
+
const feedback = [];
|
|
716
|
+
if (password.length >= 8) {
|
|
717
|
+
score += 1;
|
|
718
|
+
} else {
|
|
719
|
+
feedback.push("Use at least 8 characters");
|
|
720
|
+
}
|
|
721
|
+
if (password.length >= 12) {
|
|
722
|
+
score += 1;
|
|
723
|
+
}
|
|
724
|
+
if (/[a-z]/.test(password)) {
|
|
725
|
+
score += 1;
|
|
726
|
+
} else {
|
|
727
|
+
feedback.push("Add lowercase letters");
|
|
728
|
+
}
|
|
729
|
+
if (/[A-Z]/.test(password)) {
|
|
730
|
+
score += 1;
|
|
731
|
+
} else {
|
|
732
|
+
feedback.push("Add uppercase letters");
|
|
733
|
+
}
|
|
734
|
+
if (/[0-9]/.test(password)) {
|
|
735
|
+
score += 1;
|
|
736
|
+
} else {
|
|
737
|
+
feedback.push("Add numbers");
|
|
738
|
+
}
|
|
739
|
+
if (/[^a-zA-Z0-9]/.test(password)) {
|
|
740
|
+
score += 1;
|
|
741
|
+
} else {
|
|
742
|
+
feedback.push("Add special characters");
|
|
743
|
+
}
|
|
744
|
+
let strength;
|
|
745
|
+
if (score <= 2) {
|
|
746
|
+
strength = "weak";
|
|
747
|
+
} else if (score <= 3) {
|
|
748
|
+
strength = "fair";
|
|
749
|
+
} else if (score <= 4) {
|
|
750
|
+
strength = "good";
|
|
751
|
+
} else {
|
|
752
|
+
strength = "strong";
|
|
753
|
+
}
|
|
754
|
+
return {
|
|
755
|
+
strength,
|
|
756
|
+
score,
|
|
757
|
+
feedback: feedback.length > 0 ? feedback : []
|
|
758
|
+
};
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
// src/error/index.ts
|
|
762
|
+
var error_exports = {};
|
|
763
|
+
__export(error_exports, {
|
|
764
|
+
extractFieldName: () => extractFieldName,
|
|
765
|
+
getFormFieldError: () => getFormFieldError,
|
|
766
|
+
getUserFriendlyError: () => getUserFriendlyError,
|
|
767
|
+
isNetworkError: () => isNetworkError,
|
|
768
|
+
isPostgrestError: () => isPostgrestError
|
|
769
|
+
});
|
|
770
|
+
|
|
771
|
+
// src/error/mapper.ts
|
|
772
|
+
var errorMappings = [
|
|
773
|
+
// Unique constraint violation
|
|
774
|
+
{
|
|
775
|
+
code: "23505",
|
|
776
|
+
message: "This item already exists",
|
|
777
|
+
action: "Please use a different name or value"
|
|
778
|
+
},
|
|
779
|
+
// Foreign key violation
|
|
780
|
+
{
|
|
781
|
+
code: "23503",
|
|
782
|
+
message: "Cannot delete: this item is in use",
|
|
783
|
+
action: "Remove all references to this item before deleting"
|
|
784
|
+
},
|
|
785
|
+
// Check constraint violation
|
|
786
|
+
{
|
|
787
|
+
code: "23514",
|
|
788
|
+
message: "Invalid value provided",
|
|
789
|
+
action: "Please check your input and try again"
|
|
790
|
+
},
|
|
791
|
+
// Undefined table
|
|
792
|
+
{
|
|
793
|
+
code: "42P01",
|
|
794
|
+
message: "Service temporarily unavailable",
|
|
795
|
+
action: "Please try again in a moment"
|
|
796
|
+
},
|
|
797
|
+
// Insufficient privilege
|
|
798
|
+
{
|
|
799
|
+
code: "42501",
|
|
800
|
+
message: "You don't have permission to perform this action",
|
|
801
|
+
action: "Contact your administrator if you need access"
|
|
802
|
+
},
|
|
803
|
+
// Not found (PostgREST)
|
|
804
|
+
{
|
|
805
|
+
code: "PGRST116",
|
|
806
|
+
message: "Item not found",
|
|
807
|
+
action: "The item may have been deleted or moved"
|
|
808
|
+
},
|
|
809
|
+
// Network errors
|
|
810
|
+
{
|
|
811
|
+
pattern: /network|connection|fetch|timeout|offline/i,
|
|
812
|
+
message: "Connection problem",
|
|
813
|
+
action: "Please check your internet connection and try again"
|
|
814
|
+
},
|
|
815
|
+
// Authentication errors
|
|
816
|
+
{
|
|
817
|
+
pattern: /unauthorized|authentication|token|session/i,
|
|
818
|
+
message: "Your session has expired",
|
|
819
|
+
action: "Please sign in again"
|
|
820
|
+
},
|
|
821
|
+
// Validation errors
|
|
822
|
+
{
|
|
823
|
+
pattern: /validation|invalid|required|missing/i,
|
|
824
|
+
message: "Please check your input",
|
|
825
|
+
action: "Make sure all required fields are filled correctly"
|
|
826
|
+
},
|
|
827
|
+
// Generic fallback
|
|
828
|
+
{
|
|
829
|
+
message: "Something went wrong",
|
|
830
|
+
action: "Please try again"
|
|
831
|
+
}
|
|
832
|
+
];
|
|
833
|
+
function extractErrorCode(error) {
|
|
834
|
+
if (error?.code) return error.code;
|
|
835
|
+
if (error?.error?.code) return error.error.code;
|
|
836
|
+
return void 0;
|
|
837
|
+
}
|
|
838
|
+
function extractErrorMessage(error) {
|
|
839
|
+
if (error?.message) return error.message;
|
|
840
|
+
if (error?.error?.message) return error.error.message;
|
|
841
|
+
if (typeof error === "string") return error;
|
|
842
|
+
return "An unknown error occurred";
|
|
843
|
+
}
|
|
844
|
+
function getUserFriendlyError(error) {
|
|
845
|
+
const errorCode = extractErrorCode(error);
|
|
846
|
+
const errorMessage = extractErrorMessage(error);
|
|
847
|
+
if (errorCode) {
|
|
848
|
+
const codeMatch = errorMappings.find((mapping) => mapping.code === errorCode);
|
|
849
|
+
if (codeMatch) {
|
|
850
|
+
return {
|
|
851
|
+
message: codeMatch.message,
|
|
852
|
+
action: codeMatch.action
|
|
853
|
+
};
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
const patternMatch = errorMappings.find(
|
|
857
|
+
(mapping) => mapping.pattern && mapping.pattern.test(errorMessage)
|
|
858
|
+
);
|
|
859
|
+
if (patternMatch) {
|
|
860
|
+
return {
|
|
861
|
+
message: patternMatch.message,
|
|
862
|
+
action: patternMatch.action
|
|
863
|
+
};
|
|
864
|
+
}
|
|
865
|
+
const fallback = errorMappings[errorMappings.length - 1];
|
|
866
|
+
return {
|
|
867
|
+
message: fallback.message,
|
|
868
|
+
action: fallback.action
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
function isPostgrestError(error) {
|
|
872
|
+
return error && typeof error === "object" && "code" in error && "message" in error && typeof error.code === "string";
|
|
873
|
+
}
|
|
874
|
+
function isNetworkError(error) {
|
|
875
|
+
const message = extractErrorMessage(error).toLowerCase();
|
|
876
|
+
return /network|connection|fetch|timeout|offline|failed to fetch/i.test(message);
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
// src/error/form.ts
|
|
880
|
+
var validationMappings = [
|
|
881
|
+
{
|
|
882
|
+
pattern: /required|missing|empty/i,
|
|
883
|
+
message: "This field is required",
|
|
884
|
+
action: "Please fill in this field"
|
|
885
|
+
},
|
|
886
|
+
{
|
|
887
|
+
pattern: /min.*length|too short/i,
|
|
888
|
+
message: "This field is too short",
|
|
889
|
+
action: "Please enter more characters"
|
|
890
|
+
},
|
|
891
|
+
{
|
|
892
|
+
pattern: /max.*length|too long/i,
|
|
893
|
+
message: "This field is too long",
|
|
894
|
+
action: "Please enter fewer characters"
|
|
895
|
+
},
|
|
896
|
+
{
|
|
897
|
+
pattern: /email|invalid.*email/i,
|
|
898
|
+
message: "Please enter a valid email address",
|
|
899
|
+
action: "Example: name@example.com"
|
|
900
|
+
},
|
|
901
|
+
{
|
|
902
|
+
pattern: /password|weak/i,
|
|
903
|
+
message: "Password is too weak",
|
|
904
|
+
action: "Use at least 8 characters with numbers and letters"
|
|
905
|
+
},
|
|
906
|
+
{
|
|
907
|
+
pattern: /match|doesn't match/i,
|
|
908
|
+
message: "Values don't match",
|
|
909
|
+
action: "Please check that both fields match"
|
|
910
|
+
},
|
|
911
|
+
{
|
|
912
|
+
pattern: /number|numeric/i,
|
|
913
|
+
message: "Please enter a valid number",
|
|
914
|
+
action: "Only numbers are allowed"
|
|
915
|
+
},
|
|
916
|
+
{
|
|
917
|
+
pattern: /date|invalid.*date/i,
|
|
918
|
+
message: "Please enter a valid date",
|
|
919
|
+
action: "Use format: MM/DD/YYYY"
|
|
920
|
+
},
|
|
921
|
+
{
|
|
922
|
+
pattern: /url|invalid.*url/i,
|
|
923
|
+
message: "Please enter a valid URL",
|
|
924
|
+
action: "Example: https://example.com"
|
|
925
|
+
},
|
|
926
|
+
{
|
|
927
|
+
pattern: /phone|invalid.*phone/i,
|
|
928
|
+
message: "Please enter a valid phone number",
|
|
929
|
+
action: "Example: (555) 123-4567"
|
|
930
|
+
},
|
|
931
|
+
{
|
|
932
|
+
message: "Invalid value",
|
|
933
|
+
action: "Please check your input"
|
|
934
|
+
}
|
|
935
|
+
];
|
|
936
|
+
function getFormFieldError(error) {
|
|
937
|
+
if (!error) return null;
|
|
938
|
+
const errorMessage = typeof error === "string" ? error : error.message || "";
|
|
939
|
+
if (!errorMessage) return null;
|
|
940
|
+
const patternMatch = validationMappings.find(
|
|
941
|
+
(mapping) => mapping.pattern && mapping.pattern.test(errorMessage)
|
|
942
|
+
);
|
|
943
|
+
if (patternMatch) {
|
|
944
|
+
return {
|
|
945
|
+
message: patternMatch.message,
|
|
946
|
+
action: patternMatch.action
|
|
947
|
+
};
|
|
948
|
+
}
|
|
949
|
+
const fallback = validationMappings[validationMappings.length - 1];
|
|
950
|
+
return {
|
|
951
|
+
message: fallback.message,
|
|
952
|
+
action: fallback.action
|
|
953
|
+
};
|
|
954
|
+
}
|
|
955
|
+
function extractFieldName(errorMessage) {
|
|
956
|
+
const fieldMatch = errorMessage.match(/(?:field|property|column)\s+['"]?(\w+)['"]?/i);
|
|
957
|
+
if (fieldMatch && fieldMatch[1]) {
|
|
958
|
+
return fieldMatch[1];
|
|
959
|
+
}
|
|
960
|
+
return null;
|
|
961
|
+
}
|
|
962
|
+
|
|
963
|
+
// src/device/index.ts
|
|
964
|
+
var device_exports = {};
|
|
965
|
+
__export(device_exports, {
|
|
966
|
+
hasCameraAsync: () => hasCameraAsync,
|
|
967
|
+
isIphone: () => isIphone,
|
|
968
|
+
isPwaLaunched: () => isPwaLaunched,
|
|
969
|
+
isSmallDevice: () => isSmallDevice
|
|
970
|
+
});
|
|
971
|
+
function isSmallDevice() {
|
|
972
|
+
return window.innerWidth <= 640;
|
|
973
|
+
}
|
|
974
|
+
function isIphone() {
|
|
975
|
+
return /iPhone/.test(navigator.userAgent);
|
|
976
|
+
}
|
|
977
|
+
function isPwaLaunched() {
|
|
978
|
+
if (window.navigator.standalone) {
|
|
979
|
+
return true;
|
|
980
|
+
}
|
|
981
|
+
if (window.matchMedia("(display-mode: standalone)").matches) {
|
|
982
|
+
return true;
|
|
983
|
+
}
|
|
984
|
+
return false;
|
|
985
|
+
}
|
|
986
|
+
async function hasCameraAsync() {
|
|
987
|
+
try {
|
|
988
|
+
const devices = await navigator.mediaDevices?.enumerateDevices();
|
|
989
|
+
return devices?.some((device) => device.kind === "videoinput") ?? false;
|
|
990
|
+
} catch (error) {
|
|
991
|
+
console.error("Error checking for camera:", error);
|
|
992
|
+
return false;
|
|
993
|
+
}
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
// src/uuid/index.ts
|
|
997
|
+
var uuid_exports = {};
|
|
998
|
+
__export(uuid_exports, {
|
|
999
|
+
newUuid: () => newUuid
|
|
1000
|
+
});
|
|
1001
|
+
function newUuid() {
|
|
1002
|
+
return "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx".replace(/[x]/g, () => {
|
|
1003
|
+
const r = Math.random() * 16 | 0;
|
|
1004
|
+
return r.toString(16);
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
// src/state/index.ts
|
|
1009
|
+
var state_exports = {};
|
|
1010
|
+
__export(state_exports, {
|
|
1011
|
+
getObjectChanges: () => getObjectChanges,
|
|
1012
|
+
withUpdate: () => withUpdate
|
|
1013
|
+
});
|
|
1014
|
+
function withUpdate(item, updates) {
|
|
1015
|
+
return { ...item, ...updates };
|
|
1016
|
+
}
|
|
1017
|
+
function getObjectChanges(oldObj, newObj) {
|
|
1018
|
+
const changes = {};
|
|
1019
|
+
for (const key of Object.keys(newObj)) {
|
|
1020
|
+
if (newObj[key] !== oldObj[key]) {
|
|
1021
|
+
changes[key] = newObj[key];
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
return changes;
|
|
1025
|
+
}
|
|
1026
|
+
|
|
1027
|
+
// src/enum/index.ts
|
|
1028
|
+
var enum_exports = {};
|
|
1029
|
+
__export(enum_exports, {
|
|
1030
|
+
getEnumValues: () => getEnumValues,
|
|
1031
|
+
parseStringToEnum: () => parseStringToEnum
|
|
1032
|
+
});
|
|
1033
|
+
function getEnumValues(enumObject) {
|
|
1034
|
+
const values = Object.values(enumObject);
|
|
1035
|
+
return values.filter((value) => typeof value !== "number");
|
|
1036
|
+
}
|
|
1037
|
+
function parseStringToEnum(enumType, value) {
|
|
1038
|
+
if (value in enumType) {
|
|
1039
|
+
return enumType[value];
|
|
1040
|
+
}
|
|
1041
|
+
const numericValue = parseInt(value, 10);
|
|
1042
|
+
if (!isNaN(numericValue) && Object.values(enumType).includes(numericValue)) {
|
|
1043
|
+
return numericValue;
|
|
1044
|
+
}
|
|
1045
|
+
return void 0;
|
|
1046
|
+
}
|
|
1047
|
+
|
|
1048
|
+
// src/dev/index.ts
|
|
1049
|
+
var dev_exports = {};
|
|
1050
|
+
__export(dev_exports, {
|
|
1051
|
+
debugLog: () => debugLog,
|
|
1052
|
+
isDev: () => isDev,
|
|
1053
|
+
isDevEnvironment: () => isDevEnvironment
|
|
1054
|
+
});
|
|
1055
|
+
function isDevEnvironment() {
|
|
1056
|
+
if (typeof process === "undefined") return false;
|
|
1057
|
+
const development = (process.env.WITH_MODE ?? "") === "development";
|
|
1058
|
+
return development;
|
|
1059
|
+
}
|
|
1060
|
+
function isDev() {
|
|
1061
|
+
if (typeof process === "undefined") return false;
|
|
1062
|
+
const development = (process.env.WITH_MODE ?? "") === "development";
|
|
1063
|
+
return development;
|
|
1064
|
+
}
|
|
1065
|
+
function debugLog(message, ...optionalParams) {
|
|
1066
|
+
if (isDevEnvironment()) {
|
|
1067
|
+
console.log(message, ...optionalParams);
|
|
1068
|
+
}
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
// src/constants/index.ts
|
|
1072
|
+
var constants_exports = {};
|
|
1073
|
+
__export(constants_exports, {
|
|
1074
|
+
AccessKeys: () => AccessKeys
|
|
1075
|
+
});
|
|
1076
|
+
|
|
1077
|
+
// src/constants/AccessKeys.ts
|
|
1078
|
+
var AccessKeys = {
|
|
1079
|
+
Timesheet: "timesheet",
|
|
1080
|
+
TimesheetAdmin: "admin_timesheet",
|
|
1081
|
+
InternalAdmin: "internal",
|
|
1082
|
+
Invoicing: "invoicing",
|
|
1083
|
+
ExpenseReport: "expense_report",
|
|
1084
|
+
ExpenseReportAdmin: "admin_expense_report",
|
|
1085
|
+
ProjectAdmin: "admin_project",
|
|
1086
|
+
FixtureCatalog: "fixture_catalog",
|
|
1087
|
+
ProjectDatabase: "project_database",
|
|
1088
|
+
Owner: "owner",
|
|
1089
|
+
User: "user"
|
|
1090
|
+
};
|
|
1091
|
+
|
|
1092
|
+
// src/download/index.ts
|
|
1093
|
+
var download_exports = {};
|
|
1094
|
+
__export(download_exports, {
|
|
1095
|
+
downloadFile: () => downloadFile,
|
|
1096
|
+
getFile: () => getFile,
|
|
1097
|
+
getFilePost: () => getFilePost
|
|
1098
|
+
});
|
|
1099
|
+
async function getFile(url, fileName) {
|
|
1100
|
+
const response = await fetch(url);
|
|
1101
|
+
const blob = await response.blob();
|
|
1102
|
+
const link = document.createElement("a");
|
|
1103
|
+
link.href = URL.createObjectURL(blob);
|
|
1104
|
+
link.download = fileName;
|
|
1105
|
+
link.click();
|
|
1106
|
+
URL.revokeObjectURL(link.href);
|
|
1107
|
+
}
|
|
1108
|
+
async function downloadFile(text) {
|
|
1109
|
+
const blob = new Blob([text], { type: "text/plain" });
|
|
1110
|
+
const link = document.createElement("a");
|
|
1111
|
+
link.style.display = "none";
|
|
1112
|
+
link.href = URL.createObjectURL(blob);
|
|
1113
|
+
document.body.appendChild(link);
|
|
1114
|
+
link.click();
|
|
1115
|
+
URL.revokeObjectURL(link.href);
|
|
1116
|
+
document.body.removeChild(link);
|
|
1117
|
+
}
|
|
1118
|
+
async function getFilePost(url, fileName, queryParams) {
|
|
1119
|
+
const response = await fetch(url, {
|
|
1120
|
+
method: "POST",
|
|
1121
|
+
headers: {
|
|
1122
|
+
"Content-Type": "application/json"
|
|
1123
|
+
},
|
|
1124
|
+
body: JSON.stringify(queryParams)
|
|
1125
|
+
});
|
|
1126
|
+
if (response.ok === false) {
|
|
1127
|
+
if (response.status === 404) throw new Error(response.statusText);
|
|
1128
|
+
if (response.status === 500) throw new Error(response.statusText);
|
|
1129
|
+
throw new Error(response.statusText);
|
|
1130
|
+
}
|
|
1131
|
+
const blob = await response.blob();
|
|
1132
|
+
const link = document.createElement("a");
|
|
1133
|
+
link.href = URL.createObjectURL(blob);
|
|
1134
|
+
link.download = fileName;
|
|
1135
|
+
link.click();
|
|
1136
|
+
URL.revokeObjectURL(link.href);
|
|
1137
|
+
}
|
|
1138
|
+
|
|
1139
|
+
// src/meta/index.ts
|
|
1140
|
+
var meta_exports = {};
|
|
1141
|
+
__export(meta_exports, {
|
|
1142
|
+
getCallerUniqueKey: () => getCallerUniqueKey
|
|
1143
|
+
});
|
|
1144
|
+
function getCallerUniqueKey() {
|
|
1145
|
+
const err = new Error();
|
|
1146
|
+
let stack = err.stack;
|
|
1147
|
+
if (stack === void 0) {
|
|
1148
|
+
try {
|
|
1149
|
+
throw err;
|
|
1150
|
+
} catch (e) {
|
|
1151
|
+
stack = e.stack;
|
|
1152
|
+
}
|
|
1153
|
+
}
|
|
1154
|
+
stack = stack || "";
|
|
1155
|
+
const lines = stack.split("\n");
|
|
1156
|
+
let earliestExecutionLine = 10;
|
|
1157
|
+
const filteredLines = lines.filter((line, index) => {
|
|
1158
|
+
const isIncluded = (line.includes("React") || line.trim().startsWith("at commitHook") || line.trim().includes("MountEffects")) === false;
|
|
1159
|
+
if (index < earliestExecutionLine && isIncluded === false) {
|
|
1160
|
+
earliestExecutionLine = index;
|
|
1161
|
+
}
|
|
1162
|
+
return isIncluded;
|
|
1163
|
+
});
|
|
1164
|
+
const result = filteredLines.filter((x, index) => index < earliestExecutionLine).join("-");
|
|
1165
|
+
return result;
|
|
1166
|
+
}
|
|
1167
|
+
export {
|
|
1168
|
+
AccessKeys,
|
|
1169
|
+
Semaphore,
|
|
1170
|
+
addDates,
|
|
1171
|
+
addDays,
|
|
1172
|
+
areDatesEqual,
|
|
1173
|
+
array_exports as array,
|
|
1174
|
+
async_exports as async,
|
|
1175
|
+
cache_exports as cache,
|
|
1176
|
+
cacheFunction,
|
|
1177
|
+
calculatePasswordStrength,
|
|
1178
|
+
camelize,
|
|
1179
|
+
chunk,
|
|
1180
|
+
chunkArray,
|
|
1181
|
+
clearAllCache,
|
|
1182
|
+
clearCache,
|
|
1183
|
+
cn,
|
|
1184
|
+
color_exports as color,
|
|
1185
|
+
concurrent,
|
|
1186
|
+
constants_exports as constants,
|
|
1187
|
+
convertArrayToObject,
|
|
1188
|
+
date_exports as date,
|
|
1189
|
+
dateReviver,
|
|
1190
|
+
debounce,
|
|
1191
|
+
debugLog,
|
|
1192
|
+
deepEquals,
|
|
1193
|
+
delay,
|
|
1194
|
+
dev_exports as dev,
|
|
1195
|
+
device_exports as device,
|
|
1196
|
+
diff,
|
|
1197
|
+
download_exports as download,
|
|
1198
|
+
downloadFile,
|
|
1199
|
+
enum_exports as enumUtils,
|
|
1200
|
+
error_exports as error,
|
|
1201
|
+
extractFieldName,
|
|
1202
|
+
format_exports as format,
|
|
1203
|
+
formatCurrency,
|
|
1204
|
+
generateSlug,
|
|
1205
|
+
getAverage,
|
|
1206
|
+
getCallerUniqueKey,
|
|
1207
|
+
getContentType,
|
|
1208
|
+
getEnumValues,
|
|
1209
|
+
getFile,
|
|
1210
|
+
getFilePost,
|
|
1211
|
+
getFormFieldError,
|
|
1212
|
+
getObjectChanges,
|
|
1213
|
+
getPath,
|
|
1214
|
+
getUserFriendlyError,
|
|
1215
|
+
getUtcDate,
|
|
1216
|
+
getUtcMoment,
|
|
1217
|
+
getValueByPath,
|
|
1218
|
+
groupBy,
|
|
1219
|
+
groupByMultipleCriteria,
|
|
1220
|
+
hasCameraAsync,
|
|
1221
|
+
includeOnly,
|
|
1222
|
+
isBlank,
|
|
1223
|
+
isDarkColor,
|
|
1224
|
+
isDeepEqual,
|
|
1225
|
+
isDev,
|
|
1226
|
+
isDevEnvironment,
|
|
1227
|
+
isImageType,
|
|
1228
|
+
isIphone,
|
|
1229
|
+
isNetworkError,
|
|
1230
|
+
isNullOrWhitespace,
|
|
1231
|
+
isPdfType,
|
|
1232
|
+
isPostgrestError,
|
|
1233
|
+
isPwaLaunched,
|
|
1234
|
+
isRenderableType,
|
|
1235
|
+
isSmallDevice,
|
|
1236
|
+
isUsable,
|
|
1237
|
+
isValidDate,
|
|
1238
|
+
isVideoType,
|
|
1239
|
+
mapUnique,
|
|
1240
|
+
mapUnqiue,
|
|
1241
|
+
meta_exports as meta,
|
|
1242
|
+
newUuid,
|
|
1243
|
+
object_exports as object,
|
|
1244
|
+
omit,
|
|
1245
|
+
parseStringToEnum,
|
|
1246
|
+
parseWithDate,
|
|
1247
|
+
pascalize,
|
|
1248
|
+
pascalizeWithSpaces,
|
|
1249
|
+
pick,
|
|
1250
|
+
promiseAllWithConcurrencyLimit,
|
|
1251
|
+
range,
|
|
1252
|
+
sanitizeInput,
|
|
1253
|
+
selectByMin,
|
|
1254
|
+
setPath,
|
|
1255
|
+
setValueByPath,
|
|
1256
|
+
slugify,
|
|
1257
|
+
sort,
|
|
1258
|
+
sortBy,
|
|
1259
|
+
state_exports as state,
|
|
1260
|
+
string_exports as string,
|
|
1261
|
+
tailwind_exports as tailwind,
|
|
1262
|
+
toDecimalString,
|
|
1263
|
+
toNumberString,
|
|
1264
|
+
toUsdString,
|
|
1265
|
+
toUtcDate,
|
|
1266
|
+
tryGetAverage,
|
|
1267
|
+
tryGetSum,
|
|
1268
|
+
types_exports as types,
|
|
1269
|
+
unique,
|
|
1270
|
+
uuid_exports as uuid,
|
|
1271
|
+
validateEmail,
|
|
1272
|
+
validateMaxLength,
|
|
1273
|
+
validateMinLength,
|
|
1274
|
+
validatePattern,
|
|
1275
|
+
validateRequired,
|
|
1276
|
+
validateValue,
|
|
1277
|
+
validation_exports as validation,
|
|
1278
|
+
withUpdate
|
|
1279
|
+
};
|