Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Small tools Halit Sever uses himself, at tools.halit.org. They run in your brows
- [**Slug generator**](https://tools.halit.org/slug-generator/) - turns titles into URL slugs: lowercase, a hyphen, underscore or dot between words, accented and Turkish letters (ç, ğ, ı, İ, ö, ş, ü) made plain or kept, German umlauts as ae, oe and ue on request, optional English stop word removal and a maximum length that keeps whole words. One slug per line for a list of titles. English only.
- [**Remove special characters**](https://tools.halit.org/remove-special-characters/) - removes punctuation, symbols, emoji and invisible characters from text and turns accented letters into plain ones (é to e, ß to ss, Turkish ı and İ to i and I), with a keep list for characters such as @ or the hyphen, an option to put a space where a character was, collapsed spaces, lowercase and an a to z only mode. Turkish version: [Türkçe karakter temizleme](https://tools.halit.org/tr/turkce-karakter-temizleme/), which also repairs garbled Turkish such as ü and ı (UTF-8 read as Windows-1252 or 1254).
- [**Kelime ve karakter sayacı**](https://tools.halit.org/tr/karakter-sayaci/) - word and character counter: words, characters with and without spaces, letters, sentences and paragraphs as you type, a reading time at a speed you set, a character limit and a count for the selected part. Words follow Unicode word boundaries (UAX #29), so apostrophes such as İstanbul'da keep a word whole; characters are grapheme clusters, so an emoji counts once. Turkish only.
- [**Word frequency counter**](https://tools.halit.org/word-frequency-counter/) - ranks every word in a text by how often it appears, with its count and its share of all words (keyword density). Counts two- and three-word phrases inside one sentence, leaves out English stop words on request, has a Turkish casing option for I and İ, and copies the table for a spreadsheet or downloads it as CSV. English only.
- **Stays on your device** - every tool is plain JavaScript in the page. A Content Security Policy blocks connections to any server except the Cloudflare Web Analytics page-view beacon, so pasted text cannot be sent anywhere.
- **English and Turkish** - each page has a Turkish twin written in Turkish, paired with `hreflang`.

Expand Down
Binary file added public/og/word-frequency-counter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 66 additions & 0 deletions public/site.css
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,72 @@ code {
display: none;
}

/* word frequency counter: the table scrolls inside the output pane */
.pane-title {
font-size: 14px;
font-weight: 600;
}

/* a fixed height, or a long list would stretch both panes */
.freq-wrap {
flex: none;
height: 440px;
min-height: 0;
overflow: auto;
background: color-mix(in srgb, var(--muted) 45%, var(--card));
}

.freq-wrap:focus-visible {
outline: 2px solid var(--ring);
outline-offset: -2px;
}

.freq-empty {
padding: 16px 20px;
color: var(--muted-foreground);
font-size: 15px;
}

.freq-empty[hidden],
.freq[hidden] {
display: none;
}

.freq th {
position: sticky;
top: 0;
background: var(--card);
}

.freq th:first-child,
.freq td:first-child {
width: 4.5em;
padding-left: 20px;
color: var(--muted-foreground);
}

.freq .word {
overflow-wrap: anywhere;
}

.freq td:last-child,
.freq th:last-child {
padding-right: 20px;
}

.stopwords {
max-width: 72ch;
margin-top: 16px;
color: var(--muted-foreground);
font: 400 13px/1.7 var(--font-mono);
}

@media (max-width: 833px) {
.freq-wrap {
height: 360px;
}
}

/* word and character counter: the text gets the wider column */
.counter {
grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
Expand Down
55 changes: 54 additions & 1 deletion scripts/browser-check.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -921,12 +921,64 @@ for (const width of [1280, 390]) {
await context.close();
}

const FREQUENCY = "/word-frequency-counter/";
for (const width of [1280, 390]) {
const label = `en frequency ${width}`;
const { context, page, errors } = await open(width, FREQUENCY, label);
await page.evaluate(() => localStorage.clear());
await page.reload({ waitUntil: "networkidle" });
const rows = () => page.$$eval("#rows tr", (trs) => trs.map((tr) => [...tr.children].map((td) => td.textContent)));
expect(await page.isVisible("#empty"), `${label}: empty note hidden`);
await page.fill("#src", "The cat and the hat. The cat sat. Don't stop, don’t!");
let r = await rows();
expect(JSON.stringify(r.slice(0, 3)) === JSON.stringify([["1", "the", "3", "27.27"], ["2", "cat", "2", "18.18"], ["3", "don't", "2", "18.18"]]), `${label}: words ${JSON.stringify(r.slice(0, 3))}`);
expect((await page.textContent("#counts")) === "11 words · 7 unique", `${label}: counts ${await page.textContent("#counts")}`);
await page.check('input[data-option="stopwords"]');
r = await rows();
expect(r.map((x) => x[1]).join(",") === "cat,hat,sat,stop", `${label}: stop words ${JSON.stringify(r)}`);
await page.locator('input[name="size"][value="2"]').check({ force: true });
await page.fill("#src", "Word frequency counter. A word frequency counter counts words.");
r = await rows();
expect(r[0][1] === "frequency counter" && r[0][2] === "2" && r[1][1] === "word frequency" && (await page.textContent("#col-word")) === "Phrase", `${label}: phrases ${JSON.stringify(r)}`);
await page.reload({ waitUntil: "networkidle" });
expect((await page.isChecked('input[name="size"][value="2"]')) && (await page.isChecked('input[data-option="stopwords"]')), `${label}: options not remembered`);
await page.click("#reset");
expect((await page.isChecked('input[name="size"][value="1"]')) && !(await page.isChecked('input[data-option="stopwords"]')), `${label}: reset`);
await page.fill("#src", "IŞIK ışık İzmir izmir 2026 a");
expect((await rows()).map((x) => x[1]).join(",") === "izmir,2026,a,işik,ışık", `${label}: english casing ${JSON.stringify(await rows())}`);
await page.check('input[data-option="turkish"]');
await page.uncheck('input[data-option="numbers"]');
await page.fill("#min", "2");
expect((await rows()).map((x) => x[1]).join(",") === "ışık,izmir", `${label}: turkish ${JSON.stringify(await rows())}`);
await page.click("#reset");
await page.fill("#src", "Alpha beta beta");
await page.click("#copy");
await page.waitForTimeout(150);
const copied = await page.evaluate(() => navigator.clipboard.readText());
expect(copied === "Rank\tWord\tCount\tPercent\n1\tbeta\t2\t66.67\n2\talpha\t1\t33.33", `${label}: copy ${JSON.stringify(copied)}`);
const [download] = await Promise.all([page.waitForEvent("download"), page.click("#csv")]);
const file = await download.path();
const { readFile: rf } = await import("node:fs/promises");
const csv = (await rf(file, "utf8")).replace(/^\uFEFF/, "");
expect(download.suggestedFilename() === "word-frequency.csv" && csv === "Rank,Word,Count,Percent\r\n1,beta,2,66.67\r\n2,alpha,1,33.33", `${label}: csv ${JSON.stringify(csv)}`);
const words = Array.from({ length: 700 }, (_, i) => `w${i}`).join(" ");
await page.fill("#src", words);
expect((await page.locator("#rows tr").count()) === 500 && (await page.textContent("#counts")).includes("showing the top 500"), `${label}: row cap`);
await page.fill("#src", "");
expect(await page.isVisible("#empty"), `${label}: empty after clear`);
await page.fill("#src", "A word frequency counter shows how often each word appears in a text. Paste a text, and the counter ranks every word, so the words you repeat most stand out. The counter also counts phrases.");
await page.screenshot({ path: `${shots}/en-frequency-${width}.png`, fullPage: true });
await langMenu(page, label, "en", { en: FREQUENCY, tr: "/tr/" }, null);
finish(errors, label);
await context.close();
}

for (const path of OTHER) {
for (const width of [1440, 390]) {
const label = `${path} ${width}`;
const { context, page, errors } = await open(width, path, label);
await page.screenshot({ path: `${shots}/page${path.replace(/\//g, "_")}-${width}.png`, fullPage: true });
if (path !== "/missing-page") expect((await page.locator(".tool-card").count()) === 16, `${label}: index does not list every tool`);
if (path !== "/missing-page") expect((await page.locator(".tool-card").count()) === 17, `${label}: index does not list every tool`);
if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/tr/kdv-hesaplama/"]').count()) === 1, `${label}: index does not link KDV`);
if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/tr/yas-hesaplama/"]').count()) === 1, `${label}: index does not link yaş hesaplama`);
if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/days-between-dates/"]').count()) === 1, `${label}: index does not link days between dates`);
Expand All @@ -939,6 +991,7 @@ for (const path of OTHER) {
if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/slug-generator/"]').count()) === 1, `${label}: index does not link the slug generator`);
if (path !== "/missing-page") expect((await page.locator(`.tool-card a[href="${SPECIAL[path === "/tr/" ? "tr" : "en"]}"]`).count()) === 1, `${label}: index does not link the special character remover`);
if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/tr/karakter-sayaci/"]').count()) === 1, `${label}: index does not link the counter`);
if (path !== "/missing-page") expect((await page.locator('.tool-card a[href="/word-frequency-counter/"]').count()) === 1, `${label}: index does not link the word frequency counter`);
const lang = path === "/tr/" ? "tr" : "en";
await langMenu(page, label, lang, HOME, `${shots}/menu${path.replace(/\//g, "_")}-${width}.png`);
finish(errors, label);
Expand Down
33 changes: 31 additions & 2 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,35 @@ ${row("reading", u.reading)}
</section>`;
}

/** Phrase length and minimum length above the panes, the ranked table where the output text would be. */
function frequencyTool(page) {
const u = page.ui;
return `<section class="tool" aria-label="${esc(u.toolLabel)}">
<div class="rep-bar">
<fieldset class="field"><legend>${esc(u.size)}</legend><div class="seg seg-radio">${u.sizes.map(([v, l], i) => radio("size", v, l, i === 0)).join("")}</div></fieldset>
<div class="field"><label for="min">${esc(u.min)}</label><input id="min" class="input" type="number" inputmode="numeric" min="1" max="100" step="1" placeholder="${esc(u.minPh)}" aria-describedby="min-hint"><small id="min-hint">${esc(u.minHint)}</small></div>
</div>
<div class="panes">
<div class="pane">
<div class="pane-head"><label for="src">${esc(u.input)}</label><div class="pane-actions"><button type="button" class="btn btn-outline" id="paste">${esc(u.paste)}</button><button type="button" class="btn btn-quiet" id="clear">${esc(u.clear)}</button></div></div>
<textarea id="src" spellcheck="false" autocomplete="off" placeholder="${esc(u.placeholder)}"></textarea>
</div>
<div class="pane out">
<div class="pane-head"><span class="pane-title" id="freq-title">${esc(u.output)}</span><div class="pane-actions"><button type="button" class="btn btn-outline" id="csv">${esc(u.csv)}</button><button type="button" class="btn btn-primary" id="copy"><span class="idle">${esc(u.copy)}</span><span class="done">${CHECK}${esc(u.copied)}</span></button></div></div>
<div class="freq-wrap" role="region" aria-labelledby="freq-title" tabindex="0">
<p class="freq-empty" id="empty">${esc(u.empty)}</p>
<table class="found freq" id="table" hidden><thead><tr><th scope="col" class="n">${esc(u.rank)}</th><th scope="col" id="col-word">${esc(u.word)}</th><th scope="col" class="n">${esc(u.count)}</th><th scope="col" class="n">${esc(u.share)}</th></tr></thead><tbody id="rows"></tbody></table>
</div>
</div>
</div>
<div class="meta-row"><span id="counts">${esc(u.zero)}</span><span class="status" id="status" role="status" aria-live="polite"></span></div>
<fieldset class="options">
<div class="options-head"><legend>${esc(u.options)}</legend><button type="button" class="btn btn-quiet" id="reset">${esc(u.reset)}</button></div>
<div class="opt-grid">${page.options.map(checkbox).join("")}</div>
</fieldset>
</section>`;
}

const SWAP = `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M2.5 5.5h10M10 3l2.5 2.5L10 8M13.5 10.5h-10M6 8l-2.5 2.5L6 13"/></svg>`;
const OPEN = `<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" focusable="false"><path d="M9 2.5H4.5a1 1 0 0 0-1 1v9a1 1 0 0 0 1 1h7a1 1 0 0 0 1-1V6M9 2.5 12.5 6M9 2.5V6h3.5"/></svg>`;
const MINUS = `<svg class="sign" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true" focusable="false"><path d="M3 6h6"/></svg>`;
Expand Down Expand Up @@ -670,7 +699,7 @@ ${row("weekend", u.weekend)}
</section>`;
}

const TOOL_BODY = { paste: pasteTool, linebreaks: lineBreaksTool, case: caseTool, color: colorTool, invisible: invisibleTool, repeater: repeaterTool, chmod: chmodTool, slug: slugTool, special: specialTool, counter: counterTool, reverse: caseTool, flip: pasteTool, compare: compareTool, kdv: kdvTool, yas: yasTool, dates: datesTool };
const TOOL_BODY = { paste: pasteTool, linebreaks: lineBreaksTool, case: caseTool, color: colorTool, invisible: invisibleTool, repeater: repeaterTool, chmod: chmodTool, slug: slugTool, special: specialTool, counter: counterTool, frequency: frequencyTool, reverse: caseTool, flip: pasteTool, compare: compareTool, kdv: kdvTool, yas: yasTool, dates: datesTool };

/** Prose, a list of titled rows with sources, and a dated note; the paste and compare pages build theirs from why and shortcuts. */
function infoSection(page, sec) {
Expand Down Expand Up @@ -826,7 +855,7 @@ await mkdir(OUT, { recursive: true });
await cp(new URL("../public/", import.meta.url), OUT, { recursive: true });
await rm(new URL("signature.svg", OUT));
await writeFile(new URL("site.css", OUT), minifyCss((await read("../tokens.css")) + "\n" + (await read("../public/site.css"))));
for (const f of ["clean.js", "plain-text.js", "diff.js", "text-compare.js", "kdv.js", "kdv-hesaplama.js", "yas.js", "yas-hesaplama.js", "date-diff.js", "days-between-dates.js", "line-breaks.js", "remove-line-breaks.js", "case.js", "case-converter.js", "color.js", "hex-to-rgb.js", "invisible.js", "invisible-character.js", "repeat.js", "text-repeater.js", "reverse.js", "reverse-text.js", "flip.js", "upside-down-text.js", "chmod.js", "chmod-calculator.js", "slug.js", "slug-generator.js", "special.js", "remove-special-characters.js", "count.js", "karakter-sayaci.js", "nav.js"]) await cp(new URL(`../src/${f}`, import.meta.url), new URL(f, OUT));
for (const f of ["clean.js", "plain-text.js", "diff.js", "text-compare.js", "kdv.js", "kdv-hesaplama.js", "yas.js", "yas-hesaplama.js", "date-diff.js", "days-between-dates.js", "line-breaks.js", "remove-line-breaks.js", "case.js", "case-converter.js", "color.js", "hex-to-rgb.js", "invisible.js", "invisible-character.js", "repeat.js", "text-repeater.js", "reverse.js", "reverse-text.js", "flip.js", "upside-down-text.js", "chmod.js", "chmod-calculator.js", "slug.js", "slug-generator.js", "special.js", "remove-special-characters.js", "count.js", "karakter-sayaci.js", "frequency.js", "word-frequency-counter.js", "nav.js"]) await cp(new URL(`../src/${f}`, import.meta.url), new URL(f, OUT));

const built = [];
for (const page of pages.list) {
Expand Down
Loading