DashXx / plugins /random-generator.js
HerzaJ's picture
Upload 56 files
7c363b0 verified
const crypto = require('crypto');
const WORD_LISTS = {
lorem: [
'lorem', 'ipsum', 'dolor', 'sit', 'amet', 'consectetur', 'adipiscing', 'elit',
'sed', 'do', 'eiusmod', 'tempor', 'incididunt', 'ut', 'labore', 'et', 'dolore',
'magna', 'aliqua', 'enim', 'ad', 'minim', 'veniam', 'quis', 'nostrud',
'exercitation', 'ullamco', 'laboris', 'nisi', 'aliquip', 'ex', 'ea', 'commodo',
'consequat', 'duis', 'aute', 'irure', 'in', 'reprehenderit', 'voluptate',
'velit', 'esse', 'cillum', 'fugiat', 'nulla', 'pariatur', 'excepteur', 'sint',
'occaecat', 'cupidatat', 'non', 'proident', 'sunt', 'culpa', 'qui', 'officia',
'deserunt', 'mollit', 'anim', 'id', 'est', 'laborum'
],
english: [
'the', 'quick', 'brown', 'fox', 'jumps', 'over', 'lazy', 'dog', 'and', 'runs',
'through', 'forest', 'while', 'birds', 'sing', 'beautiful', 'songs', 'under',
'bright', 'sunny', 'sky', 'with', 'clouds', 'floating', 'peacefully', 'above',
'green', 'trees', 'beside', 'flowing', 'river', 'where', 'fish', 'swim',
'quietly', 'among', 'rocks', 'covered', 'moss', 'creating', 'natural', 'harmony'
],
tech: [
'algorithm', 'database', 'framework', 'library', 'function', 'variable', 'array',
'object', 'method', 'class', 'interface', 'component', 'module', 'package',
'deployment', 'server', 'client', 'backend', 'frontend', 'fullstack', 'api',
'endpoint', 'authentication', 'authorization', 'encryption', 'decryption',
'blockchain', 'machine', 'learning', 'artificial', 'intelligence', 'neural',
'network', 'deep', 'learning', 'data', 'science', 'analytics', 'visualization'
]
};
const CHARACTERS = {
lowercase: 'abcdefghijklmnopqrstuvwxyz',
uppercase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
numbers: '0123456789',
symbols: '!@#$%^&*()_+-=[]{}|;:,.<>?',
special: '!@#$%^&*'
};
const generateRandomWords = (count, wordList) => {
const words = [];
for (let i = 0; i < count; i++) {
const randomIndex = Math.floor(Math.random() * wordList.length);
words.push(wordList[randomIndex]);
}
return words.join(' ');
};
const generateRandomString = (length, charset) => {
let result = '';
for (let i = 0; i < length; i++) {
result += charset.charAt(Math.floor(Math.random() * charset.length));
}
return result;
};
const generatePassword = (length, options) => {
let charset = '';
if (options.lowercase) charset += CHARACTERS.lowercase;
if (options.uppercase) charset += CHARACTERS.uppercase;
if (options.numbers) charset += CHARACTERS.numbers;
if (options.symbols) charset += CHARACTERS.symbols;
if (!charset) charset = CHARACTERS.lowercase + CHARACTERS.uppercase + CHARACTERS.numbers;
return generateRandomString(length, charset);
};
const generateSentences = (count, wordList, minWords = 5, maxWords = 15) => {
const sentences = [];
for (let i = 0; i < count; i++) {
const wordCount = Math.floor(Math.random() * (maxWords - minWords + 1)) + minWords;
const words = [];
for (let j = 0; j < wordCount; j++) {
const randomIndex = Math.floor(Math.random() * wordList.length);
words.push(wordList[randomIndex]);
}
let sentence = words.join(' ');
sentence = sentence.charAt(0).toUpperCase() + sentence.slice(1) + '.';
sentences.push(sentence);
}
return sentences.join(' ');
};
const handler = async (req, res) => {
try {
const {
type = 'words',
count = 10,
length = 12,
wordType = 'lorem',
includeNumbers = true,
includeUppercase = true,
includeLowercase = true,
includeSymbols = false,
minWords = 5,
maxWords = 15
} = req.query;
const validTypes = ['words', 'sentences', 'paragraphs', 'password', 'string', 'uuid'];
const validWordTypes = Object.keys(WORD_LISTS);
if (!validTypes.includes(type)) {
return res.status(400).json({
success: false,
error: `Invalid type. Valid types: ${validTypes.join(', ')}`
});
}
if (!validWordTypes.includes(wordType) && ['words', 'sentences', 'paragraphs'].includes(type)) {
return res.status(400).json({
success: false,
error: `Invalid wordType. Valid wordTypes: ${validWordTypes.join(', ')}`
});
}
let result = '';
const wordList = WORD_LISTS[wordType] || WORD_LISTS.lorem;
switch (type) {
case 'words':
result = generateRandomWords(parseInt(count), wordList);
break;
case 'sentences':
result = generateSentences(parseInt(count), wordList, parseInt(minWords), parseInt(maxWords));
break;
case 'paragraphs':
const paragraphs = [];
for (let i = 0; i < parseInt(count); i++) {
const sentenceCount = Math.floor(Math.random() * 6) + 3;
paragraphs.push(generateSentences(sentenceCount, wordList, parseInt(minWords), parseInt(maxWords)));
}
result = paragraphs.join('\n\n');
break;
case 'password':
const passwordOptions = {
lowercase: includeLowercase === 'true',
uppercase: includeUppercase === 'true',
numbers: includeNumbers === 'true',
symbols: includeSymbols === 'true'
};
result = generatePassword(parseInt(length), passwordOptions);
break;
case 'string':
let charset = '';
if (includeLowercase === 'true') charset += CHARACTERS.lowercase;
if (includeUppercase === 'true') charset += CHARACTERS.uppercase;
if (includeNumbers === 'true') charset += CHARACTERS.numbers;
if (includeSymbols === 'true') charset += CHARACTERS.symbols;
if (!charset) charset = CHARACTERS.lowercase + CHARACTERS.numbers;
result = generateRandomString(parseInt(length), charset);
break;
case 'uuid':
result = crypto.randomUUID();
break;
}
res.json({
success: true,
data: {
type,
result,
length: result.length,
word_count: result.split(' ').length,
generated_at: new Date().toISOString(),
parameters: {
type,
count: parseInt(count),
length: parseInt(length),
wordType,
includeNumbers: includeNumbers === 'true',
includeUppercase: includeUppercase === 'true',
includeLowercase: includeLowercase === 'true',
includeSymbols: includeSymbols === 'true'
}
}
});
} catch (error) {
res.status(500).json({
success: false,
error: error.message
});
}
};
module.exports = {
name: 'Random Text Generator',
description: 'Generate random text, words, sentences, passwords, and UUIDs',
type: 'GET',
routes: ['api/tools/random/text'],
tags: ['utility', 'random', 'generator', 'text'],
parameters: ['type', 'count', 'length', 'wordType', 'includeNumbers', 'includeUppercase', 'includeLowercase', 'includeSymbols'],
enabled: true,
main: ['tools'],
handler
};