Last active
July 21, 2023 13:41
-
-
Save pedrouid/731b93b728ab59cd9ae02abc95957a94 to your computer and use it in GitHub Desktop.
Random Domain Name Generator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// @desc Creates a list of domains with custom TLDs using a pattern string with fixed length with option for keywords | |
// @param {String} pattern | |
// @param {Array|String} tlds | |
// @returns {Array} domainList | |
// | |
// | |
// Pattern string is defined by: | |
// - keywords lowercase | |
// - any letter uppercase A | |
// - consonants uppercase C | |
// - vowels uppercase V | |
function domainListGenerator (pattern, tlds) { | |
const _pattern = pattern.match(/[ACV]|[a-z]+/g); | |
const alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']; | |
const consonants = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'y', 'z']; | |
const vowels = ['a', 'e', 'i', 'o', 'u']; | |
let domainList = []; | |
function iterator (lastIndex, word = '', tld = '.com') { | |
const index = lastIndex + 1; | |
if (index > _pattern.length - 1) { | |
let _tld = tld.slice(0, 1) === '.' ? tld : '.' + tld; | |
let domain = word + _tld; | |
domainList.push(domain.toLowerCase()); | |
} else if (_pattern[index] === 'A') { | |
alphabet.map(letter => | |
iterator(index, word + letter, tld) | |
); | |
} else if (_pattern[index] === 'C') { | |
consonants.map(consonant => | |
iterator(index, word + consonant, tld) | |
); | |
} else if (_pattern[index] === 'V') { | |
vowels.map(vowel => | |
iterator(index, word + vowel, tld) | |
); | |
} else { | |
iterator(index, word + _pattern[index], tld); | |
} | |
} | |
if (Array.isArray(tlds)) { | |
tlds.map(tld => iterator(-1, '', tld)); | |
} else if (typeof tlds === 'string') { | |
iterator(-1, '', tlds); | |
} else if (!tlds) { | |
iterator(-1); | |
} | |
return domainList; | |
} | |
// ..... EXAMPLES ..... | |
domainListGenerator('CVVC') // ['baab.com', 'baac.com', ...] | |
domainListGenerator('CVVC', '.io') // ['baab.io', 'baeb.io', ...] | |
domainListGenerator('Vsocial', '.io') // ['asocial.io', 'esocial.io', ...] | |
domainListGenerator('educationVC', '.org') // ['educationab.org', 'educationac.org', ...] | |
domainListGenerator('coinCVC', ['.net', '.io']) // ['coinbab.net', 'coinbac.net', ..., 'coinbab.io', 'coinbac.io', ...] | |
// @desc Returns a random domain with custom TLD using a pattern string with fixed length with option for keywords | |
// @param {String} pattern | |
// @param {String} tld | |
// @returns {String} domain | |
// | |
// | |
// Pattern string is defined by: | |
// - keywords lowercase | |
// - any letter uppercase A | |
// - consonants uppercase C | |
// - vowels uppercase V | |
function domainNameGenerator (pattern, tld) { | |
const domainList = domainListGenerator(pattern, tld); | |
const index = Math.floor(Math.random() * domainList.length); | |
const domain = domainList[index]; | |
return domain; | |
} | |
// ..... EXAMPLES ..... | |
domainNameGenerator('CVVC') // biex.com | |
domainNameGenerator('CVVC', '.io') // tual.io | |
domainNameGenerator('Vsocial', '.io') // zsocial.io | |
domainNameGenerator('educationVC', '.org') // educational.org | |
domainNameGenerator('coinCVC', '.net') // coinrev.net |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment