const axios = require('axios'); class UsernameGen { constructor() { this.headers = { referer: 'https://usernamegenerator.com/', 'user-agent': 'Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Mobile Safari/537.36' }; } validate(input, fieldName) { if (!input) throw new Error(`${fieldName} is required`); if (!/^[a-zA-Z0-9]+$/.test(input)) throw new Error(`${fieldName} must contain only letters and numbers (no spaces or special characters)`); return input; } create = async function (keyword, { mode = 'instans', theme = 'action' } = {}) { try { keyword = this.validate(keyword, 'Keyword'); const conf = { modes: ['instans', 'ai'], themes: ['action', 'adventure', 'fantasy', 'historical', 'horror', 'mythology', 'nature', 'sci-fi', 'strategy'] }; if (!conf.modes.includes(mode)) throw new Error(`Available modes: ${conf.modes.join(', ')}`); if (mode === 'instans') { const { data } = await axios.get(`https://usernamegenerator.com/wk/gamertags/${keyword}`, { headers: this.headers }); return data; } else { if (!conf.themes.includes(theme)) throw new Error(`Available themes: ${conf.themes.join(', ')}`); const { data } = await axios.post('https://usernamegenerator.com/ai/generate/player-names', { genre: theme, keywords: keyword }, { headers: this.headers }); return data; } } catch (error) { throw new Error(error.message); } } mix = async function (name1, name2) { try { name1 = this.validate(name1, 'Name1'); name2 = this.validate(name2, 'Name2'); const { data } = await axios.get(`https://usernamegenerator.com/wk/mix-words/${name1}-${name2}`, { headers: this.headers }); return data; } catch (error) { throw new Error(error.message); } } } // Usage: const u = new UsernameGen(); const resp = await u.create('rynn', { mode: 'ai', theme: 'fantasy' }); console.log(resp);