Skip to content

Instantly share code, notes, and snippets.

@Gimenz
Created August 7, 2021 20:51
Show Gist options
  • Save Gimenz/72758d16cae58230394de4907c478dd3 to your computer and use it in GitHub Desktop.
Save Gimenz/72758d16cae58230394de4907c478dd3 to your computer and use it in GitHub Desktop.
get random fake name using nodejs
const { default: axios } = require('axios');
const { JSDOM } = require('jsdom');
async function fakeName(age, gender = 'female', country = 'id_ID') {
try {
if (gender == 'female') {
gender = '100'
} else if (gender == 'male') {
gender == '0'
} else {
gender == '50'
}
const { data } = await axios.get('https://name-fake.com/' + country, {
data: encodeURIComponent(`con[]=${country}&perc=${gender}&miny=${age}&maxy=${age}`)
})
let dom = new JSDOM(data).window.document;
let prop = [...dom.querySelectorAll('div.from_div_45g45gg')].filter(x => x.textContent !== null)
let res = {}
for (let i = 0; i < prop.length; i++) {
let a = prop.map(x => x.textContent.replace(/\s+/g, '_').toLowerCase())
let val = dom.getElementById('copy' + (i + 1)).textContent
res[`${a[i]}`] = val
}
return res
} catch (error) {
return error
}
}
fakeName()
/* {
first_name: 'Laswi',
last_name: 'Rajasa',
username: 'rafid07',
email: 'rafid07@boranora.com',
password: 'ZFNfyBTIud',
company: 'Perum Sinaga Tbk',
country: 'Indonesia (Indonesia)',
postcode: '63041',
city: 'Bau-Bau',
address: 'Dk. Abdul Muis No. 348',
phone: '(+62) 984 5970 1320',
birthday: '1970-11-25',
age: '50',
gender: 'male',
mother_name: 'Widodo',
url: 'https://name-fake.com/id_ID/dfdaabb2b345fc35e63f62ebeb56062b'
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment