examples/MCP-tools Public
import assert from "node:assert/strict";import { test } from "node:test";import { textStats } from "../src/tools/text-stats.ts";const now = new Date("2026-10-07T12:00:00Z");const stats = (text: string, words_per_minute = 238) => textStats.run({ text, words_per_minute }, { now });test("counts words, sentences and paragraphs", () => { const r = stats("The quick brown fox jumps. It lands well!\n\nA second paragraph? Yes."); assert.equal(r.words, 12); assert.equal(r.sentences, 4); assert.equal(r.paragraphs, 2);});test("counts characters as a reader sees them", () => { const r = stats("café 👍🏽"); assert.equal(r.characters, 6); assert.equal(r.characters_excluding_spaces, 5); assert.equal(r.words, 1);});test("keeps contractions whole and splits hyphenated words", () => { assert.equal(stats("Don't stop.").words, 2); assert.equal(stats("state-of-the-art").words, 4);});test("estimates reading time at the given speed", () => { const text = Array(476).fill("word").join(" "); assert.equal(stats(text).reading_time_seconds, 120); assert.equal(stats(text).reading_time, "2 min"); assert.equal(stats(text, 476).reading_time, "1 min"); assert.equal(stats("Just a few words.").reading_time, "under a minute");});test("empty and blank text is all zeros", () => { for (const text of ["", " \n\n "]) { const r = stats(text); assert.deepEqual([r.words, r.sentences, r.paragraphs, r.reading_time_seconds], [0, 0, 0, 0]); assert.equal(r.reading_time, "0 min"); }});