Represents a user in the system with validation and utility methods.
constructor(name: string, email: string, age: number)Parameters:
name- User's full name (required, non-empty)email- User's email address (required, valid email format)age- User's age (required, 0-150)
Throws:
Error- If name is emptyError- If email is invalidError- If age is outside valid range
Returns the user's unique identifier.
Returns the date when the user was created.
Returns true if the user is 18 or older.
Returns formatted display name (e.g., "John Doe (25)").
Returns string representation of the user.
Returns JSON-serializable object representation.
import { User } from './models/user';
const user = new User('John Doe', 'john@example.com', 25);
console.log(user.getDisplayName()); // "John Doe (25)"
console.log(user.isAdult()); // trueProvides mathematical operations with error handling.
Adds two numbers.
Subtracts second number from first.
Multiplies two numbers.
Divides first number by second.
Throws: Error if dividing by zero.
Calculates base raised to exponent.
Calculates square root.
Throws: Error if value is negative.
Calculates percentage of a value.
Returns true if number is even.
Returns true if number is odd.
Returns absolute value.
import { Calculator } from './services/calculator';
const calc = new Calculator();
console.log(calc.add(5, 3)); // 8
console.log(calc.divide(10, 2)); // 5
console.log(calc.isEven(4)); // trueProvides leveled logging functionality.
constructor(logLevel: LogLevel = LogLevel.INFO)enum LogLevel {
DEBUG = 0,
INFO = 1,
WARN = 2,
ERROR = 3,
}Sets the minimum log level.
Logs debug message (only if log level allows).
Logs info message (only if log level allows).
Logs warning message (only if log level allows).
Logs error message with optional Error object.
import { Logger, LogLevel } from './utils/logger';
const logger = new Logger(LogLevel.DEBUG);
logger.info('Application started');
logger.warn('This is a warning');
logger.error('Something went wrong', new Error('Details'));Creates a delay for the specified number of milliseconds.
Generates random integer between min and max (inclusive).
Type guard to check if value is not null or undefined.
Capitalizes the first letter of a string.
Converts camelCase to kebab-case.
Converts kebab-case to camelCase.
Creates a deep clone of an object.
Removes duplicate values from an array.
Groups array elements by a key function.
import { delay, randomInt, capitalize, deepClone } from './utils/helpers';
// Delay execution
await delay(1000);
// Generate random number
const num = randomInt(1, 10);
// Capitalize string
const name = capitalize('john'); // "John"
// Deep clone object
const original = { a: 1, b: { c: 2 } };
const cloned = deepClone(original);