mirror of
https://github.com/duhanbalci/iyzico.git
synced 2026-03-03 20:29:18 +00:00
29 lines
774 B
TypeScript
29 lines
774 B
TypeScript
/**
|
|
* Utility functions
|
|
*/
|
|
|
|
/**
|
|
* Generates a random number between min and max (inclusive)
|
|
* @param min - Minimum value (default: 0)
|
|
* @param max - Maximum value (default: 100)
|
|
* @returns Random number between min and max
|
|
*/
|
|
export function generateRandomNumber(min: number = 0, max: number = 100): number {
|
|
if (min > max) {
|
|
throw new Error('Min value cannot be greater than max value');
|
|
}
|
|
return Math.floor(Math.random() * (max - min + 1)) + min;
|
|
}
|
|
|
|
/**
|
|
* Generates a random key for İyzico API requests
|
|
* Uses timestamp + random number combination
|
|
* @returns Random key string
|
|
*/
|
|
export function generateRandomKey(): string {
|
|
const timestamp = Date.now();
|
|
const random = generateRandomNumber(100000, 999999);
|
|
return `${timestamp}${random}`;
|
|
}
|
|
|