JavaScript Python PHP
async function executar(values) {
function generateFrontendLorem(v) {
const unit = feChoice(v.unit, ['palavras', 'frases', 'parágrafos']), count = feInteger(v.count, 'Quantidade', 1, unit === 'palavras' ? 500 : unit === 'frases' ? 100 : 30);
const words = 'lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur'.split(' ');
if (unit === 'palavras')
return { text: Array.from({ length: count }, (_, i) => words[i % words.length]).join(' ') };
const sentences = Array.from({ length: count * (unit === 'parágrafos' ? 4 : 1) }, (_, i) => { const sentence = Array.from({ length: 12 }, (_, j) => words[(i * 12 + j) % words.length]).join(' '); return sentence[0].toUpperCase() + sentence.slice(1) + '.'; });
return { text: unit === 'frases' ? sentences.join(' ') : Array.from({ length: count }, (_, i) => sentences.slice(i * 4, i * 4 + 4).join(' ')).join('\n\n') };
}
function feInteger(value, label, min, max) {
if (!/^-?\d+$/.test(value || '') || !Number.isSafeInteger(Number(value)) || Number(value) < min || Number(value) > max)
throw new Error(`${label}: use um inteiro de ${min} a ${max}.`);
return Number(value);
}
function feChoice(value, choices) {
if (!choices.includes(value))
throw new Error('Opção não suportada: ' + value);
return value;
}
for (const value of Object.values(values)) if (typeof value !== "string" || value.length > 100000) throw new Error("Use até 100 mil caracteres por campo.");
return await generateFrontendLorem(values);
}
import html
import json
import math
import re
from urllib.parse import urlsplit, urlunsplit
def executar(values):
def text(value, limit=100000):
if not isinstance(value, str) or len(value.encode('utf-16-le')) // 2 > limit:
raise ValueError('Texto excede o limite permitido.')
if re.search(r'[\x00-\x08\x0b\x0c\x0e-\x1f\ufffe\uffff\ud800-\udfff]', value):
raise ValueError('Controle ou Unicode inválido.')
return value
def integer(value, minimum, maximum):
if not isinstance(value, str) or not re.fullmatch(r'-?[0-9]+', value) or not minimum <= int(value) <= maximum:
raise ValueError('Inteiro fora dos limites permitidos.')
return int(value)
def color(value):
if not re.fullmatch(r'#[0-9a-fA-F]{6}', value):
raise ValueError('Cor HEX inválida.')
return value.lower()
def choice(value, options):
if value not in options:
raise ValueError('Opção não suportada.')
return value
def esc(value):
return html.escape(text(value), quote=True).replace(''', ''')
def url(value):
text(value, 2048)
parsed = urlsplit(value)
if not re.match(r'https?://', value, re.I) or parsed.scheme not in ('http', 'https') or not parsed.hostname or parsed.username or parsed.password or re.search(r'[\s\\]', value):
raise ValueError('Use uma URL HTTP/HTTPS absoluta sem credenciais.')
if parsed.port is not None and not 0 <= parsed.port <= 65535:
raise ValueError('Porta inválida.')
return value
def svg(width, height, body):
return f'<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}" viewBox="0 0 {width} {height}">{body}</svg>'
def image(markup, label):
return {'text': markup, 'images': [{'label': label, 'svg': markup}]}
def num(value):
rounded = math.floor(value * 1000 + 0.5) / 1000
return str(int(rounded)) if rounded.is_integer() else str(rounded)
for value in values.values():
if not isinstance(value, str) or len(value.encode('utf-16-le')) // 2 > 100000:
raise ValueError('Use até 100 mil caracteres por campo.')
unit = choice(values['unit'], ['palavras', 'frases', 'parágrafos'])
count = integer(values['count'], 1, 500 if unit == 'palavras' else 100 if unit == 'frases' else 30)
words = 'lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur'.split()
if unit == 'palavras':
return {'text': ' '.join(words[i % len(words)] for i in range(count))}
sentences = []
for i in range(count * (4 if unit == 'parágrafos' else 1)):
sentence = ' '.join(words[(i * 12 + j) % len(words)] for j in range(12))
sentences.append(sentence[0].upper() + sentence[1:] + '.')
return {'text': ' '.join(sentences) if unit == 'frases' else '\n\n'.join(' '.join(sentences[i * 4:i * 4 + 4]) for i in range(count))}
<?php
function executar(array $values): array {
$text = static function ($value, $limit = 100000) {
if (!is_string($value) || !preg_match('//u', $value) || strlen(iconv('UTF-8', 'UTF-16LE', $value)) / 2 > $limit || preg_match('/[\x00-\x08\x0b\x0c\x0e-\x1f\x{fffe}\x{ffff}]/u', $value)) { throw new InvalidArgumentException('Texto excede o limite ou contém caracteres inválidos.'); }
return $value;
};
$integer = static function ($value, $min, $max) {
if (!is_string($value) || !preg_match('/^-?[0-9]+$/D', $value) || strlen(ltrim($value, '-0')) > 10 || (float)$value < $min || (float)$value > $max) { throw new InvalidArgumentException('Inteiro fora dos limites permitidos.'); }
return (int)$value;
};
$color = static function ($value) {
if (!preg_match('/^#[0-9a-fA-F]{6}$/D', $value)) { throw new InvalidArgumentException('Cor HEX inválida.'); }
return strtolower($value);
};
$choice = static function ($value, $options) {
if (!in_array($value, $options, true)) { throw new InvalidArgumentException('Opção não suportada.'); }
return $value;
};
$esc = static function ($value) use ($text) { return str_replace(''', ''', htmlspecialchars($text($value), ENT_QUOTES | ENT_HTML401, 'UTF-8')); };
$url = static function ($value) use ($text) {
$text($value, 2048); $p = parse_url($value);
if (!$p || !isset($p['host']) || !in_array(strtolower($p['scheme'] ?? ''), ['http', 'https'], true) || isset($p['user']) || isset($p['pass']) || preg_match('/[\s\\\\]/u', $value)) { throw new InvalidArgumentException('Use URL HTTP/HTTPS absoluta sem credenciais.'); }
return $value;
};
$svg = static function ($w, $h, $body) { return '<svg xmlns="http://www.w3.org/2000/svg" width="' . $w . '" height="' . $h . '" viewBox="0 0 ' . $w . ' ' . $h . '">' . $body . '</svg>'; };
$image = static function ($markup, $label) { return ['text' => $markup, 'images' => [['label' => $label, 'svg' => $markup]]]; };
$num = static function ($value) { return (string)(floor($value * 1000 + 0.5) / 1000); };
foreach ($values as $value) { if (!is_string($value) || !preg_match('//u', $value) || strlen(iconv('UTF-8', 'UTF-16LE', $value)) / 2 > 100000) { throw new InvalidArgumentException('Use até 100 mil caracteres por campo.'); } }
$unit = $choice($values['unit'], ['palavras', 'frases', 'parágrafos']); $count = $integer($values['count'], 1, $unit === 'palavras' ? 500 : ($unit === 'frases' ? 100 : 30));
$words = explode(' ', 'lorem ipsum dolor sit amet consectetur adipiscing elit sed do eiusmod tempor incididunt ut labore et dolore magna aliqua ut enim ad minim veniam quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur');
if ($unit === 'palavras') { $out = []; for ($i = 0; $i < $count; $i++) { $out[] = $words[$i % count($words)]; } return ['text' => implode(' ', $out)]; }
$sentences = []; for ($i = 0; $i < $count * ($unit === 'parágrafos' ? 4 : 1); $i++) { $parts = []; for ($j = 0; $j < 12; $j++) { $parts[] = $words[($i * 12 + $j) % count($words)]; } $sentences[] = ucfirst(implode(' ', $parts)) . '.'; }
if ($unit === 'frases') { return ['text' => implode(' ', $sentences)]; } $out = []; for ($i = 0; $i < $count; $i++) { $out[] = implode(' ', array_slice($sentences, $i * 4, 4)); } return ['text' => implode("\n\n", $out)];
}