feat(new tool): Random Line Picker (#393)

Adds a new Random Line Picker tool to pick one or more random lines from user-provided text. It's a handy utility for quickly selecting random items (winners, samples, shuffled lists) inside the app.

Co-authored-by: sharevb <sharevb@gmail.com>
This commit is contained in:
Brian Baidalandsharevb authored and GitHub committed 2026-05-11 00:28:20 +02:00
1 parent f0e35b09ee
commit 89975dc505
25 files changed
+489 -23

No files matched your search

+14 -1
View File
@@ -8604,7 +8604,20 @@ tools:
title-generated-command: الأمر المُنشأ title-generated-command: الأمر المُنشأ
tag-nbsp-h-nbsp: ح tag-nbsp-h-nbsp: ح
tag-nbsp-m-nbsp: م tag-nbsp-m-nbsp: م
tag-nbsp-s: '&nbsp;s' tag-nbsp-s: "&nbsp;s"
random-line-picker:
title: محدد سطور عشوائية
description: اختر سطورًا عشوائية من نص الإدخال
externalAccess: "null"
texts:
label-allow-repeated-lines: السماح بتكرار الأسطر
label-number-of-lines-to-pick: "عدد الأسطر للاختيار:"
label-prefix-lines-with-line-number: أضف أرقام الأسطر
placeholder-picked-lines: الأسطر المختارة
placeholder-put-your-text-here: ضع نصك هنا...
tag-copy: نسخ
tag-refresh: تحديث
text-picked-lines-copied-to-clipboard: تم نسخ الأسطر المختارة إلى الحافظة!
spanCopyable: spanCopyable:
copy: نسخ إلى الحافظة copy: نسخ إلى الحافظة
copied: تم النسخ! copied: تم النسخ!
+13
View File
@@ -8709,6 +8709,19 @@ tools:
tag-nbsp-h-nbsp: '&nbsp;h&nbsp;' tag-nbsp-h-nbsp: '&nbsp;h&nbsp;'
tag-nbsp-m-nbsp: m tag-nbsp-m-nbsp: m
tag-nbsp-s: s tag-nbsp-s: s
random-line-picker:
title: Tilfældig linjevælger
description: Vælg tilfældige linjer fra et tekstinput
externalAccess: "null"
texts:
label-allow-repeated-lines: Tillad gentagne linjer
label-number-of-lines-to-pick: "Antal linjer der skal vælges:"
label-prefix-lines-with-line-number: Tilføj linjenumre
placeholder-picked-lines: Valgte linjer
placeholder-put-your-text-here: Indtast din tekst her...
tag-copy: Kopiér
tag-refresh: Opdater
text-picked-lines-copied-to-clipboard: De valgte linjer er kopieret til udklipsholderen!
about: about:
alltools-title: Alle {toolsCount} værktøjer alltools-title: Alle {toolsCount} værktøjer
tools: tools:
+14 -1
View File
@@ -9096,7 +9096,20 @@ tools:
title-generated-command: Generierter Befehl title-generated-command: Generierter Befehl
tag-nbsp-h-nbsp: h tag-nbsp-h-nbsp: h
tag-nbsp-m-nbsp: m tag-nbsp-m-nbsp: m
tag-nbsp-s: '&nbsp;s' tag-nbsp-s: "&nbsp;s"
random-line-picker:
title: Zufällige Zeilenauswahl
description: Wähle zufällige Zeilen aus einem Texteingabefeld
externalAccess: "null"
texts:
label-allow-repeated-lines: Wiederholte Zeilen erlauben
label-number-of-lines-to-pick: "Anzahl der auszuwählenden Zeilen:"
label-prefix-lines-with-line-number: Zeilennummern hinzufügen
placeholder-picked-lines: Ausgewählte Zeilen
placeholder-put-your-text-here: Fügen Sie hier Ihren Text ein...
tag-copy: Kopieren
tag-refresh: Aktualisieren
text-picked-lines-copied-to-clipboard: Ausgewählte Zeilen in die Zwischenablage kopiert!
locale-selector: locale-selector:
select-a-language: Wählen Sie eine Sprache select-a-language: Wählen Sie eine Sprache
collapsibleToolMenu: collapsibleToolMenu:
+16 -3
View File
@@ -9131,9 +9131,22 @@ tools:
label-cancel: Ματαίωση label-cancel: Ματαίωση
label-hibernate: Διαχειμάζω label-hibernate: Διαχειμάζω
title-generated-command: Δημιουργήθηκε εντολή title-generated-command: Δημιουργήθηκε εντολή
tag-nbsp-h-nbsp: '&nbsp;h&nbsp;' tag-nbsp-h-nbsp: "&nbsp;h&nbsp;"
tag-nbsp-m-nbsp: '&nbsp;μ&nbsp;' tag-nbsp-m-nbsp: "&nbsp;μ&nbsp;"
tag-nbsp-s: '&nbsp;s' tag-nbsp-s: "&nbsp;s"
random-line-picker:
title: Επιλογέας Τυχαίων Γραμμών
description: Επιλέξτε τυχαίες γραμμές από ένα κείμενο
externalAccess: "null"
texts:
label-allow-repeated-lines: Επιτρέπεται επανάληψη γραμμών
label-number-of-lines-to-pick: "Αριθμός γραμμών για επιλογή:"
label-prefix-lines-with-line-number: Προσθήκη αριθμών γραμμής
placeholder-picked-lines: Επιλεγμένες γραμμές
placeholder-put-your-text-here: Βάλτε το κείμενό σας εδώ...
tag-copy: Αντιγραφή
tag-refresh: Φρεσκάρισμα
text-picked-lines-copied-to-clipboard: Οι επιλεγμένες γραμμές αντιγράφηκαν στο πρόχειρο!
collapsibleToolMenu: collapsibleToolMenu:
text: text:
expanding: Επέκταση... expanding: Επέκταση...
+16 -3
View File
@@ -8707,9 +8707,22 @@ tools:
label-cancel: Cancel label-cancel: Cancel
label-hibernate: Hibernate label-hibernate: Hibernate
title-generated-command: Generated command title-generated-command: Generated command
tag-nbsp-h-nbsp: '&nbsp;h&nbsp;' tag-nbsp-h-nbsp: "&nbsp;h&nbsp;"
tag-nbsp-m-nbsp: '&nbsp;m&nbsp;' tag-nbsp-m-nbsp: "&nbsp;m&nbsp;"
tag-nbsp-s: '&nbsp;s' tag-nbsp-s: "&nbsp;s"
random-line-picker:
title: Random Line Picker
description: Pick random lines from a text input
externalAccess: "null"
texts:
label-allow-repeated-lines: Allow repeated lines
label-number-of-lines-to-pick: "Number of lines to pick:"
label-prefix-lines-with-line-number: Add line numbers
placeholder-picked-lines: Picked lines
placeholder-put-your-text-here: Put your text here...
tag-copy: Copy
tag-refresh: Refresh
text-picked-lines-copied-to-clipboard: Picked lines copied to clipboard!
collapsibleToolMenu: collapsibleToolMenu:
text: text:
expanding: Expanding... expanding: Expanding...
+16 -3
View File
@@ -9015,9 +9015,22 @@ tools:
label-cancel: Cancelar label-cancel: Cancelar
label-hibernate: Hibernar label-hibernate: Hibernar
title-generated-command: Comando generado title-generated-command: Comando generado
tag-nbsp-h-nbsp: '&nbsp;h&nbsp;' tag-nbsp-h-nbsp: "&nbsp;h&nbsp;"
tag-nbsp-m-nbsp: '&nbsp;m&nbsp;' tag-nbsp-m-nbsp: "&nbsp;m&nbsp;"
tag-nbsp-s: '&nbsp;s' tag-nbsp-s: "&nbsp;s"
random-line-picker:
title: Selector de líneas aleatorias
description: Selecciona líneas aleatorias de un texto
externalAccess: "null"
texts:
label-allow-repeated-lines: Permitir líneas repetidas
label-number-of-lines-to-pick: "Número de líneas a seleccionar:"
label-prefix-lines-with-line-number: Agregar números de línea
placeholder-picked-lines: Líneas seleccionadas
placeholder-put-your-text-here: Pon tu texto aquí...
tag-copy: Copiar
tag-refresh: Actualizar
text-picked-lines-copied-to-clipboard: ¡Líneas seleccionadas copiadas al portapapeles!
spanCopyable: spanCopyable:
copy: Copiar al portapapeles copy: Copiar al portapapeles
copied: Copiado! copied: Copiado!
+14 -1
View File
@@ -9098,7 +9098,20 @@ tools:
title-generated-command: Commande générée title-generated-command: Commande générée
tag-nbsp-h-nbsp: '&nbsp;h&nbsp;' tag-nbsp-h-nbsp: '&nbsp;h&nbsp;'
tag-nbsp-m-nbsp: m tag-nbsp-m-nbsp: m
tag-nbsp-s: '&nbsp;s' tag-nbsp-s: "&nbsp;s"
random-line-picker:
title: Sélecteur de lignes aléatoires
description: Sélectionnez des lignes aléatoires depuis un texte
externalAccess: "null"
texts:
label-allow-repeated-lines: Autoriser les lignes répétées
label-number-of-lines-to-pick: "Nombre de lignes à sélectionner :"
label-prefix-lines-with-line-number: Ajouter les numéros de ligne
placeholder-picked-lines: Lignes sélectionnées
placeholder-put-your-text-here: Mettez votre texte ici...
tag-copy: Copier
tag-refresh: Actualiser
text-picked-lines-copied-to-clipboard: Lignes sélectionnées copiées dans le presse-papiers !
favoriteButton: favoriteButton:
add: Ajouter aux favoris add: Ajouter aux favoris
remove: Retirer des favoris remove: Retirer des favoris
+14 -1
View File
@@ -8938,7 +8938,20 @@ tools:
title-generated-command: Ordú ginte title-generated-command: Ordú ginte
tag-nbsp-h-nbsp: '&nbsp;h&nbsp;' tag-nbsp-h-nbsp: '&nbsp;h&nbsp;'
tag-nbsp-m-nbsp: m tag-nbsp-m-nbsp: m
tag-nbsp-s: '&nbsp;s' tag-nbsp-s: "&nbsp;s"
random-line-picker:
title: Roghnóir Líní Rándamach
description: Roghnaigh línte randamacha ó ionchur téacs
externalAccess: "null"
texts:
label-allow-repeated-lines: Ceadaigh línte athráite
label-number-of-lines-to-pick: "Líon na línte le roghnú:"
label-prefix-lines-with-line-number: Cuir uimhreacha línte leis
placeholder-picked-lines: Línte roghnaithe
placeholder-put-your-text-here: Cuir do théacs anseo...
tag-copy: Cóipeáil
tag-refresh: Nuashonrú
text-picked-lines-copied-to-clipboard: Cóipeáladh na línte roghnaithe chuig an gclár gearrthaisce!
locale-selector: locale-selector:
select-a-language: Roghnaigh teanga select-a-language: Roghnaigh teanga
collapsibleToolMenu: collapsibleToolMenu:
+16 -3
View File
@@ -8918,9 +8918,22 @@ tools:
label-cancel: Cancellare label-cancel: Cancellare
label-hibernate: Ibernazione label-hibernate: Ibernazione
title-generated-command: Comando generato title-generated-command: Comando generato
tag-nbsp-h-nbsp: '&nbsp;h&nbsp;' tag-nbsp-h-nbsp: "&nbsp;h&nbsp;"
tag-nbsp-m-nbsp: '&nbsp;m&nbsp;' tag-nbsp-m-nbsp: "&nbsp;m&nbsp;"
tag-nbsp-s: '&nbsp;s' tag-nbsp-s: "&nbsp;s"
random-line-picker:
title: Selettore di righe casuali
description: Seleziona righe casuali da un input di testo
externalAccess: "null"
texts:
label-allow-repeated-lines: Permetti righe ripetute
label-number-of-lines-to-pick: "Numero di righe da selezionare:"
label-prefix-lines-with-line-number: Aggiungi numeri di riga
placeholder-picked-lines: Righe selezionate
placeholder-put-your-text-here: Inserisci il tuo testo qui...
tag-copy: Copia
tag-refresh: Aggiorna
text-picked-lines-copied-to-clipboard: Righe selezionate copiate negli appunti!
about: about:
alltools-title: Tutti gli strumenti {toolsCount} alltools-title: Tutti gli strumenti {toolsCount}
tools: tools:
+16 -3
View File
@@ -8225,9 +8225,22 @@ tools:
label-cancel: 취소 label-cancel: 취소
label-hibernate: 절전 모드 label-hibernate: 절전 모드
title-generated-command: 생성된 명령 title-generated-command: 생성된 명령
tag-nbsp-h-nbsp: '&nbsp;h&nbsp;' tag-nbsp-h-nbsp: "&nbsp;h&nbsp;"
tag-nbsp-m-nbsp: '&nbsp;m&nbsp;' tag-nbsp-m-nbsp: "&nbsp;m&nbsp;"
tag-nbsp-s: '&nbsp;s' tag-nbsp-s: "&nbsp;s"
random-line-picker:
title: 무작위 줄 선택기
description: 텍스트 입력에서 무작위 줄을 선택합니다
externalAccess: "null"
texts:
label-allow-repeated-lines: 중복된 줄 허용
label-number-of-lines-to-pick: "선택할 줄 수:"
label-prefix-lines-with-line-number: 줄 번호 추가
placeholder-picked-lines: 선택된 줄
placeholder-put-your-text-here: 텍스트를 여기에 입력하세요...
tag-copy: 복사
tag-refresh: 새로 고침
text-picked-lines-copied-to-clipboard: 선택된 줄이 클립보드에 복사되었습니다!
about: about:
alltools-title: 모든 {toolsCount}개 도구 alltools-title: 모든 {toolsCount}개 도구
tools: tools:
+14 -1
View File
@@ -8840,7 +8840,20 @@ tools:
title-generated-command: Gegenereerde opdracht title-generated-command: Gegenereerde opdracht
tag-nbsp-h-nbsp: h tag-nbsp-h-nbsp: h
tag-nbsp-m-nbsp: m tag-nbsp-m-nbsp: m
tag-nbsp-s: '&nbsp;s' tag-nbsp-s: "&nbsp;s"
random-line-picker:
title: Willekeurige regelkiezer
description: Kies willekeurige regels uit een tekstinvoer
externalAccess: "null"
texts:
label-allow-repeated-lines: Toestaan dat regels herhaald worden
label-number-of-lines-to-pick: "Aantal regels om te kiezen:"
label-prefix-lines-with-line-number: Regelnummers toevoegen
placeholder-picked-lines: Geselecteerde regels
placeholder-put-your-text-here: Plaats je tekst hier...
tag-copy: Kopiëren
tag-refresh: Verversen
text-picked-lines-copied-to-clipboard: Geselecteerde regels gekopieerd naar klembord!
about: about:
alltools-title: Alle {toolsCount}-hulpmiddelen alltools-title: Alle {toolsCount}-hulpmiddelen
tools: tools:
+13
View File
@@ -8758,6 +8758,19 @@ tools:
tag-nbsp-h-nbsp: '&nbsp;h&nbsp;' tag-nbsp-h-nbsp: '&nbsp;h&nbsp;'
tag-nbsp-m-nbsp: m tag-nbsp-m-nbsp: m
tag-nbsp-s: s tag-nbsp-s: s
random-line-picker:
title: Tilfeldig linjevelger
description: Velg tilfeldige linjer fra en tekstinndata
externalAccess: "null"
texts:
label-allow-repeated-lines: Tillat repeterte linjer
label-number-of-lines-to-pick: "Antall linjer å velge:"
label-prefix-lines-with-line-number: Legg til linjenummer
placeholder-picked-lines: Valgte linjer
placeholder-put-your-text-here: Legg inn teksten din her...
tag-copy: Kopier
tag-refresh: Oppdater
text-picked-lines-copied-to-clipboard: Valgte linjer kopiert til utklippstavlen!
spanCopyable: spanCopyable:
copy: Kopier til utklippstavlen copy: Kopier til utklippstavlen
copied: Kopiert! copied: Kopiert!
+14 -1
View File
@@ -8825,7 +8825,20 @@ tools:
title-generated-command: Wygenerowane polecenie title-generated-command: Wygenerowane polecenie
tag-nbsp-h-nbsp: h&nbsp; tag-nbsp-h-nbsp: h&nbsp;
tag-nbsp-m-nbsp: m&nbsp; tag-nbsp-m-nbsp: m&nbsp;
tag-nbsp-s: '&nbsp;s' tag-nbsp-s: "&nbsp;s"
random-line-picker:
title: Losowy wybór linii
description: Wybierz losowe linie z pola tekstowego
externalAccess: "null"
texts:
label-allow-repeated-lines: Zezwól na powtarzające się linie
label-number-of-lines-to-pick: "Liczba linii do wybrania:"
label-prefix-lines-with-line-number: Dodaj numery linii
placeholder-picked-lines: Wybrane linie
placeholder-put-your-text-here: Wklej swój tekst tutaj...
tag-copy: Kopiuj
tag-refresh: Odśwież
text-picked-lines-copied-to-clipboard: Wybrane linie zostały skopiowane do schowka!
favoriteButton: favoriteButton:
remove: Usuń z ulubionych remove: Usuń z ulubionych
add: Dodaj do ulubionych add: Dodaj do ulubionych
+14 -1
View File
@@ -8892,7 +8892,20 @@ tools:
title-generated-command: Comando gerado title-generated-command: Comando gerado
tag-nbsp-h-nbsp: '&nbsp;h&nbsp;' tag-nbsp-h-nbsp: '&nbsp;h&nbsp;'
tag-nbsp-m-nbsp: m tag-nbsp-m-nbsp: m
tag-nbsp-s: '&nbsp;s' tag-nbsp-s: "&nbsp;s"
random-line-picker:
title: Seletor de linhas aleatórias
description: Selecione linhas aleatórias de um texto
externalAccess: "null"
texts:
label-allow-repeated-lines: Permitir linhas repetidas
label-number-of-lines-to-pick: "Número de linhas para escolher:"
label-prefix-lines-with-line-number: Adicionar números de linha
placeholder-picked-lines: Linhas selecionadas
placeholder-put-your-text-here: Coloque seu texto aqui...
tag-copy: Copiar
tag-refresh: Atualizar
text-picked-lines-copied-to-clipboard: Linhas selecionadas copiadas para a área de transferência!
spanCopyable: spanCopyable:
copy: Copiar para a área de transferência copy: Copiar para a área de transferência
copied: Copiado! copied: Copiado!
+13
View File
@@ -8881,6 +8881,19 @@ tools:
tag-nbsp-h-nbsp: '&nbsp;h&nbsp;' tag-nbsp-h-nbsp: '&nbsp;h&nbsp;'
tag-nbsp-m-nbsp: м tag-nbsp-m-nbsp: м
tag-nbsp-s: с tag-nbsp-s: с
random-line-picker:
title: Выбор случайных строк
description: Выбирайте случайные строки из текстового ввода
externalAccess: "null"
texts:
label-allow-repeated-lines: Разрешить повторяющиеся строки
label-number-of-lines-to-pick: "Количество строк для выбора:"
label-prefix-lines-with-line-number: Добавить номера строк
placeholder-picked-lines: Выбранные строки
placeholder-put-your-text-here: Поместите ваш текст здесь...
tag-copy: Копировать
tag-refresh: Обновить
text-picked-lines-copied-to-clipboard: Выбранные строки скопированы в буфер обмена!
spanCopyable: spanCopyable:
copy: Копировать в буфер обмена copy: Копировать в буфер обмена
copied: Скопировано! copied: Скопировано!
+13
View File
@@ -8823,6 +8823,19 @@ tools:
tag-nbsp-h-nbsp: '&nbsp;h&nbsp;' tag-nbsp-h-nbsp: '&nbsp;h&nbsp;'
tag-nbsp-m-nbsp: '&nbsp;m&nbsp;' tag-nbsp-m-nbsp: '&nbsp;m&nbsp;'
tag-nbsp-s: s tag-nbsp-s: s
random-line-picker:
title: Rastgele Satır Seçici
description: Metin girişi içinden rastgele satırlar seçin
externalAccess: "null"
texts:
label-allow-repeated-lines: Tekrarlanan satırlara izin ver
label-number-of-lines-to-pick: "Seçilecek satır sayısı:"
label-prefix-lines-with-line-number: Satır numaralarını ekle
placeholder-picked-lines: Seçilen satırlar
placeholder-put-your-text-here: Metninizi buraya koyun...
tag-copy: Kopyala
tag-refresh: Yenile
text-picked-lines-copied-to-clipboard: Seçilen satırlar panoya kopyalandı!
about: about:
alltools-title: Tüm {toolsCount} Araç alltools-title: Tüm {toolsCount} Araç
tools: tools:
+13
View File
@@ -8812,6 +8812,19 @@ tools:
tag-nbsp-h-nbsp: год tag-nbsp-h-nbsp: год
tag-nbsp-m-nbsp: м tag-nbsp-m-nbsp: м
tag-nbsp-s: с tag-nbsp-s: с
random-line-picker:
title: Випадковий вибір рядків
description: Виберіть випадкові рядки з текстового вводу
externalAccess: "null"
texts:
label-allow-repeated-lines: Дозволити повторювані рядки
label-number-of-lines-to-pick: "Кількість рядків для вибору:"
label-prefix-lines-with-line-number: Додати номери рядків
placeholder-picked-lines: Вибрані рядки
placeholder-put-your-text-here: Помістіть свій текст тут...
tag-copy: Копіювати
tag-refresh: Оновити
text-picked-lines-copied-to-clipboard: Вибрані рядки скопійовано в буфер обміну!
spanCopyable: spanCopyable:
copy: Копіювати в буфер обміну copy: Копіювати в буфер обміну
copied: Скопійовано! copied: Скопійовано!
+14 -1
View File
@@ -8771,7 +8771,20 @@ tools:
title-generated-command: Lệnh được tạo title-generated-command: Lệnh được tạo
tag-nbsp-h-nbsp: h tag-nbsp-h-nbsp: h
tag-nbsp-m-nbsp: m tag-nbsp-m-nbsp: m
tag-nbsp-s: '&nbsp;s' tag-nbsp-s: "&nbsp;s"
random-line-picker:
title: Trình chọn dòng ngẫu nhiên
description: Chọn các dòng ngẫu nhiên từ ô nhập văn bản
externalAccess: "null"
texts:
label-allow-repeated-lines: Cho phép dòng lặp lại
label-number-of-lines-to-pick: "Số dòng cần chọn:"
label-prefix-lines-with-line-number: Thêm số dòng
placeholder-picked-lines: Dòng đã chọn
placeholder-put-your-text-here: Nhập văn bản tại đây...
tag-copy: Sao chép
tag-refresh: Làm mới
text-picked-lines-copied-to-clipboard: Các dòng đã chọn đã được sao chép vào bộ nhớ tạm!
spanCopyable: spanCopyable:
copy: Sao chép vào bảng tạm copy: Sao chép vào bảng tạm
copied: Đã sao chép! copied: Đã sao chép!
+13
View File
@@ -8277,6 +8277,19 @@ tools:
tag-nbsp-h-nbsp: '&nbsp;h&nbsp;' tag-nbsp-h-nbsp: '&nbsp;h&nbsp;'
tag-nbsp-m-nbsp: 和 tag-nbsp-m-nbsp: 和
tag-nbsp-s: 和 tag-nbsp-s: 和
random-line-picker:
title: 随机行选择器
description: 从文本输入中随机选择行
externalAccess: "null"
texts:
label-allow-repeated-lines: 允许重复行
label-number-of-lines-to-pick: "要选择的行数:"
label-prefix-lines-with-line-number: 添加行号
placeholder-picked-lines: 已选择的行
placeholder-put-your-text-here: 在此处粘贴你的文本...
tag-copy: 复制
tag-refresh: 刷新
text-picked-lines-copied-to-clipboard: 已选择的行已复制到剪贴板!
collapsibleToolMenu: collapsibleToolMenu:
text: text:
expanding: 正在扩展…… expanding: 正在扩展……
+14
View File
@@ -0,0 +1,14 @@
import { ArrowsShuffle } from '@vicons/tabler';
import { defineTool } from '../tool';
import { translate as t } from '@/plugins/i18n.plugin';
export const tool = defineTool({
name: t('tools.random-line-picker.title'),
path: '/random-line-picker',
description: t('tools.random-line-picker.description'),
keywords: ['text', 'random', 'line', 'picker', 'shuffle'],
component: () => import('./random-line-picker.vue'),
icon: ArrowsShuffle,
createdAt: new Date('2026-05-08'),
category: 'Text',
});
@@ -0,0 +1,27 @@
import { expect, test } from '@playwright/test';
test.describe('Tool - Random Line Picker', () => {
test.beforeEach(async ({ page }) => {
await page.goto('/random-line-picker');
await expect(page.getByTestId('input')).toBeVisible();
await expect(page.getByTestId('count')).toBeVisible();
});
test('Has correct title', async ({ page }) => {
await expect(page).toHaveTitle('Random Line Picker - IT Tools');
});
test('Picks random lines without repeats', async ({ page }) => {
await page.getByTestId('input').fill('one\ntwo\nthree\nfour');
const countInput = page.getByTestId('count').locator('input');
await countInput.fill('2');
await countInput.press('Enter');
const picked = (await page.getByTestId('output').inputValue()).split('\n');
expect(picked.length).toBe(2);
expect(new Set(picked).size).toBe(2);
});
});
@@ -0,0 +1,73 @@
import { describe, expect, it } from 'vitest';
import { getLines, pickLines } from './random-line-picker.models';
import type { Config } from './random-line-picker.types';
describe('random-line-picker', () => {
describe('getLines', () => {
it('should split input into lines', () => {
const config: Config = { input: 'a\nb\nc', count: 1, repeat: false, prefix: false };
expect(getLines(config)).toEqual(['a', 'b', 'c']);
});
it('should return an empty array for empty input', () => {
const config: Config = { input: '', count: 1, repeat: false, prefix: false };
expect(getLines(config)).toEqual([]);
});
});
describe('pickLines', () => {
it('should return the correct number of lines', () => {
const config: Config = { input: 'a\nb\nc\nd\ne', count: 3, repeat: false, prefix: false };
const result = pickLines(config).split('\n');
expect(result).toHaveLength(3);
});
it('should not exceed the number of available lines when repeat is false', () => {
const config: Config = { input: 'a\nb\nc', count: 10, repeat: false, prefix: false };
const result = pickLines(config).split('\n');
expect(result).toHaveLength(3);
});
it('should allow picking more lines than available when repeat is true', () => {
const config: Config = { input: 'a\nb', count: 5, repeat: true, prefix: false };
const result = pickLines(config).split('\n');
expect(result).toHaveLength(5);
});
it('should only return lines from the input', () => {
const config: Config = { input: 'foo\nbar\nbaz', count: 3, repeat: false, prefix: false };
const result = pickLines(config).split('\n');
expect(result.every(line => ['foo', 'bar', 'baz'].includes(line))).toBe(true);
});
it('should not repeat lines when repeat is false', () => {
const config: Config = { input: 'a\nb\nc', count: 3, repeat: false, prefix: false };
const result = pickLines(config).split('\n');
expect(new Set(result).size).toBe(result.length);
});
it('should add numeric prefix when prefix is true', () => {
const config: Config = { input: 'a\nb\nc', count: 3, repeat: false, prefix: true };
const result = pickLines(config).split('\n');
expect(result[0]).toMatch(/^1\. /);
expect(result[1]).toMatch(/^2\. /);
expect(result[2]).toMatch(/^3\. /);
});
it('should not add prefix when prefix is false', () => {
const config: Config = { input: 'a\nb\nc', count: 3, repeat: false, prefix: false };
const result = pickLines(config).split('\n');
expect(result.every(line => !/^\d+\. /.test(line))).toBe(true);
});
it('should return an empty string for empty input', () => {
const config: Config = { input: '', count: 3, repeat: false, prefix: false };
expect(pickLines(config)).toBe('');
});
it('should return a single line when count is 1', () => {
const config: Config = { input: 'only', count: 1, repeat: false, prefix: false };
expect(pickLines(config)).toBe('only');
});
});
});
@@ -0,0 +1,24 @@
import type { Config } from './random-line-picker.types';
function getRandomInt(min: number, max: number) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
export function getLines(config: Config) {
return config.input ? config.input.split(/\n/) : [];
}
export function pickLines(config: Config) {
const lines = getLines(config);
const length = config.repeat ? config.count : Math.min(config.count, lines.length);
return Array.from({ length }, (_, i) => {
const index = getRandomInt(0, lines.length - 1);
const line = config.repeat ? lines[index] : lines.splice(index, 1)[0];
return line && config.prefix ? `${i + 1}. ${line}` : line;
}).join('\n');
}
@@ -0,0 +1,6 @@
export interface Config {
input: string
count: number
repeat: boolean
prefix: boolean
}
@@ -0,0 +1,75 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n';
import { computedRefreshable } from '@/composable/computedRefreshable';
import { useCopy } from '@/composable/copy';
import { useStorage } from '@vueuse/core';
import { getLines, pickLines } from './random-line-picker.models';
const { t } = useI18n();
const config = useStorage('random-line-picker:config', {
input: '',
count: 1,
repeat: false,
prefix: false,
});
const [pickedLines, refreshPickedLines] = computedRefreshable(() => pickLines(config.value));
const { copy } = useCopy({ source: pickedLines, text: t('tools.random-line-picker.texts.text-picked-lines-copied-to-clipboard') });
const maxCount = ref<number | undefined>(undefined);
watch([() => config.value.repeat, () => config.value.input], () => {
maxCount.value = config.value.repeat ? undefined : getLines(config.value).length;
if (!config.value.repeat && maxCount.value && config.value.count > maxCount.value) {
config.value.count = maxCount.value;
}
}, { immediate: true });
</script>
<template>
<div>
<c-card>
<c-input-text v-model:value="config.input" test-id="input" multiline :placeholder="t('tools.random-line-picker.texts.placeholder-put-your-text-here')" rows="10" />
<n-space mt-5>
<n-form-item :label="t('tools.random-line-picker.texts.label-number-of-lines-to-pick')" label-placement="left">
<n-input-number-i18n v-model:value="config.count" data-test-id="count" min="1" :max="maxCount" size="small" />
</n-form-item>
<n-form-item :label="t('tools.random-line-picker.texts.label-allow-repeated-lines')" label-placement="left">
<n-switch v-model:value="config.repeat" />
</n-form-item>
<n-form-item :label="t('tools.random-line-picker.texts.label-prefix-lines-with-line-number')" label-placement="left">
<n-switch v-model:value="config.prefix" />
</n-form-item>
</n-space>
</c-card>
<c-card mt-5>
<c-input-text
v-model:value="pickedLines"
test-id="output"
multiline
:placeholder="t('tools.random-line-picker.texts.placeholder-picked-lines')"
readonly
rows="3"
autosize
class="passphrase-display"
word-wrap
/>
<div mt-5 flex justify-center gap-3>
<c-button @click="copy()">
{{ t('tools.random-line-picker.texts.tag-copy') }}
</c-button>
<c-button @click="refreshPickedLines">
{{ t('tools.random-line-picker.texts.tag-refresh') }}
</c-button>
</div>
</c-card>
</div>
</template>