@openzeppelin/ui-utils 1.2.0 → 1.2.2

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 CHANGED
@@ -1156,6 +1156,25 @@ function formatTimestamp(date) {
1156
1156
  return date.toLocaleDateString();
1157
1157
  }
1158
1158
  /**
1159
+ * Formats seconds into a human-readable duration string (e.g. "1 day", "24 hours", "30 minutes").
1160
+ * @param seconds Duration in seconds
1161
+ * @returns Human-readable string with correct singular/plural
1162
+ */
1163
+ function formatSecondsToReadable(seconds) {
1164
+ if (seconds <= 0 || !Number.isFinite(seconds)) return "0 seconds";
1165
+ if (seconds < 60) return seconds === 1 ? "1 second" : `${seconds} seconds`;
1166
+ if (seconds < 3600) {
1167
+ const mins = Math.floor(seconds / 60);
1168
+ return mins === 1 ? "1 minute" : `${mins} minutes`;
1169
+ }
1170
+ if (seconds < 86400) {
1171
+ const hours = Math.floor(seconds / 3600);
1172
+ return hours === 1 ? "1 hour" : `${hours} hours`;
1173
+ }
1174
+ const days = Math.floor(seconds / 86400);
1175
+ return days === 1 ? "1 day" : `${days} days`;
1176
+ }
1177
+ /**
1159
1178
  * Detects whether a string contains hex-encoded or base64-encoded binary data.
1160
1179
  * Useful for auto-detecting the encoding format of user inputs across blockchain adapters.
1161
1180
  *
@@ -1425,7 +1444,7 @@ function simpleHash(str) {
1425
1444
  * ```
1426
1445
  */
1427
1446
  function validateBytes(value, options = {}) {
1428
- const { acceptedFormats = "both", maxBytes, allowHexPrefix = true } = options;
1447
+ const { acceptedFormats = "both", maxBytes, exactBytes, allowHexPrefix = true } = options;
1429
1448
  if (!value || value.trim() === "") return {
1430
1449
  isValid: true,
1431
1450
  cleanedValue: "",
@@ -1487,6 +1506,13 @@ function validateBytes(value, options = {}) {
1487
1506
  cleanedValue: cleanValue,
1488
1507
  detectedFormat
1489
1508
  };
1509
+ if (exactBytes && byteSize !== exactBytes) return {
1510
+ isValid: false,
1511
+ error: `Exactly ${exactBytes} bytes required (${detectedFormat === "hex" ? `${exactBytes * 2} hex characters` : `${exactBytes} bytes`}), got ${byteSize} bytes`,
1512
+ cleanedValue: cleanValue,
1513
+ detectedFormat,
1514
+ byteSize
1515
+ };
1490
1516
  if (maxBytes && byteSize > maxBytes) return {
1491
1517
  isValid: false,
1492
1518
  error: `Maximum ${maxBytes} bytes allowed (${detectedFormat === "hex" ? `${maxBytes * 2} hex characters` : `${maxBytes} bytes`})`,
@@ -2469,6 +2495,7 @@ exports.detectServiceType = detectServiceType;
2469
2495
  exports.enhanceNumericValidation = enhanceNumericValidation;
2470
2496
  exports.findRoleAssignment = findRoleAssignment;
2471
2497
  exports.formatAccessControlError = formatAccessControlError;
2498
+ exports.formatSecondsToReadable = formatSecondsToReadable;
2472
2499
  exports.formatTimestamp = formatTimestamp;
2473
2500
  exports.generateId = generateId;
2474
2501
  exports.getAllMembers = getAllMembers;