superjs-core 0.1.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/index.js ADDED
@@ -0,0 +1,1505 @@
1
+ // src/core/index.ts
2
+ function isPlainObject(value) {
3
+ if (value === null || typeof value !== "object") return false;
4
+ const proto = Object.getPrototypeOf(value);
5
+ return proto === Object.prototype || proto === null;
6
+ }
7
+ function getType(value) {
8
+ return Object.prototype.toString.call(value);
9
+ }
10
+ function clone(value, seen) {
11
+ if (value === null || typeof value !== "object") return value;
12
+ if (seen.has(value)) return seen.get(value);
13
+ const tag = getType(value);
14
+ if (tag === "[object Date]") {
15
+ const cloned = new Date(value.getTime());
16
+ seen.set(value, cloned);
17
+ return cloned;
18
+ }
19
+ if (tag === "[object RegExp]") {
20
+ const regExp = value;
21
+ const cloned = new RegExp(regExp.source, regExp.flags);
22
+ cloned.lastIndex = regExp.lastIndex;
23
+ seen.set(value, cloned);
24
+ return cloned;
25
+ }
26
+ if (tag === "[object Map]") {
27
+ const cloned = /* @__PURE__ */ new Map();
28
+ seen.set(value, cloned);
29
+ value.forEach((v, k) => {
30
+ cloned.set(clone(k, seen), clone(v, seen));
31
+ });
32
+ return cloned;
33
+ }
34
+ if (tag === "[object Set]") {
35
+ const cloned = /* @__PURE__ */ new Set();
36
+ seen.set(value, cloned);
37
+ value.forEach((v) => {
38
+ cloned.add(clone(v, seen));
39
+ });
40
+ return cloned;
41
+ }
42
+ if (Array.isArray(value)) {
43
+ const cloned = [];
44
+ seen.set(value, cloned);
45
+ for (let i = 0; i < value.length; i++) {
46
+ cloned[i] = clone(value[i], seen);
47
+ }
48
+ return cloned;
49
+ }
50
+ if (tag === "[object Object]") {
51
+ const cloned = {};
52
+ seen.set(value, cloned);
53
+ const keys = Object.keys(value);
54
+ for (let i = 0; i < keys.length; i++) {
55
+ const key = keys[i];
56
+ cloned[key] = clone(value[key], seen);
57
+ }
58
+ return cloned;
59
+ }
60
+ return value;
61
+ }
62
+ function deepClone(value) {
63
+ const seen = /* @__PURE__ */ new WeakMap();
64
+ return clone(value, seen);
65
+ }
66
+ function deepMerge(...objects) {
67
+ const result = {};
68
+ for (let i = 0; i < objects.length; i++) {
69
+ const obj = objects[i];
70
+ if (obj === null || obj === void 0) continue;
71
+ const keys = Object.keys(obj);
72
+ for (let j = 0; j < keys.length; j++) {
73
+ const key = keys[j];
74
+ const val = obj[key];
75
+ const existing = result[key];
76
+ if (val !== void 0 && isPlainObject(val) && isPlainObject(existing)) {
77
+ result[key] = deepMerge(
78
+ existing,
79
+ val
80
+ );
81
+ } else if (val !== void 0) {
82
+ result[key] = val;
83
+ }
84
+ }
85
+ }
86
+ return result;
87
+ }
88
+ function debounce(fn, wait, options) {
89
+ const { leading = false, trailing = true, maxWait } = options ?? {};
90
+ let timer = null;
91
+ let maxTimer = null;
92
+ let lastArgs = null;
93
+ let lastCallTime = null;
94
+ let lastInvokeTime = 0;
95
+ function invoke(time) {
96
+ lastInvokeTime = time;
97
+ if (lastArgs) {
98
+ fn(...lastArgs);
99
+ lastArgs = null;
100
+ }
101
+ }
102
+ function startTimer(waitTime) {
103
+ if (timer) clearTimeout(timer);
104
+ timer = setTimeout(() => {
105
+ const now = Date.now();
106
+ if (lastArgs && trailing) {
107
+ invoke(now);
108
+ }
109
+ timer = null;
110
+ lastCallTime = null;
111
+ }, waitTime);
112
+ }
113
+ function startMaxTimer() {
114
+ if (maxWait === void 0 || maxTimer) return;
115
+ maxTimer = setTimeout(() => {
116
+ if (lastArgs) {
117
+ invoke(Date.now());
118
+ if (timer) {
119
+ clearTimeout(timer);
120
+ timer = null;
121
+ }
122
+ lastCallTime = null;
123
+ }
124
+ }, maxWait);
125
+ }
126
+ function clearAllTimers() {
127
+ if (timer) {
128
+ clearTimeout(timer);
129
+ timer = null;
130
+ }
131
+ if (maxTimer) {
132
+ clearTimeout(maxTimer);
133
+ maxTimer = null;
134
+ }
135
+ }
136
+ function shouldInvoke(time) {
137
+ if (lastCallTime === null) return true;
138
+ const timeSinceLastCall = time - lastCallTime;
139
+ const timeSinceLastInvoke = time - lastInvokeTime;
140
+ return timeSinceLastCall >= wait || maxWait !== void 0 && timeSinceLastInvoke >= maxWait;
141
+ }
142
+ const debounced = function(...args) {
143
+ const time = Date.now();
144
+ const isInvoking = shouldInvoke(time);
145
+ lastArgs = args;
146
+ lastCallTime = time;
147
+ if (isInvoking && !timer && leading) {
148
+ invoke(time);
149
+ }
150
+ if (!timer) {
151
+ startTimer(wait);
152
+ if (maxWait !== void 0) {
153
+ startMaxTimer();
154
+ }
155
+ }
156
+ };
157
+ debounced.cancel = () => {
158
+ clearAllTimers();
159
+ lastArgs = null;
160
+ lastCallTime = null;
161
+ lastInvokeTime = 0;
162
+ };
163
+ debounced.flush = () => {
164
+ if (timer && lastArgs) {
165
+ invoke(Date.now());
166
+ clearAllTimers();
167
+ lastCallTime = null;
168
+ }
169
+ };
170
+ return debounced;
171
+ }
172
+ function throttle(fn, wait) {
173
+ let lastTime = 0;
174
+ let timer = null;
175
+ let lastArgs = null;
176
+ const throttled = function(...args) {
177
+ const now = Date.now();
178
+ const remaining = wait - (now - lastTime);
179
+ if (remaining <= 0) {
180
+ if (timer) {
181
+ clearTimeout(timer);
182
+ timer = null;
183
+ }
184
+ lastTime = now;
185
+ lastArgs = null;
186
+ fn.apply(this, args);
187
+ } else {
188
+ lastArgs = args;
189
+ if (!timer) {
190
+ timer = setTimeout(() => {
191
+ lastTime = Date.now();
192
+ timer = null;
193
+ if (lastArgs) {
194
+ fn.apply(this, lastArgs);
195
+ lastArgs = null;
196
+ }
197
+ }, remaining);
198
+ }
199
+ }
200
+ };
201
+ return throttled;
202
+ }
203
+ function memoize(fn, resolver) {
204
+ const cache = /* @__PURE__ */ new Map();
205
+ const memoized = function(...args) {
206
+ const key = resolver ? resolver(...args) : String(args[0]);
207
+ if (cache.has(key)) {
208
+ return cache.get(key);
209
+ }
210
+ const result = fn.apply(this, args);
211
+ cache.set(key, result);
212
+ return result;
213
+ };
214
+ memoized.cache = cache;
215
+ return memoized;
216
+ }
217
+ function retry(fn, options) {
218
+ const {
219
+ attempts = 3,
220
+ baseDelay = 1e3,
221
+ maxDelay = 3e4,
222
+ shouldRetry = () => true
223
+ } = options ?? {};
224
+ let attempt = 0;
225
+ const execute = () => {
226
+ attempt++;
227
+ return fn().catch((error) => {
228
+ if (attempt >= attempts || !shouldRetry(error)) {
229
+ throw error;
230
+ }
231
+ const delay = Math.min(
232
+ baseDelay * Math.pow(2, attempt - 1) + Math.random() * baseDelay,
233
+ maxDelay
234
+ );
235
+ return new Promise((resolve2) => {
236
+ setTimeout(() => {
237
+ resolve2(execute());
238
+ }, delay);
239
+ });
240
+ });
241
+ };
242
+ return execute();
243
+ }
244
+ function noop() {
245
+ return void 0;
246
+ }
247
+ function identity(value) {
248
+ return value;
249
+ }
250
+ function once(fn) {
251
+ let called = false;
252
+ let result;
253
+ return function(...args) {
254
+ if (!called) {
255
+ called = true;
256
+ result = fn.apply(this, args);
257
+ }
258
+ return result;
259
+ };
260
+ }
261
+
262
+ // src/math/index.ts
263
+ var DivisionByZeroError = class extends Error {
264
+ constructor() {
265
+ super("Division by zero");
266
+ this.name = "DivisionByZeroError";
267
+ }
268
+ };
269
+ function getPrecision(value) {
270
+ if (!isFinite(value)) return 0;
271
+ const eIndex = String(value).indexOf("e");
272
+ if (eIndex > -1) {
273
+ const exp = parseInt(String(value).slice(eIndex + 1), 10);
274
+ if (exp < 0) return Math.abs(exp);
275
+ return 0;
276
+ }
277
+ const str = String(value);
278
+ const dot = str.indexOf(".");
279
+ return dot === -1 ? 0 : str.length - dot - 1;
280
+ }
281
+ function toPrecisionFactor(a, b) {
282
+ return Math.pow(10, Math.max(getPrecision(a), getPrecision(b)));
283
+ }
284
+ function add(a, b) {
285
+ const factor = toPrecisionFactor(a, b);
286
+ return (Math.round(a * factor) + Math.round(b * factor)) / factor;
287
+ }
288
+ function sub(a, b) {
289
+ const factor = toPrecisionFactor(a, b);
290
+ return (Math.round(a * factor) - Math.round(b * factor)) / factor;
291
+ }
292
+ function mul(a, b) {
293
+ const factorA = toPrecisionFactor(a, 1);
294
+ const factorB = toPrecisionFactor(1, b);
295
+ const result = Math.round(a * factorA) * Math.round(b * factorB) / (factorA * factorB);
296
+ return result;
297
+ }
298
+ function div(a, b) {
299
+ if (b === 0) throw new DivisionByZeroError();
300
+ const factor = toPrecisionFactor(a, b);
301
+ return Math.round(a * factor) / Math.round(b * factor);
302
+ }
303
+ function round(value, precision = 0) {
304
+ const factor = Math.pow(10, precision);
305
+ return Math.round(value * factor) / factor;
306
+ }
307
+ function floor(value, precision = 0) {
308
+ const factor = Math.pow(10, precision);
309
+ return Math.floor(value * factor) / factor;
310
+ }
311
+ function ceil(value, precision = 0) {
312
+ const factor = Math.pow(10, precision);
313
+ return Math.ceil(value * factor) / factor;
314
+ }
315
+ function approxEqual(a, b, tolerance = Number.EPSILON) {
316
+ return Math.abs(a - b) <= tolerance;
317
+ }
318
+ function clamp(value, min, max) {
319
+ if (min > max) {
320
+ throw new RangeError("Minimum value cannot exceed maximum value");
321
+ }
322
+ return Math.min(Math.max(value, min), max);
323
+ }
324
+ function sum(values) {
325
+ let total = 0;
326
+ for (let i = 0; i < values.length; i++) {
327
+ total += values[i];
328
+ }
329
+ return total;
330
+ }
331
+ function average(values) {
332
+ if (values.length === 0) {
333
+ throw new RangeError("Cannot compute average of an empty array");
334
+ }
335
+ return sum(values) / values.length;
336
+ }
337
+ function randomInt(min, max) {
338
+ if (!Number.isInteger(min) || !Number.isInteger(max)) {
339
+ throw new RangeError("Arguments must be integers");
340
+ }
341
+ if (min > max) {
342
+ throw new RangeError("Minimum value cannot exceed maximum value");
343
+ }
344
+ return Math.floor(Math.random() * (max - min + 1)) + min;
345
+ }
346
+ function inRange(value, min, max) {
347
+ return value >= min && value <= max;
348
+ }
349
+
350
+ // src/date/index.ts
351
+ var InvalidDateError = class extends Error {
352
+ constructor(input) {
353
+ super(`Invalid date: ${String(input)}`);
354
+ this.name = "InvalidDateError";
355
+ }
356
+ };
357
+ var MONTH_NAMES_SHORT = [
358
+ "Jan",
359
+ "Feb",
360
+ "Mar",
361
+ "Apr",
362
+ "May",
363
+ "Jun",
364
+ "Jul",
365
+ "Aug",
366
+ "Sep",
367
+ "Oct",
368
+ "Nov",
369
+ "Dec"
370
+ ];
371
+ var MONTH_NAMES_FULL = [
372
+ "January",
373
+ "February",
374
+ "March",
375
+ "April",
376
+ "May",
377
+ "June",
378
+ "July",
379
+ "August",
380
+ "September",
381
+ "October",
382
+ "November",
383
+ "December"
384
+ ];
385
+ var MONTH_MAP = {
386
+ jan: 0,
387
+ january: 0,
388
+ feb: 1,
389
+ february: 1,
390
+ mar: 2,
391
+ march: 2,
392
+ apr: 3,
393
+ april: 3,
394
+ may: 4,
395
+ jun: 5,
396
+ june: 5,
397
+ jul: 6,
398
+ july: 6,
399
+ aug: 7,
400
+ august: 7,
401
+ sep: 8,
402
+ september: 8,
403
+ oct: 9,
404
+ october: 9,
405
+ nov: 10,
406
+ november: 10,
407
+ dec: 11,
408
+ december: 11
409
+ };
410
+ function formatDate(date, format2 = "YYYY-MM-DD") {
411
+ const year = date.getFullYear();
412
+ const month = date.getMonth();
413
+ const day = date.getDate();
414
+ const hours = date.getHours();
415
+ const minutes = date.getMinutes();
416
+ const seconds = date.getSeconds();
417
+ const ms = date.getMilliseconds();
418
+ const pad2 = (n, len = 2) => String(n).padStart(len, "0");
419
+ return format2.replace(/YYYY/g, String(year)).replace(/YY/g, String(year).slice(-2)).replace(/MMMM/g, MONTH_NAMES_FULL[month]).replace(/MMM/g, MONTH_NAMES_SHORT[month]).replace(/MM/g, pad2(month + 1)).replace(/DD/g, pad2(day)).replace(/HH/g, pad2(hours)).replace(/mm/g, pad2(minutes)).replace(/ss/g, pad2(seconds)).replace(/SSS/g, pad2(ms, 3));
420
+ }
421
+ function parseDate(input) {
422
+ if (input instanceof Date) {
423
+ if (isNaN(input.getTime())) throw new InvalidDateError(input);
424
+ return new Date(input.getTime());
425
+ }
426
+ if (typeof input === "number") {
427
+ const d = new Date(input);
428
+ if (isNaN(d.getTime())) throw new InvalidDateError(input);
429
+ return d;
430
+ }
431
+ const trimmed = input.trim();
432
+ const isoMatch = trimmed.match(/^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2}):(\d{2})(?:\.(\d+))?)?(?:Z|[+-]\d{2}:?\d{2})?$/);
433
+ if (isoMatch) {
434
+ const d = new Date(
435
+ parseInt(isoMatch[1], 10),
436
+ parseInt(isoMatch[2], 10) - 1,
437
+ parseInt(isoMatch[3], 10),
438
+ isoMatch[4] ? parseInt(isoMatch[4], 10) : 0,
439
+ isoMatch[5] ? parseInt(isoMatch[5], 10) : 0,
440
+ isoMatch[6] ? parseInt(isoMatch[6], 10) : 0,
441
+ isoMatch[7] ? parseInt(isoMatch[7].padEnd(3, "0"), 10) : 0
442
+ );
443
+ if (!isNaN(d.getTime())) return d;
444
+ }
445
+ const dmyMatch = trimmed.match(/^(\d{1,2})[\/-](\d{1,2})[\/-](\d{4})$/);
446
+ if (dmyMatch) {
447
+ const d = new Date(
448
+ parseInt(dmyMatch[3], 10),
449
+ parseInt(dmyMatch[2], 10) - 1,
450
+ parseInt(dmyMatch[1], 10)
451
+ );
452
+ if (!isNaN(d.getTime())) return d;
453
+ }
454
+ const textMatch = trimmed.match(/^(\d{1,2})\s+([a-zA-Z]+)\s+(\d{4})$/);
455
+ if (textMatch) {
456
+ const monthIndex = MONTH_MAP[textMatch[2].toLowerCase()];
457
+ if (monthIndex !== void 0) {
458
+ const d = new Date(
459
+ parseInt(textMatch[3], 10),
460
+ monthIndex,
461
+ parseInt(textMatch[1], 10)
462
+ );
463
+ if (!isNaN(d.getTime())) return d;
464
+ }
465
+ }
466
+ const numMatch = trimmed.match(/^-?\d+$/);
467
+ if (numMatch) {
468
+ const d = new Date(parseInt(numMatch[0], 10));
469
+ if (!isNaN(d.getTime())) return d;
470
+ }
471
+ const fallback = new Date(trimmed);
472
+ if (!isNaN(fallback.getTime())) return fallback;
473
+ throw new InvalidDateError(input);
474
+ }
475
+ function isValidDate(d) {
476
+ return d instanceof Date && !isNaN(d.getTime());
477
+ }
478
+ var MS_IN_SECOND = 1e3;
479
+ var MS_IN_MINUTE = 60 * MS_IN_SECOND;
480
+ var MS_IN_HOUR = 60 * MS_IN_MINUTE;
481
+ var MS_IN_DAY = 24 * MS_IN_HOUR;
482
+ function dateDiff(date1, date2) {
483
+ if (!isValidDate(date1) || !isValidDate(date2)) {
484
+ throw new InvalidDateError("Invalid date provided to dateDiff");
485
+ }
486
+ let years = date2.getFullYear() - date1.getFullYear();
487
+ let months = date2.getMonth() - date1.getMonth();
488
+ let days = date2.getDate() - date1.getDate();
489
+ if (days < 0) {
490
+ months -= 1;
491
+ const prevMonth = new Date(date2.getFullYear(), date2.getMonth(), 0);
492
+ days += prevMonth.getDate();
493
+ }
494
+ if (months < 0) {
495
+ years -= 1;
496
+ months += 12;
497
+ }
498
+ const msDiff = Math.abs(date2.getTime() - date1.getTime());
499
+ const totalSeconds = Math.floor(msDiff / MS_IN_SECOND);
500
+ const hours = Math.floor(msDiff % MS_IN_DAY / MS_IN_HOUR);
501
+ const minutes = Math.floor(msDiff % MS_IN_HOUR / MS_IN_MINUTE);
502
+ const seconds = totalSeconds % 60;
503
+ return { years, months, days, hours, minutes, seconds };
504
+ }
505
+ function addDays(date, days) {
506
+ if (!isValidDate(date)) throw new InvalidDateError(date);
507
+ const result = new Date(date.getTime());
508
+ result.setDate(result.getDate() + days);
509
+ return result;
510
+ }
511
+ function addMonths(date, months) {
512
+ if (!isValidDate(date)) throw new InvalidDateError(date);
513
+ const result = new Date(date.getTime());
514
+ const targetMonth = result.getMonth() + months;
515
+ result.setMonth(targetMonth);
516
+ if (result.getMonth() !== (targetMonth % 12 + 12) % 12) {
517
+ result.setDate(0);
518
+ }
519
+ return result;
520
+ }
521
+ function addYears(date, years) {
522
+ if (!isValidDate(date)) throw new InvalidDateError(date);
523
+ const result = new Date(date.getTime());
524
+ const targetYear = result.getFullYear() + years;
525
+ result.setFullYear(targetYear);
526
+ if (result.getFullYear() !== targetYear) {
527
+ result.setDate(0);
528
+ }
529
+ return result;
530
+ }
531
+ function startOfDay(date) {
532
+ if (!isValidDate(date)) throw new InvalidDateError(date);
533
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0, 0, 0, 0);
534
+ }
535
+ function endOfDay(date) {
536
+ if (!isValidDate(date)) throw new InvalidDateError(date);
537
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 23, 59, 59, 999);
538
+ }
539
+ function startOfMonth(date) {
540
+ if (!isValidDate(date)) throw new InvalidDateError(date);
541
+ return new Date(date.getFullYear(), date.getMonth(), 1, 0, 0, 0, 0);
542
+ }
543
+ function endOfMonth(date) {
544
+ if (!isValidDate(date)) throw new InvalidDateError(date);
545
+ return new Date(date.getFullYear(), date.getMonth() + 1, 0, 23, 59, 59, 999);
546
+ }
547
+ function startOfYear(date) {
548
+ if (!isValidDate(date)) throw new InvalidDateError(date);
549
+ return new Date(date.getFullYear(), 0, 1, 0, 0, 0, 0);
550
+ }
551
+ function endOfYear(date) {
552
+ if (!isValidDate(date)) throw new InvalidDateError(date);
553
+ return new Date(date.getFullYear(), 12, 0, 23, 59, 59, 999);
554
+ }
555
+ function isWeekend(date) {
556
+ if (!isValidDate(date)) throw new InvalidDateError(date);
557
+ const day = date.getDay();
558
+ return day === 0 || day === 6;
559
+ }
560
+ function isLeapYear(year) {
561
+ return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
562
+ }
563
+ function isBefore(date1, date2) {
564
+ if (!isValidDate(date1) || !isValidDate(date2)) {
565
+ throw new InvalidDateError("Invalid date provided to isBefore");
566
+ }
567
+ return date1.getTime() < date2.getTime();
568
+ }
569
+ function isAfter(date1, date2) {
570
+ if (!isValidDate(date1) || !isValidDate(date2)) {
571
+ throw new InvalidDateError("Invalid date provided to isAfter");
572
+ }
573
+ return date1.getTime() > date2.getTime();
574
+ }
575
+ function isBetween(date, start, end) {
576
+ if (!isValidDate(date) || !isValidDate(start) || !isValidDate(end)) {
577
+ throw new InvalidDateError("Invalid date provided to isBetween");
578
+ }
579
+ return date.getTime() >= start.getTime() && date.getTime() <= end.getTime();
580
+ }
581
+ function isBusinessDay(date) {
582
+ return isValidDate(date) && !isWeekend(date);
583
+ }
584
+ function addBusinessDays(date, days) {
585
+ if (!isValidDate(date)) throw new InvalidDateError(date);
586
+ const result = new Date(date.getTime());
587
+ let remaining = Math.abs(days);
588
+ const step = days >= 0 ? 1 : -1;
589
+ while (remaining > 0) {
590
+ result.setDate(result.getDate() + step);
591
+ const day = result.getDay();
592
+ if (day !== 0 && day !== 6) {
593
+ remaining--;
594
+ }
595
+ }
596
+ return result;
597
+ }
598
+ function calculateAge(birthDate) {
599
+ if (!isValidDate(birthDate)) throw new InvalidDateError(birthDate);
600
+ const today = /* @__PURE__ */ new Date();
601
+ let age = today.getFullYear() - birthDate.getFullYear();
602
+ const monthDiff = today.getMonth() - birthDate.getMonth();
603
+ if (monthDiff < 0 || monthDiff === 0 && today.getDate() < birthDate.getDate()) {
604
+ age--;
605
+ }
606
+ return age;
607
+ }
608
+
609
+ // src/crypto/index.ts
610
+ function hash(str) {
611
+ let h = 5381;
612
+ for (let i = 0; i < str.length; i++) {
613
+ h = (h << 5) + h + str.charCodeAt(i) | 0;
614
+ }
615
+ return h >>> 0;
616
+ }
617
+ function simpleHash(str) {
618
+ let h1 = 1732584193;
619
+ let h2 = 4023233417;
620
+ let h3 = 2562383102;
621
+ let h4 = 271733878;
622
+ for (let i = 0; i < str.length; i++) {
623
+ const c = str.charCodeAt(i);
624
+ h1 = h1 + c | 0;
625
+ h2 = h2 + (c << 3) + i | 0;
626
+ h3 = h3 ^ c | 0;
627
+ h4 = h4 + (c << 5) + (c << 1) | 0;
628
+ }
629
+ const toHex = (n) => (n >>> 0).toString(16).padStart(8, "0");
630
+ return toHex(h1) + toHex(h2) + toHex(h3) + toHex(h4);
631
+ }
632
+ function getRandomBytes(size) {
633
+ const bytes = new Uint8Array(size);
634
+ if (typeof crypto !== "undefined" && typeof crypto.getRandomValues === "function") {
635
+ crypto.getRandomValues(bytes);
636
+ } else {
637
+ for (let i = 0; i < size; i++) {
638
+ bytes[i] = Math.floor(Math.random() * 256);
639
+ }
640
+ }
641
+ return bytes;
642
+ }
643
+ function randomHex(size = 16) {
644
+ const bytes = getRandomBytes(size);
645
+ let result = "";
646
+ for (let i = 0; i < bytes.length; i++) {
647
+ result += bytes[i].toString(16).padStart(2, "0");
648
+ }
649
+ return result;
650
+ }
651
+ function utf8ToBytes(str) {
652
+ if (typeof TextEncoder !== "undefined") {
653
+ return new TextEncoder().encode(str);
654
+ }
655
+ const bytes = new Uint8Array(str.length);
656
+ for (let i = 0; i < str.length; i++) {
657
+ bytes[i] = str.charCodeAt(i);
658
+ }
659
+ return bytes;
660
+ }
661
+ function bytesToUtf8(bytes) {
662
+ if (typeof TextDecoder !== "undefined") {
663
+ return new TextDecoder().decode(bytes);
664
+ }
665
+ let result = "";
666
+ for (let i = 0; i < bytes.length; i++) {
667
+ result += String.fromCharCode(bytes[i]);
668
+ }
669
+ return result;
670
+ }
671
+ function bytesToBase64(bytes) {
672
+ let binary = "";
673
+ for (let i = 0; i < bytes.length; i++) {
674
+ binary += String.fromCharCode(bytes[i]);
675
+ }
676
+ if (typeof btoa === "function") {
677
+ return btoa(binary);
678
+ }
679
+ return Buffer.from(binary, "latin1").toString("base64");
680
+ }
681
+ function base64ToBytes(str) {
682
+ let binary;
683
+ if (typeof atob === "function") {
684
+ binary = atob(str);
685
+ } else {
686
+ binary = Buffer.from(str, "base64").toString("latin1");
687
+ }
688
+ const bytes = new Uint8Array(binary.length);
689
+ for (let i = 0; i < binary.length; i++) {
690
+ bytes[i] = binary.charCodeAt(i);
691
+ }
692
+ return bytes;
693
+ }
694
+ function base64Encode(str) {
695
+ const bytes = utf8ToBytes(str);
696
+ return bytesToBase64(bytes);
697
+ }
698
+ function base64Decode(str) {
699
+ const bytes = base64ToBytes(str);
700
+ return bytesToUtf8(bytes);
701
+ }
702
+ function generateToken(bytes = 32) {
703
+ return randomHex(bytes);
704
+ }
705
+ function generateOTP(length = 6) {
706
+ const bytes = getRandomBytes(length);
707
+ let otp = "";
708
+ for (let i = 0; i < length; i++) {
709
+ otp += (bytes[i] % 10).toString();
710
+ }
711
+ return otp;
712
+ }
713
+ function xorCipher(str, key) {
714
+ let result = "";
715
+ for (let i = 0; i < str.length; i++) {
716
+ const code = str.charCodeAt(i) ^ key.charCodeAt(i % key.length);
717
+ result += String.fromCharCode(code);
718
+ }
719
+ return result;
720
+ }
721
+ function checksum(input) {
722
+ let crc = 4294967295;
723
+ for (let i = 0; i < input.length; i++) {
724
+ crc ^= input.charCodeAt(i);
725
+ for (let j = 0; j < 8; j++) {
726
+ if (crc & 1) {
727
+ crc = crc >>> 1 ^ 3988292384;
728
+ } else {
729
+ crc = crc >>> 1;
730
+ }
731
+ }
732
+ }
733
+ return ((crc ^ 4294967295) >>> 0).toString(16).padStart(8, "0");
734
+ }
735
+ function constantTimeEqual(a, b) {
736
+ if (a.length !== b.length) return false;
737
+ let result = 0;
738
+ for (let i = 0; i < a.length; i++) {
739
+ result |= a.charCodeAt(i) ^ b.charCodeAt(i);
740
+ }
741
+ return result === 0;
742
+ }
743
+
744
+ // src/path/index.ts
745
+ var SEP = "/";
746
+ function join(...segments) {
747
+ const parts = [];
748
+ for (const seg of segments) {
749
+ if (seg === "") continue;
750
+ const split = seg.split(/[\\/]/);
751
+ for (const part of split) {
752
+ if (part === "" || part === ".") continue;
753
+ if (part === "..") {
754
+ if (parts.length > 0 && parts[parts.length - 1] !== "..") {
755
+ parts.pop();
756
+ } else {
757
+ parts.push("..");
758
+ }
759
+ } else {
760
+ parts.push(part);
761
+ }
762
+ }
763
+ }
764
+ if (parts.length === 0) return ".";
765
+ const result = parts.join(SEP);
766
+ if (segments.length > 0 && segments[0].startsWith("/")) {
767
+ return SEP + result;
768
+ }
769
+ return result;
770
+ }
771
+ function resolve(...segments) {
772
+ let resolved = "";
773
+ let isAbs = false;
774
+ for (const seg of segments) {
775
+ if (seg.startsWith("/")) {
776
+ resolved = seg;
777
+ isAbs = true;
778
+ } else if (isAbs) {
779
+ resolved = join(resolved, seg);
780
+ } else {
781
+ resolved = resolved ? join(resolved, seg) : seg;
782
+ }
783
+ }
784
+ if (!isAbs) {
785
+ resolved = join(SEP, resolved);
786
+ }
787
+ return normalize(resolved);
788
+ }
789
+ function basename(p, ext) {
790
+ const normalized = p.replace(/[\\/]+$/, "");
791
+ const idx = normalized.lastIndexOf(SEP);
792
+ let base = idx === -1 ? normalized : normalized.slice(idx + 1);
793
+ if (ext && base.endsWith(ext)) {
794
+ base = base.slice(0, -ext.length);
795
+ }
796
+ return base;
797
+ }
798
+ function dirname(p) {
799
+ if (p === SEP) return SEP;
800
+ const normalized = p.replace(/[\\/]+$/, "");
801
+ if (normalized === "") return ".";
802
+ const idx = normalized.lastIndexOf(SEP);
803
+ if (idx === -1) return ".";
804
+ if (idx === 0) return SEP;
805
+ return normalized.slice(0, idx);
806
+ }
807
+ function extname(p) {
808
+ const base = basename(p);
809
+ const idx = base.lastIndexOf(".");
810
+ if (idx === -1 || idx === 0) return "";
811
+ return base.slice(idx);
812
+ }
813
+ function normalize(p) {
814
+ const parts = p.split(/[\\/]+/);
815
+ const stack = [];
816
+ let isAbs = p.startsWith("/");
817
+ for (const part of parts) {
818
+ if (part === "" || part === ".") continue;
819
+ if (part === "..") {
820
+ if (stack.length > 0 && stack[stack.length - 1] !== "..") {
821
+ stack.pop();
822
+ } else if (!isAbs) {
823
+ stack.push("..");
824
+ }
825
+ } else {
826
+ stack.push(part);
827
+ }
828
+ }
829
+ const result = stack.join(SEP);
830
+ if (isAbs) return SEP + result;
831
+ if (result === "") return ".";
832
+ return result;
833
+ }
834
+ function isAbsolute(p) {
835
+ return p.startsWith("/");
836
+ }
837
+ function relative(from, to) {
838
+ const fromParts = normalize(from).split(SEP);
839
+ const toParts = normalize(to).split(SEP);
840
+ let i = 0;
841
+ while (i < fromParts.length && i < toParts.length && fromParts[i] === toParts[i]) {
842
+ i++;
843
+ }
844
+ const up = fromParts.slice(i).map(() => "..");
845
+ const down = toParts.slice(i);
846
+ const result = [...up, ...down].join(SEP);
847
+ return result || ".";
848
+ }
849
+ function parse(p) {
850
+ const root = p.startsWith(SEP) ? SEP : "";
851
+ const base = basename(p);
852
+ const ext = extname(base);
853
+ const name = ext ? base.slice(0, -ext.length) : base;
854
+ const dir = root ? dirname(p) : dirname(p) === "." ? "" : dirname(p);
855
+ return { root, dir, base, name, ext };
856
+ }
857
+ function format(parsed) {
858
+ const { root = "", dir = "", base = "", name = "", ext = "" } = parsed;
859
+ const baseName = base || name + ext;
860
+ if (dir) {
861
+ return dir + SEP + baseName;
862
+ }
863
+ return root + baseName;
864
+ }
865
+
866
+ // src/collection/index.ts
867
+ function groupBy(items, keyFn) {
868
+ const result = {};
869
+ for (const item of items) {
870
+ const key = keyFn(item);
871
+ if (!result[key]) result[key] = [];
872
+ result[key].push(item);
873
+ }
874
+ return result;
875
+ }
876
+ function keyBy(items, keyFn) {
877
+ const result = {};
878
+ for (const item of items) {
879
+ const key = keyFn(item);
880
+ result[key] = item;
881
+ }
882
+ return result;
883
+ }
884
+ function omit(obj, keys) {
885
+ const result = { ...obj };
886
+ for (const key of keys) {
887
+ delete result[key];
888
+ }
889
+ return result;
890
+ }
891
+ function pick(obj, keys) {
892
+ const result = {};
893
+ for (const key of keys) {
894
+ if (key in obj) {
895
+ result[key] = obj[key];
896
+ }
897
+ }
898
+ return result;
899
+ }
900
+ function pluck(items, key) {
901
+ return items.map((item) => item[key]);
902
+ }
903
+ function shuffle(items) {
904
+ const result = [...items];
905
+ for (let i = result.length - 1; i > 0; i--) {
906
+ const j = Math.floor(Math.random() * (i + 1));
907
+ const temp = result[i];
908
+ result[i] = result[j];
909
+ result[j] = temp;
910
+ }
911
+ return result;
912
+ }
913
+ function sample(items) {
914
+ return items.length > 0 ? items[Math.floor(Math.random() * items.length)] : void 0;
915
+ }
916
+ function sampleSize(items, size) {
917
+ if (size <= 0 || items.length === 0) return [];
918
+ const pool = shuffle(items);
919
+ return pool.slice(0, Math.min(size, items.length));
920
+ }
921
+ function chunk(items, size) {
922
+ if (size <= 0 || items.length === 0) return [];
923
+ const result = [];
924
+ for (let i = 0; i < items.length; i += size) {
925
+ result.push(items.slice(i, i + size));
926
+ }
927
+ return result;
928
+ }
929
+ function compareValues(a, b) {
930
+ if (a === b) return 0;
931
+ if (a == null) return -1;
932
+ if (b == null) return 1;
933
+ if (typeof a === "string" && typeof b === "string") return a < b ? -1 : 1;
934
+ if (typeof a === "number" && typeof b === "number") return a < b ? -1 : 1;
935
+ return String(a) < String(b) ? -1 : 1;
936
+ }
937
+ function sortBy(items, ...criteria) {
938
+ return [...items].sort((a, b) => {
939
+ for (const criterion of criteria) {
940
+ const cmp = compareValues(criterion(a), criterion(b));
941
+ if (cmp !== 0) return cmp;
942
+ }
943
+ return 0;
944
+ });
945
+ }
946
+ function orderBy(items, key, direction = "asc") {
947
+ return [...items].sort((a, b) => {
948
+ const cmp = compareValues(key(a), key(b));
949
+ return direction === "asc" ? cmp : -cmp;
950
+ });
951
+ }
952
+ function uniqueBy(items, keyFn) {
953
+ const seen = /* @__PURE__ */ new Set();
954
+ return items.filter((item) => {
955
+ const key = keyFn(item);
956
+ if (seen.has(key)) return false;
957
+ seen.add(key);
958
+ return true;
959
+ });
960
+ }
961
+ function flatten(items) {
962
+ const result = [];
963
+ for (const sub2 of items) {
964
+ for (const item of sub2) {
965
+ result.push(item);
966
+ }
967
+ }
968
+ return result;
969
+ }
970
+ function uniq(items) {
971
+ return [...new Set(items)];
972
+ }
973
+ function first(items) {
974
+ return items[0];
975
+ }
976
+ function last(items) {
977
+ return items[items.length - 1];
978
+ }
979
+ function isEmpty(value) {
980
+ if (Array.isArray(value)) return value.length === 0;
981
+ if (typeof value === "string") return value.length === 0;
982
+ if (value instanceof Map || value instanceof Set) return value.size === 0;
983
+ if (value !== null && typeof value === "object") return Object.keys(value).length === 0;
984
+ return false;
985
+ }
986
+
987
+ // src/string/index.ts
988
+ var WORD_SPLIT_RE = /[A-Z]?[a-z]+|[A-Z]+(?=[A-Z][a-z]|\d|\b)|\d+/g;
989
+ function splitWords(str) {
990
+ return str.match(WORD_SPLIT_RE) ?? [];
991
+ }
992
+ function capitalize(str) {
993
+ if (str.length === 0) return str;
994
+ return str[0].toUpperCase() + str.slice(1).toLowerCase();
995
+ }
996
+ function camelCase(str) {
997
+ const words2 = splitWords(str);
998
+ if (words2.length === 0) return "";
999
+ const [firstWord, ...rest] = words2;
1000
+ return firstWord.toLowerCase() + rest.map((w) => w[0].toUpperCase() + w.slice(1).toLowerCase()).join("");
1001
+ }
1002
+ function kebabCase(str) {
1003
+ return splitWords(str).map((w) => w.toLowerCase()).join("-");
1004
+ }
1005
+ function snakeCase(str) {
1006
+ return splitWords(str).map((w) => w.toLowerCase()).join("_");
1007
+ }
1008
+ function pascalCase(str) {
1009
+ return splitWords(str).map((w) => w[0].toUpperCase() + w.slice(1).toLowerCase()).join("");
1010
+ }
1011
+ function truncate(str, maxLength, suffix = "...") {
1012
+ if (str.length <= maxLength) return str;
1013
+ return str.slice(0, Math.max(0, maxLength - suffix.length)) + suffix;
1014
+ }
1015
+ function template(str, data) {
1016
+ return str.replace(/\{\{(\w+)\}\}/g, (_, key) => {
1017
+ const value = data[key];
1018
+ return value !== void 0 ? String(value) : `{{${key}}}`;
1019
+ });
1020
+ }
1021
+ function uuid() {
1022
+ if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
1023
+ return crypto.randomUUID();
1024
+ }
1025
+ const hex = "0123456789abcdef";
1026
+ const chars = [];
1027
+ for (let i = 0; i < 36; i++) {
1028
+ if (i === 8 || i === 13 || i === 18 || i === 23) {
1029
+ chars.push("-");
1030
+ } else if (i === 14) {
1031
+ chars.push("4");
1032
+ } else if (i === 19) {
1033
+ chars.push(hex[Math.floor(Math.random() * 4) + 8]);
1034
+ } else {
1035
+ chars.push(hex[Math.floor(Math.random() * 16)]);
1036
+ }
1037
+ }
1038
+ return chars.join("");
1039
+ }
1040
+ function nanoid(size = 21, alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_-") {
1041
+ const len = alphabet.length;
1042
+ let result = "";
1043
+ for (let i = 0; i < size; i++) {
1044
+ result += alphabet[Math.floor(Math.random() * len)];
1045
+ }
1046
+ return result;
1047
+ }
1048
+ var HTML_ESCAPE_MAP = {
1049
+ "&": "&amp;",
1050
+ "<": "&lt;",
1051
+ ">": "&gt;",
1052
+ '"': "&quot;",
1053
+ "'": "&#39;"
1054
+ };
1055
+ var HTML_UNESCAPE_MAP = {
1056
+ "&amp;": "&",
1057
+ "&lt;": "<",
1058
+ "&gt;": ">",
1059
+ "&quot;": '"',
1060
+ "&#39;": "'",
1061
+ "&#x27;": "'"
1062
+ };
1063
+ function escapeHtml(str) {
1064
+ return str.replace(/[&<>"']/g, (ch) => HTML_ESCAPE_MAP[ch] ?? ch);
1065
+ }
1066
+ function unescapeHtml(str) {
1067
+ return str.replace(/&(?:amp|lt|gt|quot|#39|#x27);/g, (entity) => HTML_UNESCAPE_MAP[entity] ?? entity);
1068
+ }
1069
+ function trim(str) {
1070
+ return str.trim();
1071
+ }
1072
+ function trimStart(str) {
1073
+ return str.trimStart();
1074
+ }
1075
+ function trimEnd(str) {
1076
+ return str.trimEnd();
1077
+ }
1078
+ function pad(str, length, char = " ") {
1079
+ const totalPadding = Math.max(0, length - str.length);
1080
+ const leftPad = Math.floor(totalPadding / 2);
1081
+ const rightPad = totalPadding - leftPad;
1082
+ return char.repeat(leftPad) + str + char.repeat(rightPad);
1083
+ }
1084
+ function padStart(str, length, char = " ") {
1085
+ return str.padStart(length, char);
1086
+ }
1087
+ function padEnd(str, length, char = " ") {
1088
+ return str.padEnd(length, char);
1089
+ }
1090
+ function reverse(str) {
1091
+ return str.split("").reverse().join("");
1092
+ }
1093
+ function words(str) {
1094
+ return splitWords(str);
1095
+ }
1096
+ function slugify(str) {
1097
+ return str.toLowerCase().replace(/[^\w\s-]/g, "").replace(/[\s_]+/g, "-").replace(/-+/g, "-").replace(/^-+/, "").replace(/-+$/, "");
1098
+ }
1099
+ function countOccurrences(str, substring) {
1100
+ if (substring.length === 0 || str.length === 0) return 0;
1101
+ let count = 0;
1102
+ let pos = 0;
1103
+ while ((pos = str.indexOf(substring, pos)) !== -1) {
1104
+ count++;
1105
+ pos += substring.length;
1106
+ }
1107
+ return count;
1108
+ }
1109
+
1110
+ // src/async/index.ts
1111
+ function sleep(ms) {
1112
+ return new Promise((resolve2) => setTimeout(resolve2, ms));
1113
+ }
1114
+ async function timeout(promise, ms, errorMessage) {
1115
+ let timer;
1116
+ const timeoutPromise = new Promise((_, reject) => {
1117
+ timer = setTimeout(() => reject(new Error(errorMessage ?? `Promise timed out after ${ms}ms`)), ms);
1118
+ });
1119
+ try {
1120
+ return await Promise.race([promise, timeoutPromise]);
1121
+ } finally {
1122
+ if (timer !== void 0) clearTimeout(timer);
1123
+ }
1124
+ }
1125
+ async function raceWithTimeout(promise, ms) {
1126
+ let timer;
1127
+ const timeoutPromise = new Promise((resolve2) => {
1128
+ timer = setTimeout(() => resolve2("timeout"), ms);
1129
+ });
1130
+ try {
1131
+ return await Promise.race([promise, timeoutPromise]);
1132
+ } finally {
1133
+ if (timer !== void 0) clearTimeout(timer);
1134
+ }
1135
+ }
1136
+ async function allSettledMap(items, fn) {
1137
+ return await Promise.allSettled(items.map(fn));
1138
+ }
1139
+ async function parallelMap(items, fn, concurrency = Number.POSITIVE_INFINITY) {
1140
+ if (concurrency === Number.POSITIVE_INFINITY) {
1141
+ return await Promise.all(items.map(fn));
1142
+ }
1143
+ const results = [];
1144
+ const queue = [...items];
1145
+ const worker = async () => {
1146
+ while (queue.length > 0) {
1147
+ const item = queue.shift();
1148
+ results.push(await fn(item));
1149
+ }
1150
+ };
1151
+ const workerCount = Math.min(concurrency, items.length);
1152
+ const workers = Array.from({ length: workerCount }, () => worker());
1153
+ await Promise.all(workers);
1154
+ return results;
1155
+ }
1156
+ async function retryAsync(fn, options) {
1157
+ const { attempts = 3, baseDelay = 1e3, maxDelay = 3e4, shouldRetry = () => true } = options ?? {};
1158
+ let lastError;
1159
+ for (let attempt = 0; attempt < attempts; attempt++) {
1160
+ try {
1161
+ return await fn();
1162
+ } catch (error) {
1163
+ lastError = error;
1164
+ if (!shouldRetry(error) || attempt >= attempts - 1) break;
1165
+ const delay = Math.min(baseDelay * 2 ** attempt + Math.random() * baseDelay, maxDelay);
1166
+ await sleep(delay);
1167
+ }
1168
+ }
1169
+ throw lastError;
1170
+ }
1171
+ async function pipeline(initial, ...fns) {
1172
+ let result = initial;
1173
+ for (const fn of fns) {
1174
+ result = await fn(result);
1175
+ }
1176
+ return result;
1177
+ }
1178
+ function deferred() {
1179
+ let resolve2;
1180
+ let reject;
1181
+ const promise = new Promise((res, rej) => {
1182
+ resolve2 = res;
1183
+ reject = rej;
1184
+ });
1185
+ return { promise, resolve: resolve2, reject };
1186
+ }
1187
+
1188
+ // src/io/index.ts
1189
+ function parseCsv(input, options) {
1190
+ const { delimiter = ",", header = true, skipEmptyLines = true } = options ?? {};
1191
+ const lines = input.split(/\r?\n/);
1192
+ const rows = [];
1193
+ for (const line of lines) {
1194
+ const trimmed = line.trim();
1195
+ if (skipEmptyLines && trimmed.length === 0) continue;
1196
+ const values = parseCsvLine(trimmed, delimiter);
1197
+ rows.push(values);
1198
+ }
1199
+ if (rows.length === 0) return [];
1200
+ if (header) {
1201
+ const [head, ...body] = rows;
1202
+ if (head === void 0) return [];
1203
+ return body.map((row) => {
1204
+ const record = {};
1205
+ for (let i = 0; i < head.length; i++) {
1206
+ record[head[i]] = row[i] ?? "";
1207
+ }
1208
+ return record;
1209
+ });
1210
+ }
1211
+ return rows.map((row) => {
1212
+ const record = {};
1213
+ for (let i = 0; i < row.length; i++) {
1214
+ record[String(i)] = row[i];
1215
+ }
1216
+ return record;
1217
+ });
1218
+ }
1219
+ function parseCsvLine(line, delimiter) {
1220
+ const result = [];
1221
+ let current = "";
1222
+ let inQuotes = false;
1223
+ for (let i = 0; i < line.length; i++) {
1224
+ const ch = line[i];
1225
+ if (inQuotes) {
1226
+ if (ch === '"') {
1227
+ if (line[i + 1] === '"') {
1228
+ current += '"';
1229
+ i++;
1230
+ } else {
1231
+ inQuotes = false;
1232
+ }
1233
+ } else {
1234
+ current += ch;
1235
+ }
1236
+ } else {
1237
+ if (ch === '"') {
1238
+ inQuotes = true;
1239
+ } else if (ch === delimiter) {
1240
+ result.push(current);
1241
+ current = "";
1242
+ } else {
1243
+ current += ch;
1244
+ }
1245
+ }
1246
+ }
1247
+ result.push(current);
1248
+ return result;
1249
+ }
1250
+ function stringifyCsv(data, options) {
1251
+ const { delimiter = "," } = options ?? {};
1252
+ if (data.length === 0) return "";
1253
+ const headers = Object.keys(data[0]);
1254
+ const lines = [headers.map((v) => escapeCsvField(v, delimiter)).join(delimiter)];
1255
+ for (const record of data) {
1256
+ const row = headers.map((h) => escapeCsvField(String(record[h] ?? ""), delimiter));
1257
+ lines.push(row.join(delimiter));
1258
+ }
1259
+ return lines.join("\n");
1260
+ }
1261
+ function escapeCsvField(value, delimiter) {
1262
+ if (value.includes('"') || value.includes(delimiter) || value.includes("\n") || value.includes("\r")) {
1263
+ return '"' + value.replace(/"/g, '""') + '"';
1264
+ }
1265
+ return value;
1266
+ }
1267
+ function safeJsonParse(input, default_) {
1268
+ try {
1269
+ return JSON.parse(input);
1270
+ } catch {
1271
+ return default_ ?? null;
1272
+ }
1273
+ }
1274
+ function env(name, default_) {
1275
+ const value = process.env[name];
1276
+ return value ?? default_ ?? "";
1277
+ }
1278
+ function envInt(name, default_) {
1279
+ const value = process.env[name];
1280
+ if (value === void 0 || value === "") return default_ ?? 0;
1281
+ const parsed = Number.parseInt(value, 10);
1282
+ return Number.isNaN(parsed) ? default_ ?? 0 : parsed;
1283
+ }
1284
+ function envBool(name, default_) {
1285
+ const value = process.env[name];
1286
+ if (value === void 0 || value === "") return default_ ?? false;
1287
+ return value === "true" || value === "1" || value === "yes";
1288
+ }
1289
+
1290
+ // src/type/index.ts
1291
+ function isString(value) {
1292
+ return typeof value === "string";
1293
+ }
1294
+ function isNumber(value) {
1295
+ return typeof value === "number" && Number.isFinite(value);
1296
+ }
1297
+ function isBoolean(value) {
1298
+ return typeof value === "boolean";
1299
+ }
1300
+ function isObject(value) {
1301
+ return value !== null && typeof value === "object" && !Array.isArray(value);
1302
+ }
1303
+ function isArray(value) {
1304
+ return Array.isArray(value);
1305
+ }
1306
+ function isFunction(value) {
1307
+ return typeof value === "function";
1308
+ }
1309
+ function isDate(value) {
1310
+ return value instanceof Date && !Number.isNaN(value.getTime());
1311
+ }
1312
+ function isRegExp(value) {
1313
+ return value instanceof RegExp;
1314
+ }
1315
+ function isMap(value) {
1316
+ return value instanceof Map;
1317
+ }
1318
+ function isSet(value) {
1319
+ return value instanceof Set;
1320
+ }
1321
+ function isPromise(value) {
1322
+ return value instanceof Promise;
1323
+ }
1324
+ function isNull(value) {
1325
+ return value === null;
1326
+ }
1327
+ function isUndefined(value) {
1328
+ return value === void 0;
1329
+ }
1330
+ function isNil(value) {
1331
+ return value === null || value === void 0;
1332
+ }
1333
+ function assertDefined(value, message) {
1334
+ if (value === null || value === void 0) {
1335
+ throw new Error(message ?? "Expected value to be defined");
1336
+ }
1337
+ }
1338
+ function assertType(value, guard, message) {
1339
+ if (!guard(value)) {
1340
+ throw new Error(message ?? "Value does not match expected type");
1341
+ }
1342
+ }
1343
+ function ensureArray(value) {
1344
+ return Array.isArray(value) ? value : [value];
1345
+ }
1346
+ function castArray(value) {
1347
+ return ensureArray(value);
1348
+ }
1349
+ function getType2(value) {
1350
+ if (value === null) return "null";
1351
+ if (value === void 0) return "undefined";
1352
+ if (typeof value === "string") return "string";
1353
+ if (typeof value === "boolean") return "boolean";
1354
+ if (typeof value === "function") return "function";
1355
+ if (typeof value === "number") {
1356
+ if (Number.isNaN(value)) return "nan";
1357
+ if (!Number.isFinite(value)) return "infinity";
1358
+ return "number";
1359
+ }
1360
+ if (Array.isArray(value)) return "array";
1361
+ if (value instanceof Date) return "date";
1362
+ if (value instanceof RegExp) return "regexp";
1363
+ if (value instanceof Map) return "map";
1364
+ if (value instanceof Set) return "set";
1365
+ if (value instanceof Promise) return "promise";
1366
+ return "object";
1367
+ }
1368
+ export {
1369
+ DivisionByZeroError,
1370
+ InvalidDateError,
1371
+ add,
1372
+ addBusinessDays,
1373
+ addDays,
1374
+ addMonths,
1375
+ addYears,
1376
+ allSettledMap,
1377
+ approxEqual,
1378
+ assertDefined,
1379
+ assertType,
1380
+ average,
1381
+ base64Decode,
1382
+ base64Encode,
1383
+ basename,
1384
+ calculateAge,
1385
+ camelCase,
1386
+ capitalize,
1387
+ castArray,
1388
+ ceil,
1389
+ checksum,
1390
+ chunk,
1391
+ clamp,
1392
+ constantTimeEqual,
1393
+ countOccurrences,
1394
+ dateDiff,
1395
+ debounce,
1396
+ deepClone,
1397
+ deepMerge,
1398
+ deferred,
1399
+ dirname,
1400
+ div,
1401
+ endOfDay,
1402
+ endOfMonth,
1403
+ endOfYear,
1404
+ ensureArray,
1405
+ env,
1406
+ envBool,
1407
+ envInt,
1408
+ escapeHtml,
1409
+ extname,
1410
+ first,
1411
+ flatten,
1412
+ floor,
1413
+ format,
1414
+ formatDate,
1415
+ generateOTP,
1416
+ generateToken,
1417
+ getType2 as getType,
1418
+ groupBy,
1419
+ hash,
1420
+ identity,
1421
+ inRange,
1422
+ isAbsolute,
1423
+ isAfter,
1424
+ isArray,
1425
+ isBefore,
1426
+ isBetween,
1427
+ isBoolean,
1428
+ isBusinessDay,
1429
+ isDate,
1430
+ isEmpty,
1431
+ isFunction,
1432
+ isLeapYear,
1433
+ isMap,
1434
+ isNil,
1435
+ isNull,
1436
+ isNumber,
1437
+ isObject,
1438
+ isPromise,
1439
+ isRegExp,
1440
+ isSet,
1441
+ isString,
1442
+ isUndefined,
1443
+ isWeekend,
1444
+ join,
1445
+ kebabCase,
1446
+ keyBy,
1447
+ last,
1448
+ memoize,
1449
+ mul,
1450
+ nanoid,
1451
+ noop,
1452
+ normalize,
1453
+ omit,
1454
+ once,
1455
+ orderBy,
1456
+ pad,
1457
+ padEnd,
1458
+ padStart,
1459
+ parallelMap,
1460
+ parse,
1461
+ parseCsv,
1462
+ parseDate,
1463
+ pascalCase,
1464
+ pick,
1465
+ pipeline,
1466
+ pluck,
1467
+ raceWithTimeout,
1468
+ randomHex,
1469
+ randomInt,
1470
+ relative,
1471
+ resolve,
1472
+ retry,
1473
+ retryAsync,
1474
+ reverse,
1475
+ round,
1476
+ safeJsonParse,
1477
+ sample,
1478
+ sampleSize,
1479
+ shuffle,
1480
+ simpleHash,
1481
+ sleep,
1482
+ slugify,
1483
+ snakeCase,
1484
+ sortBy,
1485
+ startOfDay,
1486
+ startOfMonth,
1487
+ startOfYear,
1488
+ stringifyCsv,
1489
+ sub,
1490
+ sum,
1491
+ template,
1492
+ throttle,
1493
+ timeout,
1494
+ trim,
1495
+ trimEnd,
1496
+ trimStart,
1497
+ truncate,
1498
+ unescapeHtml,
1499
+ uniq,
1500
+ uniqueBy,
1501
+ uuid,
1502
+ words,
1503
+ xorCipher
1504
+ };
1505
+ //# sourceMappingURL=index.js.map