@mohasinac/utils 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.cjs ADDED
@@ -0,0 +1,673 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ arrayToObject: () => arrayToObject,
24
+ booleanToString: () => booleanToString,
25
+ capitalize: () => capitalize,
26
+ capitalizeWords: () => capitalizeWords,
27
+ currentYear: () => currentYear,
28
+ dateToISOString: () => dateToISOString,
29
+ deleteCookie: () => deleteCookie,
30
+ escapeHtml: () => escapeHtml,
31
+ firestoreTimestampToDate: () => firestoreTimestampToDate,
32
+ formatCompactNumber: () => formatCompactNumber,
33
+ formatCurrency: () => formatCurrency,
34
+ formatDate: () => formatDate,
35
+ formatDateRange: () => formatDateRange,
36
+ formatDateTime: () => formatDateTime,
37
+ formatDecimal: () => formatDecimal,
38
+ formatFileSize: () => formatFileSize,
39
+ formatMonthYear: () => formatMonthYear,
40
+ formatNumber: () => formatNumber,
41
+ formatOrdinal: () => formatOrdinal,
42
+ formatPercentage: () => formatPercentage,
43
+ formatRelativeTime: () => formatRelativeTime,
44
+ formatTime: () => formatTime,
45
+ generateAuctionId: () => generateAuctionId,
46
+ generateBidId: () => generateBidId,
47
+ generateBlogPostId: () => generateBlogPostId,
48
+ generateCarouselId: () => generateCarouselId,
49
+ generateCategoryId: () => generateCategoryId,
50
+ generateCouponId: () => generateCouponId,
51
+ generateFAQId: () => generateFAQId,
52
+ generateHomepageSectionId: () => generateHomepageSectionId,
53
+ generateOrderId: () => generateOrderId,
54
+ generatePayoutId: () => generatePayoutId,
55
+ generatePreOrderId: () => generatePreOrderId,
56
+ generateProductId: () => generateProductId,
57
+ generateReviewId: () => generateReviewId,
58
+ generateUserId: () => generateUserId,
59
+ getCookie: () => getCookie,
60
+ hasCookie: () => hasCookie,
61
+ isEmptyString: () => isEmptyString,
62
+ isFuture: () => isFuture,
63
+ isPast: () => isPast,
64
+ isSameMonth: () => isSameMonth,
65
+ isToday: () => isToday,
66
+ maskString: () => maskString,
67
+ nowISO: () => nowISO,
68
+ nowMs: () => nowMs,
69
+ objectToArray: () => objectToArray,
70
+ objectToQueryString: () => objectToQueryString,
71
+ parseCookies: () => parseCookies,
72
+ parseFormattedNumber: () => parseFormattedNumber,
73
+ proseMirrorToHtml: () => proseMirrorToHtml,
74
+ queryStringToObject: () => queryStringToObject,
75
+ randomString: () => randomString,
76
+ resolveDate: () => resolveDate,
77
+ slugify: () => slugify,
78
+ stringToBoolean: () => stringToBoolean,
79
+ stripHtml: () => stripHtml,
80
+ truncate: () => truncate,
81
+ truncateWords: () => truncateWords
82
+ });
83
+ module.exports = __toCommonJS(index_exports);
84
+
85
+ // src/date.formatter.ts
86
+ function resolveDate(value) {
87
+ if (!value) return null;
88
+ if (value instanceof Date) return value;
89
+ if (typeof value === "object" && value !== null && "_seconds" in value && typeof value._seconds === "number") {
90
+ return new Date(value._seconds * 1e3);
91
+ }
92
+ const d = new Date(value);
93
+ return Number.isNaN(d.getTime()) ? null : d;
94
+ }
95
+ function formatDate(date, format = "medium", locale = "en-US") {
96
+ const dateObj = resolveDate(date);
97
+ if (!dateObj) return "";
98
+ const options = {};
99
+ switch (format) {
100
+ case "short":
101
+ options.year = "2-digit";
102
+ options.month = "numeric";
103
+ options.day = "numeric";
104
+ break;
105
+ case "medium":
106
+ options.year = "numeric";
107
+ options.month = "short";
108
+ options.day = "numeric";
109
+ break;
110
+ case "long":
111
+ options.year = "numeric";
112
+ options.month = "long";
113
+ options.day = "numeric";
114
+ break;
115
+ case "full":
116
+ options.year = "numeric";
117
+ options.month = "long";
118
+ options.day = "numeric";
119
+ options.weekday = "long";
120
+ break;
121
+ }
122
+ return dateObj.toLocaleDateString(locale, options);
123
+ }
124
+ function formatDateTime(date, format = "medium", locale = "en-US") {
125
+ const dateObj = resolveDate(date);
126
+ if (!dateObj) return "";
127
+ const dateOptions = {};
128
+ const timeOptions = {};
129
+ switch (format) {
130
+ case "short":
131
+ dateOptions.year = "2-digit";
132
+ dateOptions.month = "2-digit";
133
+ dateOptions.day = "2-digit";
134
+ timeOptions.hour = "2-digit";
135
+ timeOptions.minute = "2-digit";
136
+ break;
137
+ case "medium":
138
+ dateOptions.year = "numeric";
139
+ dateOptions.month = "short";
140
+ dateOptions.day = "numeric";
141
+ timeOptions.hour = "2-digit";
142
+ timeOptions.minute = "2-digit";
143
+ break;
144
+ case "long":
145
+ dateOptions.year = "numeric";
146
+ dateOptions.month = "long";
147
+ dateOptions.day = "numeric";
148
+ timeOptions.hour = "2-digit";
149
+ timeOptions.minute = "2-digit";
150
+ timeOptions.second = "2-digit";
151
+ break;
152
+ case "full":
153
+ dateOptions.year = "numeric";
154
+ dateOptions.month = "long";
155
+ dateOptions.day = "numeric";
156
+ dateOptions.weekday = "long";
157
+ timeOptions.hour = "2-digit";
158
+ timeOptions.minute = "2-digit";
159
+ timeOptions.second = "2-digit";
160
+ break;
161
+ }
162
+ const datePart = dateObj.toLocaleDateString(locale, dateOptions);
163
+ const timePart = dateObj.toLocaleTimeString(locale, timeOptions);
164
+ return `${datePart}, ${timePart}`;
165
+ }
166
+ function formatTime(date, format = "long", locale = "en-US") {
167
+ const dateObj = typeof date === "string" ? new Date(date) : date;
168
+ const options = format === "short" ? { hour: "2-digit", minute: "2-digit" } : { hour: "2-digit", minute: "2-digit", second: "2-digit" };
169
+ return dateObj.toLocaleTimeString(locale, options);
170
+ }
171
+ function formatRelativeTime(date) {
172
+ const dateObj = typeof date === "string" ? new Date(date) : date;
173
+ const now = /* @__PURE__ */ new Date();
174
+ const diffMs = now.getTime() - dateObj.getTime();
175
+ const diffSec = Math.floor(diffMs / 1e3);
176
+ const diffMin = Math.floor(diffSec / 60);
177
+ const diffHour = Math.floor(diffMin / 60);
178
+ const diffDay = Math.floor(diffHour / 24);
179
+ const diffWeek = Math.floor(diffDay / 7);
180
+ const diffMonth = Math.floor(diffDay / 30);
181
+ const diffYear = Math.floor(diffDay / 365);
182
+ if (diffSec < 60) return "just now";
183
+ if (diffMin < 60) return `${diffMin} minute${diffMin > 1 ? "s" : ""} ago`;
184
+ if (diffHour < 24) return `${diffHour} hour${diffHour > 1 ? "s" : ""} ago`;
185
+ if (diffDay < 7) return `${diffDay} day${diffDay > 1 ? "s" : ""} ago`;
186
+ if (diffWeek < 4) return `${diffWeek} week${diffWeek > 1 ? "s" : ""} ago`;
187
+ if (diffMonth < 12)
188
+ return `${diffMonth} month${diffMonth > 1 ? "s" : ""} ago`;
189
+ return `${diffYear} year${diffYear > 1 ? "s" : ""} ago`;
190
+ }
191
+ function formatMonthYear(date, locale = "en-US") {
192
+ const dateObj = typeof date === "string" ? new Date(date) : date;
193
+ return dateObj.toLocaleDateString(locale, { month: "long", year: "numeric" });
194
+ }
195
+ function formatDateRange(startDate, endDate, locale = "en-US") {
196
+ const start = typeof startDate === "string" ? new Date(startDate) : startDate;
197
+ const end = typeof endDate === "string" ? new Date(endDate) : endDate;
198
+ const startFormatted = start.toLocaleDateString(locale, {
199
+ month: "short",
200
+ day: "numeric",
201
+ year: start.getFullYear() !== end.getFullYear() ? "numeric" : void 0
202
+ });
203
+ const endFormatted = end.toLocaleDateString(locale, {
204
+ month: "short",
205
+ day: "numeric",
206
+ year: "numeric"
207
+ });
208
+ return `${startFormatted} - ${endFormatted}`;
209
+ }
210
+ function isToday(date) {
211
+ const dateObj = typeof date === "string" ? new Date(date) : date;
212
+ const today = /* @__PURE__ */ new Date();
213
+ return dateObj.getDate() === today.getDate() && dateObj.getMonth() === today.getMonth() && dateObj.getFullYear() === today.getFullYear();
214
+ }
215
+ function isPast(date) {
216
+ const dateObj = typeof date === "string" ? new Date(date) : date;
217
+ return dateObj.getTime() < Date.now();
218
+ }
219
+ function isFuture(date) {
220
+ const dateObj = typeof date === "string" ? new Date(date) : date;
221
+ return dateObj.getTime() > Date.now();
222
+ }
223
+ function nowMs() {
224
+ return Date.now();
225
+ }
226
+ function isSameMonth(a, b) {
227
+ const da = new Date(a);
228
+ const db = new Date(b);
229
+ return da.getFullYear() === db.getFullYear() && da.getMonth() === db.getMonth();
230
+ }
231
+ function currentYear() {
232
+ return new Date(nowMs()).getFullYear().toString();
233
+ }
234
+ function nowISO() {
235
+ return new Date(nowMs()).toISOString();
236
+ }
237
+
238
+ // src/number.formatter.ts
239
+ function formatCurrency(amount, currency = "USD", locale = "en-US") {
240
+ return new Intl.NumberFormat(locale, { style: "currency", currency }).format(
241
+ amount
242
+ );
243
+ }
244
+ function formatNumber(num, locale = "en-US", options) {
245
+ return new Intl.NumberFormat(locale, {
246
+ minimumFractionDigits: options == null ? void 0 : options.decimals,
247
+ maximumFractionDigits: options == null ? void 0 : options.decimals
248
+ }).format(num);
249
+ }
250
+ function formatPercentage(num, decimals = 0) {
251
+ return `${(num * 100).toFixed(decimals)}%`;
252
+ }
253
+ function formatFileSize(bytes) {
254
+ if (bytes === 0) return "0 Bytes";
255
+ const k = 1024;
256
+ const sizes = ["Bytes", "KB", "MB", "GB", "TB"];
257
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
258
+ return `${parseFloat((bytes / Math.pow(k, i)).toFixed(2))} ${sizes[i]}`;
259
+ }
260
+ function formatCompactNumber(num) {
261
+ if (num < 1e3) return num.toString();
262
+ if (num < 1e6) return `${(num / 1e3).toFixed(1)}K`;
263
+ if (num < 1e9) return `${(num / 1e6).toFixed(1)}M`;
264
+ return `${(num / 1e9).toFixed(1)}B`;
265
+ }
266
+ function formatDecimal(num, decimals = 2) {
267
+ return num.toFixed(decimals);
268
+ }
269
+ function formatOrdinal(num) {
270
+ const suffixes = ["th", "st", "nd", "rd"];
271
+ const value = num % 100;
272
+ return num + (suffixes[(value - 20) % 10] || suffixes[value] || suffixes[0]);
273
+ }
274
+ function parseFormattedNumber(str) {
275
+ const isNegative = /^-/.test(str) || str.includes("-");
276
+ let cleaned = str.replace(/[^\d,.]/g, "");
277
+ if (cleaned === "" || cleaned === "0") return 0;
278
+ const lastCommaIndex = cleaned.lastIndexOf(",");
279
+ const lastDotIndex = cleaned.lastIndexOf(".");
280
+ const commaCount = (cleaned.match(/,/g) || []).length;
281
+ const dotCount = (cleaned.match(/\./g) || []).length;
282
+ let decimalSeparator = ".";
283
+ let thousandsSeparator = ",";
284
+ if (lastCommaIndex > -1 && lastDotIndex > -1) {
285
+ if (lastCommaIndex > lastDotIndex) {
286
+ decimalSeparator = ",";
287
+ thousandsSeparator = ".";
288
+ }
289
+ } else if (lastDotIndex > -1 && lastCommaIndex === -1) {
290
+ const afterDot = cleaned.substring(lastDotIndex + 1);
291
+ if (dotCount > 1) {
292
+ cleaned = cleaned.replace(/\./g, "");
293
+ } else if (afterDot.length > 3) {
294
+ cleaned = cleaned.replace(/\./g, "");
295
+ }
296
+ decimalSeparator = ".";
297
+ thousandsSeparator = "";
298
+ } else if (lastCommaIndex > -1 && lastDotIndex === -1) {
299
+ const afterComma = cleaned.substring(lastCommaIndex + 1);
300
+ if (commaCount > 1) {
301
+ cleaned = cleaned.replace(/,/g, "");
302
+ decimalSeparator = ".";
303
+ thousandsSeparator = "";
304
+ } else if (afterComma.length > 3) {
305
+ cleaned = cleaned.replace(/,/g, "");
306
+ decimalSeparator = ".";
307
+ thousandsSeparator = "";
308
+ } else {
309
+ decimalSeparator = ",";
310
+ thousandsSeparator = "";
311
+ }
312
+ }
313
+ let result = cleaned;
314
+ if (thousandsSeparator) {
315
+ result = result.replace(new RegExp("\\" + thousandsSeparator, "g"), "");
316
+ }
317
+ result = result.replace(decimalSeparator, ".");
318
+ const num = parseFloat(result);
319
+ return isNegative ? -Math.abs(num) : num;
320
+ }
321
+
322
+ // src/string.formatter.ts
323
+ function capitalize(str) {
324
+ return str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();
325
+ }
326
+ function capitalizeWords(str) {
327
+ return str.split(" ").map((word) => capitalize(word)).join(" ");
328
+ }
329
+ function truncate(str, maxLength, suffix = "...") {
330
+ if (str.length <= maxLength) return str;
331
+ return str.slice(0, maxLength - suffix.length) + suffix;
332
+ }
333
+ function truncateWords(str, wordCount, suffix = "...") {
334
+ const words = str.split(" ");
335
+ if (words.length <= wordCount) return str;
336
+ return words.slice(0, wordCount).join(" ") + suffix;
337
+ }
338
+ function stripHtml(html) {
339
+ return html.replace(/<[^>]*>/g, "");
340
+ }
341
+ function escapeHtml(str) {
342
+ const map = {
343
+ "&": "&amp;",
344
+ "<": "&lt;",
345
+ ">": "&gt;",
346
+ '"': "&quot;",
347
+ "'": "&#x27;",
348
+ "/": "&#x2F;"
349
+ };
350
+ return str.replace(/[&<>"'/]/g, (char) => map[char]);
351
+ }
352
+ function slugify(str) {
353
+ return str.toLowerCase().trim().replace(/[^\w\s-]/g, "").replace(/[\s_-]+/g, "-").replace(/^-+|-+$/g, "");
354
+ }
355
+ function maskString(str, visibleStart = 4, visibleEnd = 4, maskChar = "*") {
356
+ if (str.length <= visibleStart + visibleEnd) return str;
357
+ const start = str.slice(0, visibleStart);
358
+ const end = str.slice(-visibleEnd);
359
+ const masked = maskChar.repeat(str.length - visibleStart - visibleEnd);
360
+ return start + masked + end;
361
+ }
362
+ function randomString(length = 10) {
363
+ const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
364
+ const indices = new Uint8Array(length);
365
+ globalThis.crypto.getRandomValues(indices);
366
+ return Array.from(indices, (i) => chars[i % chars.length]).join("");
367
+ }
368
+ function isEmptyString(str) {
369
+ return !str || str.trim().length === 0;
370
+ }
371
+ function renderProseMirrorNodes(nodes) {
372
+ return nodes.map(renderProseMirrorNode).join("");
373
+ }
374
+ function renderProseMirrorNode(node) {
375
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
376
+ switch (node.type) {
377
+ case "doc":
378
+ return renderProseMirrorNodes((_a = node.content) != null ? _a : []);
379
+ case "paragraph": {
380
+ const inner = renderProseMirrorNodes((_b = node.content) != null ? _b : []);
381
+ return inner ? `<p>${inner}</p>` : "<p></p>";
382
+ }
383
+ case "text": {
384
+ let text = escapeHtml((_c = node.text) != null ? _c : "");
385
+ if (node.marks) {
386
+ for (const mark of node.marks) {
387
+ if (mark.type === "bold") text = `<strong>${text}</strong>`;
388
+ else if (mark.type === "italic") text = `<em>${text}</em>`;
389
+ else if (mark.type === "underline") text = `<u>${text}</u>`;
390
+ else if (mark.type === "strike") text = `<s>${text}</s>`;
391
+ else if (mark.type === "code") text = `<code>${text}</code>`;
392
+ else if (mark.type === "link") {
393
+ const rawHref = String((_e = (_d = mark.attrs) == null ? void 0 : _d.href) != null ? _e : "#").trim();
394
+ const safe = /^(https?:\/\/|mailto:|\/|#)/i.test(rawHref) ? rawHref : "#";
395
+ const href = safe.replace(
396
+ /[&"<>]/g,
397
+ (c) => {
398
+ var _a2;
399
+ return (_a2 = { "&": "&amp;", '"': "&quot;", "<": "&lt;", ">": "&gt;" }[c]) != null ? _a2 : c;
400
+ }
401
+ );
402
+ text = `<a href="${href}" rel="noopener noreferrer">${text}</a>`;
403
+ }
404
+ }
405
+ }
406
+ return text;
407
+ }
408
+ case "heading": {
409
+ const level = (_g = (_f = node.attrs) == null ? void 0 : _f.level) != null ? _g : 2;
410
+ return `<h${level}>${renderProseMirrorNodes((_h = node.content) != null ? _h : [])}</h${level}>`;
411
+ }
412
+ case "bulletList":
413
+ return `<ul>${renderProseMirrorNodes((_i = node.content) != null ? _i : [])}</ul>`;
414
+ case "orderedList":
415
+ return `<ol>${renderProseMirrorNodes((_j = node.content) != null ? _j : [])}</ol>`;
416
+ case "listItem":
417
+ return `<li>${renderProseMirrorNodes((_k = node.content) != null ? _k : [])}</li>`;
418
+ case "blockquote":
419
+ return `<blockquote>${renderProseMirrorNodes((_l = node.content) != null ? _l : [])}</blockquote>`;
420
+ case "codeBlock":
421
+ return `<pre><code>${renderProseMirrorNodes((_m = node.content) != null ? _m : [])}</code></pre>`;
422
+ case "hardBreak":
423
+ return "<br>";
424
+ case "horizontalRule":
425
+ return "<hr>";
426
+ default:
427
+ return renderProseMirrorNodes((_n = node.content) != null ? _n : []);
428
+ }
429
+ }
430
+ function proseMirrorToHtml(value) {
431
+ var _a;
432
+ if (!value) return value;
433
+ try {
434
+ const parsed = JSON.parse(value);
435
+ if ((parsed == null ? void 0 : parsed.type) === "doc") {
436
+ return renderProseMirrorNodes((_a = parsed.content) != null ? _a : []);
437
+ }
438
+ return value;
439
+ } catch (e) {
440
+ return value;
441
+ }
442
+ }
443
+
444
+ // src/type.converter.ts
445
+ function stringToBoolean(value) {
446
+ return ["true", "yes", "1", "on"].includes(value.toLowerCase());
447
+ }
448
+ function booleanToString(value, format = "truefalse") {
449
+ const formats = {
450
+ yesno: { true: "Yes", false: "No" },
451
+ truefalse: { true: "True", false: "False" },
452
+ onoff: { true: "On", false: "Off" }
453
+ };
454
+ return formats[format][value.toString()];
455
+ }
456
+ function arrayToObject(arr, keyField) {
457
+ return arr.reduce(
458
+ (acc, item) => {
459
+ const key = String(item[keyField]);
460
+ acc[key] = item;
461
+ return acc;
462
+ },
463
+ {}
464
+ );
465
+ }
466
+ function objectToArray(obj) {
467
+ return Object.values(obj);
468
+ }
469
+ function queryStringToObject(queryString) {
470
+ const params = new URLSearchParams(queryString);
471
+ const result = {};
472
+ params.forEach((value, key) => {
473
+ result[key] = value;
474
+ });
475
+ return result;
476
+ }
477
+ function objectToQueryString(obj) {
478
+ const params = new URLSearchParams();
479
+ Object.entries(obj).forEach(([key, value]) => {
480
+ if (value !== null && value !== void 0) {
481
+ params.append(key, String(value));
482
+ }
483
+ });
484
+ return params.toString();
485
+ }
486
+ function firestoreTimestampToDate(timestamp) {
487
+ if (timestamp && typeof timestamp === "object" && "toDate" in timestamp && typeof timestamp.toDate === "function") {
488
+ return timestamp.toDate();
489
+ }
490
+ if (timestamp && typeof timestamp === "object" && "seconds" in timestamp && typeof timestamp.seconds === "number") {
491
+ return new Date(timestamp.seconds * 1e3);
492
+ }
493
+ return new Date(timestamp);
494
+ }
495
+ function dateToISOString(date) {
496
+ return typeof date === "string" ? new Date(date).toISOString() : date.toISOString();
497
+ }
498
+
499
+ // src/cookie.converter.ts
500
+ function parseCookies() {
501
+ if (typeof document === "undefined") return {};
502
+ const result = {};
503
+ for (const cookie of document.cookie.split(";")) {
504
+ const [name, ...valueParts] = cookie.trim().split("=");
505
+ if (name) result[name.trim()] = decodeURIComponent(valueParts.join("="));
506
+ }
507
+ return result;
508
+ }
509
+ function getCookie(name) {
510
+ if (typeof document === "undefined") return null;
511
+ for (const cookie of document.cookie.split(";")) {
512
+ const [cookieName, ...valueParts] = cookie.trim().split("=");
513
+ if ((cookieName == null ? void 0 : cookieName.trim()) === name)
514
+ return decodeURIComponent(valueParts.join("="));
515
+ }
516
+ return null;
517
+ }
518
+ function hasCookie(name) {
519
+ return getCookie(name) !== null;
520
+ }
521
+ function deleteCookie(name, path = "/") {
522
+ if (typeof document === "undefined") return;
523
+ document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=${path};`;
524
+ }
525
+
526
+ // src/id-generators.ts
527
+ function generateRandomString(length = 6) {
528
+ const chars = "abcdefghijklmnopqrstuvwxyz0123456789";
529
+ const indices = new Uint8Array(length);
530
+ globalThis.crypto.getRandomValues(indices);
531
+ return Array.from(indices, (i) => chars[i % chars.length]).join("");
532
+ }
533
+ function getTimestamp() {
534
+ return Date.now().toString();
535
+ }
536
+ function generateCategoryId(input) {
537
+ const nameSlug = slugify(input.name);
538
+ if (input.parentName)
539
+ return `category-${nameSlug}-${slugify(input.parentName)}`;
540
+ if (input.rootName) return `category-${nameSlug}-${slugify(input.rootName)}`;
541
+ return `category-${nameSlug}`;
542
+ }
543
+ function generateUserId(input) {
544
+ const firstSlug = slugify(input.firstName);
545
+ const lastSlug = slugify(input.lastName);
546
+ const emailPrefix = input.email.split("@")[0].toLowerCase().substring(0, 8);
547
+ const emailSlug = slugify(emailPrefix);
548
+ return `user-${firstSlug}-${lastSlug}-${emailSlug}`;
549
+ }
550
+ function generateProductId(input) {
551
+ const count = input.count || 1;
552
+ return `product-${slugify(input.name)}-${slugify(input.category)}-${input.condition}-${slugify(input.sellerName)}-${count}`;
553
+ }
554
+ function generateAuctionId(input) {
555
+ const count = input.count || 1;
556
+ return `auction-${slugify(input.name)}-${slugify(input.category)}-${input.condition}-${slugify(input.sellerName)}-${count}`;
557
+ }
558
+ function generatePreOrderId(input) {
559
+ const count = input.count || 1;
560
+ return `preorder-${slugify(input.name)}-${slugify(input.category)}-${input.condition}-${slugify(input.sellerName)}-${count}`;
561
+ }
562
+ function generateReviewId(input) {
563
+ const date = input.date || /* @__PURE__ */ new Date();
564
+ const y = date.getFullYear();
565
+ const m = String(date.getMonth() + 1).padStart(2, "0");
566
+ const d = String(date.getDate()).padStart(2, "0");
567
+ return `review-${slugify(input.productName)}-${slugify(input.userFirstName)}-${y}${m}${d}`;
568
+ }
569
+ function generateOrderId(input) {
570
+ const date = input.date || /* @__PURE__ */ new Date();
571
+ const y = date.getFullYear();
572
+ const m = String(date.getMonth() + 1).padStart(2, "0");
573
+ const d = String(date.getDate()).padStart(2, "0");
574
+ return `order-${input.productCount}-${y}${m}${d}-${generateRandomString(6)}`;
575
+ }
576
+ function generateFAQId(input) {
577
+ return `faq-${slugify(input.category)}-${slugify(input.question).substring(0, 50)}`;
578
+ }
579
+ function generateCouponId(code) {
580
+ return `coupon-${code.toUpperCase().replace(/[^A-Z0-9]/g, "")}`;
581
+ }
582
+ function generateCarouselId(input) {
583
+ return `carousel-${slugify(input.title).substring(0, 30)}-${getTimestamp()}`;
584
+ }
585
+ function generateHomepageSectionId(input) {
586
+ return `section-${slugify(input.type)}-${getTimestamp()}`;
587
+ }
588
+ function generateBidId(input) {
589
+ const date = input.date || /* @__PURE__ */ new Date();
590
+ const y = date.getFullYear();
591
+ const m = String(date.getMonth() + 1).padStart(2, "0");
592
+ const d = String(date.getDate()).padStart(2, "0");
593
+ const random = input.random || generateRandomString(6);
594
+ return `bid-${slugify(input.productName).substring(0, 30)}-${slugify(input.userFirstName)}-${y}${m}${d}-${random}`;
595
+ }
596
+ function generateBlogPostId(input) {
597
+ const titleSlug = slugify(input.title).substring(0, 40).replace(/-+$/, "");
598
+ const categorySlug = slugify(input.category);
599
+ const base = `blog-${titleSlug}-${categorySlug}`;
600
+ if (input.status && input.status !== "published")
601
+ return `${base}-${input.status}`;
602
+ return base;
603
+ }
604
+ function generatePayoutId(input) {
605
+ const sellerSlug = slugify(input.sellerName).substring(0, 25).replace(/-+$/, "");
606
+ const date = input.date || /* @__PURE__ */ new Date();
607
+ const y = date.getFullYear();
608
+ const m = String(date.getMonth() + 1).padStart(2, "0");
609
+ const d = String(date.getDate()).padStart(2, "0");
610
+ return `payout-${sellerSlug}-${y}${m}${d}-${generateRandomString(6)}`;
611
+ }
612
+ // Annotate the CommonJS export names for ESM import in node:
613
+ 0 && (module.exports = {
614
+ arrayToObject,
615
+ booleanToString,
616
+ capitalize,
617
+ capitalizeWords,
618
+ currentYear,
619
+ dateToISOString,
620
+ deleteCookie,
621
+ escapeHtml,
622
+ firestoreTimestampToDate,
623
+ formatCompactNumber,
624
+ formatCurrency,
625
+ formatDate,
626
+ formatDateRange,
627
+ formatDateTime,
628
+ formatDecimal,
629
+ formatFileSize,
630
+ formatMonthYear,
631
+ formatNumber,
632
+ formatOrdinal,
633
+ formatPercentage,
634
+ formatRelativeTime,
635
+ formatTime,
636
+ generateAuctionId,
637
+ generateBidId,
638
+ generateBlogPostId,
639
+ generateCarouselId,
640
+ generateCategoryId,
641
+ generateCouponId,
642
+ generateFAQId,
643
+ generateHomepageSectionId,
644
+ generateOrderId,
645
+ generatePayoutId,
646
+ generatePreOrderId,
647
+ generateProductId,
648
+ generateReviewId,
649
+ generateUserId,
650
+ getCookie,
651
+ hasCookie,
652
+ isEmptyString,
653
+ isFuture,
654
+ isPast,
655
+ isSameMonth,
656
+ isToday,
657
+ maskString,
658
+ nowISO,
659
+ nowMs,
660
+ objectToArray,
661
+ objectToQueryString,
662
+ parseCookies,
663
+ parseFormattedNumber,
664
+ proseMirrorToHtml,
665
+ queryStringToObject,
666
+ randomString,
667
+ resolveDate,
668
+ slugify,
669
+ stringToBoolean,
670
+ stripHtml,
671
+ truncate,
672
+ truncateWords
673
+ });