ngxsmk-tel-input
Version:
Angular international telephone input (intl-tel-input UI + libphonenumber-js validation). ControlValueAccessor. SSR-safe.
135 lines • 4.5 kB
TypeScript
/**
* Enhanced TypeScript types and type guards for ngxsmk-tel-input
*/
import { CountryCode } from 'libphonenumber-js';
import { ParseResult, ParseWithInvalidResult } from './ngxsmk-tel-input.service';
import { CarrierInfo, FormatSuggestion } from './phone-intelligence.service';
/**
* Type guard to check if a value is a valid CountryCode
*/
export declare function isCountryCode(value: unknown): value is CountryCode;
/**
* Type guard to check if a value is a valid phone number string
*/
export declare function isPhoneNumberString(value: unknown): value is string;
/**
* Type guard to check if ParseResult is valid
*/
export declare function isValidParseResult(result: ParseResult | ParseWithInvalidResult): result is ParseResult & {
e164: string;
};
/**
* Type guard to check if value is E.164 format
*/
export declare function isE164Format(value: unknown): value is string;
/**
* Type guard to check if CarrierInfo is complete
*/
export declare function isCompleteCarrierInfo(info: CarrierInfo | null): info is CarrierInfo;
/**
* Type guard to check if FormatSuggestion has high confidence
*/
export declare function isHighConfidenceSuggestion(suggestion: FormatSuggestion | null): suggestion is FormatSuggestion;
/**
* Strict type for phone input configuration
*/
export interface StrictPhoneInputConfig {
readonly initialCountry: CountryCode | 'auto';
readonly preferredCountries: readonly CountryCode[];
readonly onlyCountries?: readonly CountryCode[];
readonly separateDialCode: boolean;
readonly allowDropdown: boolean;
readonly nationalDisplay: 'formatted' | 'digits';
readonly formatWhenValid: 'off' | 'blur' | 'typing';
readonly size: 'sm' | 'md' | 'lg';
readonly variant: 'outline' | 'filled' | 'underline';
readonly theme: 'light' | 'dark' | 'auto';
readonly disabled: boolean;
readonly enableIntelligence: boolean;
readonly enableFormatSuggestions: boolean;
}
/**
* Type-safe phone input event
*/
export interface PhoneInputEvent {
readonly raw: string;
readonly e164: string | null;
readonly iso2: CountryCode;
readonly isValid: boolean;
readonly timestamp: number;
}
/**
* Type-safe country change event
*/
export interface CountryChangeEvent {
readonly iso2: CountryCode;
readonly previousIso2?: CountryCode;
readonly timestamp: number;
}
/**
* Type-safe validation event
*/
export interface ValidationEvent {
readonly isValid: boolean;
readonly errors: readonly string[];
readonly timestamp: number;
}
/**
* Utility type to extract input signal types
*/
export type InputSignalType<T> = T extends import('@angular/core').InputSignal<infer U> ? U : never;
/**
* Utility type to extract output signal types
*/
export type OutputSignalType<T> = T extends import('@angular/core').OutputEmitterRef<infer U> ? U : never;
/**
* Branded type for E.164 phone numbers
*/
export type E164PhoneNumber = string & {
readonly __brand: 'E164PhoneNumber';
};
/**
* Create a branded E.164 phone number
*/
export declare function createE164PhoneNumber(value: string): E164PhoneNumber | null;
/**
* Branded type for national phone numbers
*/
export type NationalPhoneNumber = string & {
readonly __brand: 'NationalPhoneNumber';
};
/**
* Create a branded national phone number
*/
export declare function createNationalPhoneNumber(value: string, country: CountryCode): NationalPhoneNumber | null;
/**
* Type-safe phone number validation result
*/
export interface TypedValidationResult {
readonly isValid: boolean;
readonly e164: E164PhoneNumber | null;
readonly national: NationalPhoneNumber | null;
readonly country: CountryCode;
readonly errors: readonly ValidationError[];
}
/**
* Validation error with type information
*/
export interface ValidationError {
readonly code: 'REQUIRED' | 'INVALID' | 'INVALID_COUNTRY_CODE' | 'TOO_SHORT' | 'TOO_LONG';
readonly message: string;
readonly field?: string;
}
/**
* Create a typed validation result
*/
export declare function createTypedValidationResult(parseResult: ParseResult, country: CountryCode): TypedValidationResult;
/**
* Assert that a value is a CountryCode (throws if not)
*/
export declare function assertCountryCode(value: unknown): asserts value is CountryCode;
/**
* Assert that a value is E.164 format (throws if not)
*/
export declare function assertE164Format(value: unknown): asserts value is E164PhoneNumber;
//# sourceMappingURL=types-enhanced.d.ts.map