nigerian-mobile-validator
Version:
The most rigorous, up-to-date library for validating Nigerian mobile numbers. Fully NCC-compliant, and security-focused, with enterprise-grade features to prevent the business risks of validation failures in regulated industries.
66 lines (65 loc) • 2.88 kB
JavaScript
;
// src/number-validation/mobile-number-validation-result.ts
Object.defineProperty(exports, "__esModule", { value: true });
exports.MobileNumberValidationResult = void 0;
const mobile_validation_status_1 = require("./mobile-validation-status");
/**
* An object representing the result of validating the mobile number provided by the user.
*/
class MobileNumberValidationResult {
/**
* Create a new MobileNumberValidationResult
*
* @param userProvidedDigits The original digits input by user
* @param validationStatus Status enum representing error or success
* @param validationSucceeded Whether validation succeeded
* @param mobileNumber The validated mobile number (if successful)
* @param telcoNumberAllocation The telco allocation details (if successful)
*/
constructor(_userProvidedDigits, _validationStatus, _validationSucceeded, _mobileNumber, _telcoNumberAllocation) {
this._userProvidedDigits = _userProvidedDigits;
this._validationStatus = _validationStatus;
this._validationSucceeded = _validationSucceeded;
this._mobileNumber = _mobileNumber;
this._telcoNumberAllocation = _telcoNumberAllocation;
// Ensure we have a MobileNumber if validation succeeded
if (_validationSucceeded && !_mobileNumber) {
throw new Error('Mobile number must be provided when validation succeeds');
}
}
/** The original digits input by user. */
get userProvidedDigits() {
return this._userProvidedDigits;
}
/** Status enum representing error or success message of the validation. */
get validationStatus() {
return this._validationStatus;
}
/** User-friendly message for this validation result */
get userMessage() {
return mobile_validation_status_1.ValidationStatusMessages[this._validationStatus].userMessage;
}
/** Developer-friendly message for this validation result */
get devMessage() {
return mobile_validation_status_1.ValidationStatusMessages[this._validationStatus].devMessage;
}
/** Whether validation of a user supplied mobile number was successful. */
get validationSucceeded() {
return this._validationSucceeded;
}
/** If validation succeeded, the validated MobileNumber. */
get mobileNumber() {
return this._mobileNumber;
}
/** If validation succeeded, details about the telco allocation. */
get telcoNumberAllocation() {
return this._telcoNumberAllocation;
}
/**
* Create an empty validation result (for initial state).
*/
static empty() {
return new MobileNumberValidationResult('', mobile_validation_status_1.MobileValidationStatus.IncorrectNumberOfDigits, false, undefined, undefined);
}
}
exports.MobileNumberValidationResult = MobileNumberValidationResult;