@alviere/core 0.16.3 → 0.17.1

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.mjs CHANGED
@@ -398,6 +398,10 @@ class Validator {
398
398
  if (trimmed.includes("..")) {
399
399
  return "Please enter a valid email address.";
400
400
  }
401
+ const localPart = trimmed.split("@")[0];
402
+ if (localPart.startsWith(".") || localPart.endsWith(".")) {
403
+ return "Please enter a valid email address.";
404
+ }
401
405
  const emailRegEx = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+$/;
402
406
  if (!emailRegEx.test(trimmed)) {
403
407
  return "Please enter a valid email address.";
@@ -420,7 +424,7 @@ class Validator {
420
424
  * @param date - The date string to validate
421
425
  * @param format - The expected date format (default: 'YYYY-MM-DD')
422
426
  */
423
- date(date, format = "YYYY-MM-DD") {
427
+ date(date, _format = "YYYY-MM-DD") {
424
428
  if (!date || typeof date !== "string") {
425
429
  return "Please enter a valid date.";
426
430
  }
@@ -526,6 +530,31 @@ class Validator {
526
530
  }
527
531
  return null;
528
532
  }
533
+ /**
534
+ * Validates that a value is a valid human name.
535
+ * Accepts Unicode letters (including diacritics), combining marks, spaces,
536
+ * digits, hyphens, apostrophes, periods, and commas. Diacritics, periods,
537
+ * and commas are accepted here so the user is never shown a validation error
538
+ * for a legitimate name — callers are responsible for normalising the value
539
+ * to the API-accepted character set before sending (API regex:
540
+ * ^[a-zA-Z0-9' -]{1,40}$).
541
+ * Length is enforced to match API limits: min 1, max 40 characters.
542
+ * @param value - The value to validate
543
+ * @param fieldName - Optional field name for error message
544
+ */
545
+ nameField(value, fieldName) {
546
+ if (!value || typeof value !== "string") {
547
+ return fieldName ? `${fieldName} is required.` : "This field is required.";
548
+ }
549
+ const trimmed = value.trim();
550
+ if (trimmed.length > 40) {
551
+ return fieldName ? `${fieldName} must be no more than 40 characters long.` : "Must be no more than 40 characters long.";
552
+ }
553
+ if (!/^[-.,\p{L}\p{M}\s\d\u0027\u2019]+$/u.test(trimmed)) {
554
+ return fieldName ? `${fieldName} must contain only letters, numbers, spaces, hyphens, apostrophes, periods, and commas.` : "Must contain only letters, numbers, spaces, hyphens, apostrophes, periods, and commas.";
555
+ }
556
+ return null;
557
+ }
529
558
  /**
530
559
  * Validates that a value contains only letters and numbers
531
560
  * @param value - The value to validate