@sudobility/types 1.9.54 → 1.9.56

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.
Files changed (112) hide show
  1. package/README.md +44 -280
  2. package/dist/index.js +28 -201
  3. package/dist/index.js.map +1 -1
  4. package/dist/types/blockchain/common.js +9 -16
  5. package/dist/types/blockchain/common.js.map +1 -1
  6. package/dist/types/blockchain/index.js +3 -17
  7. package/dist/types/blockchain/index.js.map +1 -1
  8. package/dist/types/blockchain/validation.js +6 -12
  9. package/dist/types/blockchain/validation.js.map +1 -1
  10. package/dist/types/business/enums.js +46 -49
  11. package/dist/types/business/enums.js.map +1 -1
  12. package/dist/types/business/wallet-status.js +10 -16
  13. package/dist/types/business/wallet-status.js.map +1 -1
  14. package/dist/types/common.js +1 -2
  15. package/dist/types/common.js.map +1 -1
  16. package/dist/types/config/app-config.js +1 -2
  17. package/dist/types/config/app-config.js.map +1 -1
  18. package/dist/types/config/environment.js +2 -5
  19. package/dist/types/config/environment.js.map +1 -1
  20. package/dist/types/consumables/index.js +1 -2
  21. package/dist/types/consumables/index.js.map +1 -1
  22. package/dist/types/entity/entity.js +6 -9
  23. package/dist/types/entity/entity.js.map +1 -1
  24. package/dist/types/entity/permissions.js +12 -17
  25. package/dist/types/entity/permissions.js.map +1 -1
  26. package/dist/types/entity/requests.js +1 -2
  27. package/dist/types/entity/requests.js.map +1 -1
  28. package/dist/types/entity/responses.js +1 -2
  29. package/dist/types/entity/responses.js.map +1 -1
  30. package/dist/types/infrastructure/analytics.js +3 -7
  31. package/dist/types/infrastructure/analytics.js.map +1 -1
  32. package/dist/types/infrastructure/api.js +5 -9
  33. package/dist/types/infrastructure/api.js.map +1 -1
  34. package/dist/types/infrastructure/firebase-user.js +1 -2
  35. package/dist/types/infrastructure/firebase-user.js.map +1 -1
  36. package/dist/types/infrastructure/navigation.js +1 -2
  37. package/dist/types/infrastructure/network.js +1 -4
  38. package/dist/types/infrastructure/network.js.map +1 -1
  39. package/dist/types/infrastructure/wallet.js +2 -5
  40. package/dist/types/infrastructure/wallet.js.map +1 -1
  41. package/dist/types/subscription/entitlements.js +1 -4
  42. package/dist/types/subscription/entitlements.js.map +1 -1
  43. package/dist/types/subscription/period.js +2 -5
  44. package/dist/types/subscription/period.js.map +1 -1
  45. package/dist/types/subscription/rate-limits.js +2 -5
  46. package/dist/types/subscription/rate-limits.js.map +1 -1
  47. package/dist/utils/async-helpers.js +7 -16
  48. package/dist/utils/async-helpers.js.map +1 -1
  49. package/dist/utils/auth/admin-emails.js +3 -8
  50. package/dist/utils/auth/admin-emails.js.map +1 -1
  51. package/dist/utils/auth/auth.js +14 -24
  52. package/dist/utils/auth/auth.js.map +1 -1
  53. package/dist/utils/blockchain/address.js +20 -31
  54. package/dist/utils/blockchain/address.js.map +1 -1
  55. package/dist/utils/blockchain/event-helpers.js +9 -20
  56. package/dist/utils/blockchain/event-helpers.js.map +1 -1
  57. package/dist/utils/constants/application.js +2 -20
  58. package/dist/utils/constants/application.js.map +1 -1
  59. package/dist/utils/constants/status-values.js +1 -4
  60. package/dist/utils/constants/status-values.js.map +1 -1
  61. package/dist/utils/formatting/currency.js +6 -11
  62. package/dist/utils/formatting/currency.js.map +1 -1
  63. package/dist/utils/formatting/date.js +7 -16
  64. package/dist/utils/formatting/date.js.map +1 -1
  65. package/dist/utils/formatting/string.js +16 -34
  66. package/dist/utils/formatting/string.js.map +1 -1
  67. package/dist/utils/logging/logger.js +2 -10
  68. package/dist/utils/logging/logger.js.map +1 -1
  69. package/dist/utils/url/url-params.js +1 -6
  70. package/dist/utils/url/url-params.js.map +1 -1
  71. package/dist/utils/validation/type-validation.js +27 -48
  72. package/dist/utils/validation/type-validation.js.map +1 -1
  73. package/dist/utils/validation/web3-username-validator.js +6 -10
  74. package/dist/utils/validation/web3-username-validator.js.map +1 -1
  75. package/package.json +3 -11
  76. package/dist/index.cjs +0 -243
  77. package/dist/types/blockchain/common.cjs +0 -127
  78. package/dist/types/blockchain/index.cjs +0 -30
  79. package/dist/types/blockchain/validation.cjs +0 -144
  80. package/dist/types/business/enums.cjs +0 -367
  81. package/dist/types/business/wallet-status.cjs +0 -38
  82. package/dist/types/common.cjs +0 -12
  83. package/dist/types/config/app-config.cjs +0 -6
  84. package/dist/types/config/environment.cjs +0 -24
  85. package/dist/types/consumables/index.cjs +0 -8
  86. package/dist/types/entity/entity.cjs +0 -51
  87. package/dist/types/entity/permissions.cjs +0 -93
  88. package/dist/types/entity/requests.cjs +0 -7
  89. package/dist/types/entity/responses.cjs +0 -7
  90. package/dist/types/infrastructure/analytics.cjs +0 -212
  91. package/dist/types/infrastructure/api.cjs +0 -43
  92. package/dist/types/infrastructure/firebase-user.cjs +0 -10
  93. package/dist/types/infrastructure/navigation.cjs +0 -3
  94. package/dist/types/infrastructure/network.cjs +0 -18
  95. package/dist/types/infrastructure/wallet.cjs +0 -37
  96. package/dist/types/subscription/entitlements.cjs +0 -14
  97. package/dist/types/subscription/period.cjs +0 -29
  98. package/dist/types/subscription/rate-limits.cjs +0 -20
  99. package/dist/utils/async-helpers.cjs +0 -244
  100. package/dist/utils/auth/admin-emails.cjs +0 -79
  101. package/dist/utils/auth/auth.cjs +0 -99
  102. package/dist/utils/blockchain/address.cjs +0 -225
  103. package/dist/utils/blockchain/event-helpers.cjs +0 -143
  104. package/dist/utils/constants/application.cjs +0 -152
  105. package/dist/utils/constants/status-values.cjs +0 -14
  106. package/dist/utils/formatting/currency.cjs +0 -39
  107. package/dist/utils/formatting/date.cjs +0 -197
  108. package/dist/utils/formatting/string.cjs +0 -326
  109. package/dist/utils/logging/logger.cjs +0 -92
  110. package/dist/utils/url/url-params.cjs +0 -128
  111. package/dist/utils/validation/type-validation.cjs +0 -250
  112. package/dist/utils/validation/web3-username-validator.cjs +0 -132
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.STATUS_VALUES = void 0;
4
- /**
5
- * Shared status value constants
6
- * Used across multiple enums to ensure consistency and avoid duplication
7
- */
8
- exports.STATUS_VALUES = {
9
- SUCCESS: 'success',
10
- PENDING: 'pending',
11
- FAILED: 'failed',
12
- ERROR: 'error',
13
- };
14
- //# sourceMappingURL=status-values.js.map
@@ -1,39 +0,0 @@
1
- "use strict";
2
- /**
3
- * Currency formatting utilities for USDC and other tokens.
4
- *
5
- * @since 1.0.0
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.CLAIM_PERIOD_DAYS = exports.USDC_DECIMALS = void 0;
9
- exports.formatUSDC = formatUSDC;
10
- exports.parseUSDC = parseUSDC;
11
- /** Number of decimal places for USDC token amounts. */
12
- exports.USDC_DECIMALS = 6;
13
- /** Revenue claim expiration period in days. */
14
- exports.CLAIM_PERIOD_DAYS = 60;
15
- /**
16
- * Format USDC amount from smallest unit to human-readable string
17
- * @param amount - Amount in smallest USDC units (with 6 decimals)
18
- * @returns Formatted string with 2 decimal places
19
- *
20
- * @example
21
- * formatUSDC(1000000) // Returns "1.00"
22
- * formatUSDC(2500000) // Returns "2.50"
23
- */
24
- function formatUSDC(amount) {
25
- return (amount / Math.pow(10, exports.USDC_DECIMALS)).toFixed(2);
26
- }
27
- /**
28
- * Parse USDC amount from human-readable string to smallest unit
29
- * @param amount - Human-readable amount string
30
- * @returns Amount in smallest USDC units (with 6 decimals)
31
- *
32
- * @example
33
- * parseUSDC("1.00") // Returns 1000000
34
- * parseUSDC("2.50") // Returns 2500000
35
- */
36
- function parseUSDC(amount) {
37
- return Math.floor(parseFloat(amount) * Math.pow(10, exports.USDC_DECIMALS));
38
- }
39
- //# sourceMappingURL=currency.js.map
@@ -1,197 +0,0 @@
1
- "use strict";
2
- /**
3
- * Date formatting utilities.
4
- *
5
- * @since 1.0.0
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.formatEmailDate = formatEmailDate;
9
- exports.formatTimestamp = formatTimestamp;
10
- exports.formatRelativeTime = formatRelativeTime;
11
- exports.parseDate = parseDate;
12
- exports.isDateInRange = isDateInRange;
13
- exports.addDays = addDays;
14
- exports.addHours = addHours;
15
- /**
16
- * Format a date for display in email list.
17
- * Returns time for today, "Yesterday", day name for the past week,
18
- * or a short date for older messages.
19
- *
20
- * @param date - Date object or ISO date string
21
- * @returns Formatted date string
22
- * @since 1.0.0
23
- *
24
- * @example
25
- * ```typescript
26
- * formatEmailDate(new Date()); // "3:45 PM"
27
- * formatEmailDate('2024-01-15'); // "Jan 15"
28
- * ```
29
- */
30
- function formatEmailDate(date) {
31
- const dateObj = typeof date === 'string' ? new Date(date) : date;
32
- if (isNaN(dateObj.getTime())) {
33
- return 'Invalid date';
34
- }
35
- const now = new Date();
36
- const diffMs = now.getTime() - dateObj.getTime();
37
- const diffDays = Math.floor(diffMs / (1000 * 60 * 60 * 24));
38
- // Today: show time only
39
- if (diffDays === 0) {
40
- return dateObj.toLocaleTimeString('en-US', {
41
- hour: 'numeric',
42
- minute: '2-digit',
43
- hour12: true,
44
- });
45
- }
46
- // Yesterday
47
- if (diffDays === 1) {
48
- return 'Yesterday';
49
- }
50
- // Within a week: show day name
51
- if (diffDays < 7) {
52
- return dateObj.toLocaleDateString('en-US', {
53
- weekday: 'long',
54
- });
55
- }
56
- // Within this year: show month and day
57
- if (dateObj.getFullYear() === now.getFullYear()) {
58
- return dateObj.toLocaleDateString('en-US', {
59
- month: 'short',
60
- day: 'numeric',
61
- });
62
- }
63
- // Different year: show full date
64
- return dateObj.toLocaleDateString('en-US', {
65
- year: 'numeric',
66
- month: 'short',
67
- day: 'numeric',
68
- });
69
- }
70
- /**
71
- * Format a Unix timestamp (ms) to an ISO 8601 string.
72
- *
73
- * @param timestamp - Unix timestamp in milliseconds
74
- * @returns ISO 8601 date string
75
- * @since 1.0.0
76
- *
77
- * @example
78
- * ```typescript
79
- * formatTimestamp(1700000000000); // "2023-11-14T22:13:20.000Z"
80
- * ```
81
- */
82
- function formatTimestamp(timestamp) {
83
- return new Date(timestamp).toISOString();
84
- }
85
- /**
86
- * Format a date to a relative time string (e.g., "2 hours ago").
87
- *
88
- * @param date - Date object, ISO string, or Unix timestamp (ms)
89
- * @returns Human-readable relative time string
90
- * @since 1.0.0
91
- *
92
- * @example
93
- * ```typescript
94
- * formatRelativeTime(Date.now() - 3600000); // "1 hour ago"
95
- * formatRelativeTime('2024-01-01'); // "1 year ago"
96
- * ```
97
- */
98
- function formatRelativeTime(date) {
99
- const dateObj = typeof date === 'string' || typeof date === 'number'
100
- ? new Date(date)
101
- : date;
102
- if (isNaN(dateObj.getTime())) {
103
- return 'Invalid date';
104
- }
105
- const now = new Date();
106
- const diffMs = now.getTime() - dateObj.getTime();
107
- const diffSeconds = Math.floor(diffMs / 1000);
108
- const diffMinutes = Math.floor(diffSeconds / 60);
109
- const diffHours = Math.floor(diffMinutes / 60);
110
- const diffDays = Math.floor(diffHours / 24);
111
- const diffWeeks = Math.floor(diffDays / 7);
112
- const diffMonths = Math.floor(diffDays / 30);
113
- const diffYears = Math.floor(diffDays / 365);
114
- if (diffSeconds < 60) {
115
- return 'just now';
116
- }
117
- if (diffMinutes < 60) {
118
- return diffMinutes === 1 ? '1 minute ago' : `${diffMinutes} minutes ago`;
119
- }
120
- if (diffHours < 24) {
121
- return diffHours === 1 ? '1 hour ago' : `${diffHours} hours ago`;
122
- }
123
- if (diffDays < 7) {
124
- return diffDays === 1 ? '1 day ago' : `${diffDays} days ago`;
125
- }
126
- if (diffWeeks < 4) {
127
- return diffWeeks === 1 ? '1 week ago' : `${diffWeeks} weeks ago`;
128
- }
129
- if (diffMonths < 12) {
130
- return diffMonths === 1 ? '1 month ago' : `${diffMonths} months ago`;
131
- }
132
- return diffYears === 1 ? '1 year ago' : `${diffYears} years ago`;
133
- }
134
- /**
135
- * Parse a date string safely, returning null on invalid input.
136
- *
137
- * @param dateString - Date string to parse
138
- * @returns Parsed Date or null if invalid
139
- * @since 1.0.0
140
- *
141
- * @example
142
- * ```typescript
143
- * parseDate('2024-01-15'); // Date object
144
- * parseDate('not-a-date'); // null
145
- * ```
146
- */
147
- function parseDate(dateString) {
148
- try {
149
- const date = new Date(dateString);
150
- if (isNaN(date.getTime())) {
151
- return null;
152
- }
153
- return date;
154
- }
155
- catch {
156
- return null;
157
- }
158
- }
159
- /**
160
- * Check if a date falls within an inclusive range.
161
- *
162
- * @param date - Date to check
163
- * @param startDate - Range start (inclusive)
164
- * @param endDate - Range end (inclusive)
165
- * @returns True if date is within the range
166
- * @since 1.0.0
167
- */
168
- function isDateInRange(date, startDate, endDate) {
169
- return date >= startDate && date <= endDate;
170
- }
171
- /**
172
- * Add (or subtract) days from a date. Returns a new Date instance.
173
- *
174
- * @param date - Starting date
175
- * @param days - Number of days to add (negative to subtract)
176
- * @returns New Date with days added
177
- * @since 1.0.0
178
- */
179
- function addDays(date, days) {
180
- const result = new Date(date);
181
- result.setDate(result.getDate() + days);
182
- return result;
183
- }
184
- /**
185
- * Add (or subtract) hours from a date. Returns a new Date instance.
186
- *
187
- * @param date - Starting date
188
- * @param hours - Number of hours to add (negative to subtract)
189
- * @returns New Date with hours added
190
- * @since 1.0.0
191
- */
192
- function addHours(date, hours) {
193
- const result = new Date(date);
194
- result.setHours(result.getHours() + hours);
195
- return result;
196
- }
197
- //# sourceMappingURL=date.js.map
@@ -1,326 +0,0 @@
1
- "use strict";
2
- /**
3
- * String formatting and manipulation utilities.
4
- *
5
- * @since 1.0.0
6
- */
7
- Object.defineProperty(exports, "__esModule", { value: true });
8
- exports.truncate = truncate;
9
- exports.capitalize = capitalize;
10
- exports.toTitleCase = toTitleCase;
11
- exports.toKebabCase = toKebabCase;
12
- exports.toCamelCase = toCamelCase;
13
- exports.toSnakeCase = toSnakeCase;
14
- exports.normalizeWhitespace = normalizeWhitespace;
15
- exports.isBlank = isBlank;
16
- exports.isNotBlank = isNotBlank;
17
- exports.escapeHtml = escapeHtml;
18
- exports.stripHtml = stripHtml;
19
- exports.getInitials = getInitials;
20
- exports.formatBytes = formatBytes;
21
- exports.randomString = randomString;
22
- exports.pluralize = pluralize;
23
- exports.formatNumber = formatNumber;
24
- /**
25
- * Truncate a string to a maximum length with a suffix (default `...`).
26
- *
27
- * @param str - Input string
28
- * @param maxLength - Maximum allowed length including suffix
29
- * @param suffix - Truncation suffix (default: `'...'`)
30
- * @returns Truncated string or original if within limit
31
- * @since 1.0.0
32
- *
33
- * @example
34
- * ```typescript
35
- * truncate('Hello, World!', 8); // "Hello..."
36
- * ```
37
- */
38
- function truncate(str, maxLength, suffix = '...') {
39
- if (!str || str.length <= maxLength) {
40
- return str;
41
- }
42
- return str.slice(0, maxLength - suffix.length) + suffix;
43
- }
44
- /**
45
- * Capitalize the first letter of a string.
46
- *
47
- * @param str - Input string
48
- * @returns String with first character uppercased
49
- * @since 1.0.0
50
- *
51
- * @example
52
- * ```typescript
53
- * capitalize('hello'); // "Hello"
54
- * ```
55
- */
56
- function capitalize(str) {
57
- if (!str)
58
- return str;
59
- return str.charAt(0).toUpperCase() + str.slice(1);
60
- }
61
- /**
62
- * Convert a string to title case (capitalize each word).
63
- *
64
- * @param str - Input string
65
- * @returns Title-cased string
66
- * @since 1.0.0
67
- *
68
- * @example
69
- * ```typescript
70
- * toTitleCase('hello world'); // "Hello World"
71
- * ```
72
- */
73
- function toTitleCase(str) {
74
- if (!str)
75
- return str;
76
- return str
77
- .toLowerCase()
78
- .split(' ')
79
- .map((word) => capitalize(word))
80
- .join(' ');
81
- }
82
- /**
83
- * Convert a string to kebab-case.
84
- *
85
- * @param str - Input string (camelCase, PascalCase, spaces, or underscores)
86
- * @returns Kebab-cased string
87
- * @since 1.0.0
88
- *
89
- * @example
90
- * ```typescript
91
- * toKebabCase('helloWorld'); // "hello-world"
92
- * ```
93
- */
94
- function toKebabCase(str) {
95
- if (!str)
96
- return str;
97
- return str
98
- .replace(/([a-z])([A-Z])/g, '$1-$2')
99
- .replace(/[\s_]+/g, '-')
100
- .toLowerCase();
101
- }
102
- /**
103
- * Convert a string to camelCase.
104
- *
105
- * @param str - Input string (kebab-case, snake_case, or spaces)
106
- * @returns camelCased string
107
- * @since 1.0.0
108
- *
109
- * @example
110
- * ```typescript
111
- * toCamelCase('hello-world'); // "helloWorld"
112
- * ```
113
- */
114
- function toCamelCase(str) {
115
- if (!str)
116
- return str;
117
- return str
118
- .replace(/[-_\s]+(.)?/g, (_, char) => (char ? char.toUpperCase() : ''))
119
- .replace(/^./, (char) => char.toLowerCase());
120
- }
121
- /**
122
- * Convert a string to snake_case.
123
- *
124
- * @param str - Input string (camelCase, kebab-case, or spaces)
125
- * @returns snake_cased string
126
- * @since 1.0.0
127
- *
128
- * @example
129
- * ```typescript
130
- * toSnakeCase('helloWorld'); // "hello_world"
131
- * ```
132
- */
133
- function toSnakeCase(str) {
134
- if (!str)
135
- return str;
136
- return str
137
- .replace(/([a-z])([A-Z])/g, '$1_$2')
138
- .replace(/[\s-]+/g, '_')
139
- .toLowerCase();
140
- }
141
- /**
142
- * Collapse consecutive whitespace to a single space and trim.
143
- *
144
- * @param str - Input string
145
- * @returns Normalized string
146
- * @since 1.0.0
147
- */
148
- function normalizeWhitespace(str) {
149
- if (!str)
150
- return str;
151
- return str.replace(/\s+/g, ' ').trim();
152
- }
153
- /**
154
- * Check if a string is empty, undefined, null, or only whitespace.
155
- *
156
- * @param str - Input string (may be nullish)
157
- * @returns True if blank
158
- * @since 1.0.0
159
- */
160
- function isBlank(str) {
161
- return !str || str.trim().length === 0;
162
- }
163
- /**
164
- * Type guard: check if a string is not empty and not only whitespace.
165
- *
166
- * @param str - Input string (may be nullish)
167
- * @returns True (and narrows to `string`) if not blank
168
- * @since 1.0.0
169
- */
170
- function isNotBlank(str) {
171
- return !isBlank(str);
172
- }
173
- /**
174
- * Escape HTML special characters (`&`, `<`, `>`, `"`, `'`).
175
- *
176
- * @param str - Input string
177
- * @returns HTML-escaped string
178
- * @since 1.0.0
179
- *
180
- * @example
181
- * ```typescript
182
- * escapeHtml('<b>Hi</b>'); // "&lt;b&gt;Hi&lt;/b&gt;"
183
- * ```
184
- */
185
- function escapeHtml(str) {
186
- if (!str)
187
- return str;
188
- const htmlEscapes = {
189
- '&': '&amp;',
190
- '<': '&lt;',
191
- '>': '&gt;',
192
- '"': '&quot;',
193
- "'": '&#39;',
194
- };
195
- return str.replace(/[&<>"']/g, (char) => htmlEscapes[char]);
196
- }
197
- /**
198
- * Remove all HTML tags from a string.
199
- *
200
- * @param str - Input string with HTML
201
- * @returns Plain text with tags removed
202
- * @since 1.0.0
203
- *
204
- * @example
205
- * ```typescript
206
- * stripHtml('<p>Hello <b>world</b></p>'); // "Hello world"
207
- * ```
208
- */
209
- function stripHtml(str) {
210
- if (!str)
211
- return str;
212
- return str.replace(/<[^>]*>/g, '');
213
- }
214
- /**
215
- * Extract initials from a name (e.g., "John Doe" -> "JD").
216
- *
217
- * @param name - Full name
218
- * @param maxInitials - Maximum number of initials (default: 2)
219
- * @returns Uppercase initials
220
- * @since 1.0.0
221
- */
222
- function getInitials(name, maxInitials = 2) {
223
- if (!name)
224
- return '';
225
- const words = name.trim().split(/\s+/);
226
- const initials = words
227
- .slice(0, maxInitials)
228
- .map((word) => word.charAt(0).toUpperCase())
229
- .join('');
230
- return initials;
231
- }
232
- /**
233
- * Format bytes to a human-readable size string (e.g., "1.5 MB").
234
- *
235
- * @param bytes - Size in bytes
236
- * @param decimals - Decimal places (default: 2)
237
- * @returns Formatted string like "1.5 MB"
238
- * @since 1.0.0
239
- *
240
- * @example
241
- * ```typescript
242
- * formatBytes(1536); // "1.5 KB"
243
- * formatBytes(0); // "0 Bytes"
244
- * ```
245
- */
246
- function formatBytes(bytes, decimals = 2) {
247
- if (bytes === 0)
248
- return '0 Bytes';
249
- const k = 1024;
250
- const dm = decimals < 0 ? 0 : decimals;
251
- const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB'];
252
- const i = Math.floor(Math.log(bytes) / Math.log(k));
253
- return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
254
- }
255
- /**
256
- * Generate a random string of a given length.
257
- *
258
- * @param length - Desired string length
259
- * @param charset - Character set: `'alpha'`, `'numeric'`,
260
- * `'alphanumeric'` (default), `'hex'`, or a custom string
261
- * @returns Random string
262
- * @since 1.0.0
263
- */
264
- function randomString(length, charset = 'alphanumeric') {
265
- let chars;
266
- switch (charset) {
267
- case 'alpha':
268
- chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
269
- break;
270
- case 'numeric':
271
- chars = '0123456789';
272
- break;
273
- case 'alphanumeric':
274
- chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
275
- break;
276
- case 'hex':
277
- chars = '0123456789abcdef';
278
- break;
279
- default:
280
- chars = charset;
281
- }
282
- let result = '';
283
- for (let i = 0; i < length; i++) {
284
- result += chars.charAt(Math.floor(Math.random() * chars.length));
285
- }
286
- return result;
287
- }
288
- /**
289
- * Pluralize a word based on count.
290
- * Appends `'s'` by default when count is not 1.
291
- *
292
- * @param count - Item count
293
- * @param singular - Singular form
294
- * @param plural - Optional explicit plural form
295
- * @returns Singular or plural form based on count
296
- * @since 1.0.0
297
- *
298
- * @example
299
- * ```typescript
300
- * pluralize(1, 'item'); // "item"
301
- * pluralize(3, 'item'); // "items"
302
- * pluralize(2, 'child', 'children'); // "children"
303
- * ```
304
- */
305
- function pluralize(count, singular, plural) {
306
- if (count === 1) {
307
- return singular;
308
- }
309
- return plural || `${singular}s`;
310
- }
311
- /**
312
- * Format a number with commas as thousands separators.
313
- *
314
- * @param num - Number to format
315
- * @returns Formatted string (e.g., "1,234,567")
316
- * @since 1.0.0
317
- *
318
- * @example
319
- * ```typescript
320
- * formatNumber(1234567); // "1,234,567"
321
- * ```
322
- */
323
- function formatNumber(num) {
324
- return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
325
- }
326
- //# sourceMappingURL=string.js.map
@@ -1,92 +0,0 @@
1
- "use strict";
2
- /**
3
- * Centralized logging utility
4
- * Provides consistent logging across the application with proper formatting
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.storageLogger = exports.ensLogger = exports.contractLogger = exports.apiLogger = exports.authLogger = exports.logger = exports.LogLevel = void 0;
8
- var LogLevel;
9
- (function (LogLevel) {
10
- LogLevel["ERROR"] = "error";
11
- LogLevel["WARN"] = "warn";
12
- LogLevel["INFO"] = "info";
13
- LogLevel["DEBUG"] = "debug";
14
- })(LogLevel || (exports.LogLevel = LogLevel = {}));
15
- class Logger {
16
- constructor() {
17
- this.isDevelopment = process.env.NODE_ENV === 'development';
18
- }
19
- formatTimestamp() {
20
- return new Date().toISOString();
21
- }
22
- formatMessage(_level, message, context) {
23
- const timestamp = this.formatTimestamp();
24
- const contextStr = context ? ` [${context}]` : '';
25
- return `[${timestamp}]${contextStr} ${message}`;
26
- }
27
- shouldLog(level) {
28
- // In production, only log warnings and errors
29
- if (!this.isDevelopment) {
30
- return level === LogLevel.ERROR || level === LogLevel.WARN;
31
- }
32
- return true;
33
- }
34
- error(message, context, data) {
35
- if (this.shouldLog(LogLevel.ERROR)) {
36
- console.error(this.formatMessage(LogLevel.ERROR, message, context));
37
- if (data) {
38
- console.error(data);
39
- }
40
- }
41
- }
42
- warn(message, context, data) {
43
- if (this.shouldLog(LogLevel.WARN)) {
44
- console.warn(this.formatMessage(LogLevel.WARN, message, context));
45
- if (data) {
46
- console.warn(data);
47
- }
48
- }
49
- }
50
- info(message, context, data) {
51
- if (this.shouldLog(LogLevel.INFO)) {
52
- console.log(this.formatMessage(LogLevel.INFO, message, context));
53
- if (data) {
54
- console.log(data);
55
- }
56
- }
57
- }
58
- debug(message, context, data) {
59
- if (this.shouldLog(LogLevel.DEBUG)) {
60
- console.log(this.formatMessage(LogLevel.DEBUG, message, context));
61
- if (data) {
62
- console.log(data);
63
- }
64
- }
65
- }
66
- /**
67
- * Create a contextual logger that automatically includes context in all calls
68
- */
69
- withContext(context) {
70
- return {
71
- error: (message, data) => this.error(message, context, data),
72
- warn: (message, data) => this.warn(message, context, data),
73
- info: (message, data) => this.info(message, context, data),
74
- debug: (message, data) => this.debug(message, context, data),
75
- };
76
- }
77
- }
78
- // Export singleton instance
79
- const logger = new Logger();
80
- exports.logger = logger;
81
- // Export contextual loggers for common areas
82
- const authLogger = logger.withContext('AUTH');
83
- exports.authLogger = authLogger;
84
- const apiLogger = logger.withContext('API');
85
- exports.apiLogger = apiLogger;
86
- const contractLogger = logger.withContext('CONTRACT');
87
- exports.contractLogger = contractLogger;
88
- const ensLogger = logger.withContext('ENS');
89
- exports.ensLogger = ensLogger;
90
- const storageLogger = logger.withContext('STORAGE');
91
- exports.storageLogger = storageLogger;
92
- //# sourceMappingURL=logger.js.map