| 123456789101112131415161718192021222324252627282930313233343536373839 |
- const randomNumber = max => {
- return Math.floor(Math.random() * max) < 1
- ? 1
- : Math.floor(Math.random() * max)
- }
- const randomValFrom = arr => arr[randomNumber(arr.length)]
- const randomEmail = (length = 5) => {
- let chars =
- 'abcdefghijklmnopqrstuvwxyz-_abcdefghijklmnopqrstuvwxyz0123456789'
- let str = ''
- for (let i = 0; i < length + randomNumber(9); i++) {
- str += chars.charAt(Math.floor(Math.random() * chars.length))
- }
- const suffixs = [
- '@gmail.com',
- '@aol.com',
- '@yahoo.com',
- '@apple.com',
- '@hotmail.com',
- '@rocket-mail.com',
- '@mail.com',
- ]
- return str + randomValFrom(suffixs)
- }
- const randomName = (length = 4) => {
- let chars = 'aeiouaeiouabcdefghijklmnoprstuvwyabcdefghijklmnopqrstuvwxyz'
- let str = ''
- for (let i = 0; i < length + randomNumber(9); i++) {
- str += chars.charAt(Math.floor(Math.random() * chars.length))
- }
- return str
- }
-
- module.exports = {
- number: randomNumber,
- valFrom: randomValFrom,
- email: randomEmail,
- name: randomName,
- }
|