core-utils
    Preparing search index...
    • Formats a phone number to the specified format, throwing an error if formatting fails.

      This is a convenience function that wraps formatPhoneNumber and throws an error instead of returning a ServiceResult. Use this when you want to handle errors via exception handling rather than explicit error checking.

      Parameters

      Returns string

      The formatted phone number

      Error when the phone number cannot be formatted (invalid format, missing country code, etc.)

      try {
      const formatted = formatPhoneNumberOrThrow({ phoneNumber: "(555) 123-4567", format: "E.164" });
      console.log(formatted); // "+15551234567"
      } catch (error) {
      console.error("Invalid phone number:", error.message);
      }