UNPKG

@resk/core

Version:

An innovative TypeScript framework that empowers developers to build applications with a fully decorator-based architecture for efficient resource management. By combining the power of decorators with a resource-oriented design, DecorRes enhances code cla

159 lines (158 loc) β€’ 5.47 kB
import { ICurrency } from "../currency/types"; import { ICountry, ICountryCode } from "./types"; export * from "./types"; /** * Class representing a collection of countries with their associated properties. * * @example * ```typescript * CountriesManager.setCountry({ * code: 'US', * dialCode: '+1', * phoneNumberExample: '(123) 456-7890', * flag: 'πŸ‡ΊπŸ‡Έ' * }); * * const usCountry = CountriesManager.getCountry('US'); * console.log(usCountry); // { code: 'US', dialCode: '+1', phoneNumberExample: '(123) 456-7890', flag: 'πŸ‡ΊπŸ‡Έ' } * ``` */ export declare class CountriesManager { /** * A private static record of countries, where each key is a country code and each value is an ICountry object. * * @private * @type {Record<ICountryCode, ICountry>} */ private static countries; /** * Checks if a given country object is valid. * * A country object is considered valid if it is an object and has a non-null string code. * * @param {ICountry} country The country object to check. * @returns {boolean} True if the country object is valid, false otherwise. * * @example * ```typescript * const country: ICountry = { * code: 'US', * dialCode: '+1', * phoneNumberExample: '(123) 456-7890', * flag: 'πŸ‡ΊπŸ‡Έ' * }; * console.log(CountriesManager.isValid(country)); // true * ``` */ static isValid(country: ICountry): boolean; /** * Gets the phone number example for a given country code. * * @param {ICountryCode} code The country code. * @returns {string} The phone number example for the given country code, or an empty string if the country code is not found. * * @example * ```typescript * console.log(CountriesManager.getPhoneNumberExample('US')); // '(123) 456-7890' * ``` */ static getPhoneNumberExample(code: ICountryCode): string; /** * Gets the flag for a given country code. * * @param {ICountryCode} code The country code. * @returns {string} The flag for the given country code, or an empty string if the country code is not found. * * @example * ```typescript * console.log(CountriesManager.getFlag('US')); // 'πŸ‡ΊπŸ‡Έ' * ``` */ static getFlag(code: ICountryCode): string; /** * Gets the currency for a given country code. * * @param {ICountryCode} code The country code. * @returns {ICurrency | undefined} The currency for the given country code, or undefined if the country code is not found. * * @example * ```typescript * console.log(CountriesManager.getCurrency('US')); // { code: 'USD', symbol: '$' } * ``` */ static getCurrency(code: ICountryCode): ICurrency | undefined; /** * Sets a country object in the internal record. * * The country object must be valid (i.e., it must be an object with a non-null string code). * * @param {ICountry} country The country object to set. * * @example * ```typescript * CountriesManager.setCountry({ * code: 'US', * dialCode: '+1', * phoneNumberExample: '(123) 456-7890', * flag: 'πŸ‡ΊπŸ‡Έ' * }); * ``` */ static setCountry(country: ICountry): void; /** * Retrieves a country object by its country code. * * If the provided code is not a non-null string, it returns undefined. * * @param {ICountryCode} code The country code to look up. * @returns {ICountry | undefined} The country object associated with the given code, or undefined if not found. * * @example * ```typescript * const country = CountriesManager.getCountry('US'); * console.log(country); // { code: 'US', dialCode: '+1', phoneNumberExample: '(123) 456-7890', flag: 'πŸ‡ΊπŸ‡Έ' } * ``` */ static getCountry(code: ICountryCode): ICountry | undefined; /** * Retrieves all countries stored in the internal record. * * @returns {Record<ICountryCode, ICountry>} A record of all countries, where each key is a country code and each value is an ICountry object. * * @example * ```typescript * const allCountries = CountriesManager.getCountries(); * console.log(allCountries); // { 'US': { code: 'US', ... }, ... } * ``` */ static getCountries(): Record<ICountryCode, ICountry>; /** * Sets multiple countries in the internal record. * * This method merges the provided countries with the existing ones in the internal record. * * If the provided countries object is not an object, it returns the current internal record of countries. * * @param {Partial<Record<ICountryCode, ICountry>>} countries A partial record of countries to set. * @returns {Record<ICountryCode, ICountry>} The updated internal record of countries. * * @example * ```typescript * Country.setCountries({ * 'US': { * code: 'US', * dialCode: '+1', * phoneNumberExample: '(123) 456-7890', * flag: 'πŸ‡ΊπŸ‡Έ' * }, * 'CA': { * code: 'CA', * dialCode: '+1', * phoneNumberExample: '(123) 456-7890', * flag: 'πŸ‡¨πŸ‡¦' * } * }); * ``` */ static setCountries(countries: Partial<Record<ICountryCode, ICountry>>): Record<ICountryCode, ICountry>; }