UNPKG

qapinterface

Version:

Comprehensive API utilities for Node.js applications including authentication, security, request processing, and response handling with zero external dependencies

32 lines (26 loc) 666 B
/** * API Key Generation * Single Responsibility: Generate secure API keys ONLY */ const crypto = require('crypto'); /** * Generates a secure API key. * @param {object} [options={}] - Generation options. * @returns {string} - Generated API key. */ function generateApiKey(options = {}) { const { length = 32, prefix = '', includeTimestamp = false } = options; const randomPart = crypto.randomBytes(length).toString('hex'); if (includeTimestamp) { const timestamp = Date.now().toString(36); return `${prefix}${timestamp}_${randomPart}`; } return `${prefix}${randomPart}`; } module.exports = { generateApiKey };