Reference - Functions

This section provides detailed information about the available functions, their parameters, return values, and usage examples.

Core Functions

CalculateSum(number1, number2)

CalculateSum(number1: number, number2: number): number

Calculates the sum of two numbers.

Parameters:
  • number1: The first number.
  • number2: The second number.
Returns: The sum of number1 and number2.

Example:


const result = CalculateSum(5, 10);
console.log(result); // Output: 15
                    

FormatDate(date, formatString)

FormatDate(date: Date, formatString: string = 'YYYY-MM-DD'): string

Formats a given Date object into a string representation based on the specified format.

Parameters:
  • date: The Date object to format.
  • formatString: The desired format string (e.g., 'YYYY-MM-DD', 'MM/DD/YYYY HH:mm:ss'). Defaults to 'YYYY-MM-DD'.
Returns: A string representing the formatted date.

Example:


const today = new Date();
const formatted = FormatDate(today, 'DD-MM-YYYY');
console.log(formatted); // Output: (e.g., 26-10-2023)

const verboseDate = FormatDate(new Date(2023, 9, 26, 14, 30, 0), 'YYYY-MM-DD HH:mm:ss');
console.log(verboseDate); // Output: 2023-10-26 14:30:00
                    

GetUserById(userId)

GetUserById(userId: string): Promise<User | null>

Retrieves user information from the API based on their unique ID.

Parameters:
  • userId: The unique identifier of the user.
Returns: A Promise that resolves with a User object if found, or null if the user does not exist.

Example:


async function displayUser(id) {
    const user = await GetUserById(id);
    if (user) {
        console.log(`User found: ${user.name}`);
    } else {
        console.log('User not found.');
    }
}

displayUser('user-123');
                    

See Also