<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: xiu kuang</title>
    <description>The latest articles on DEV Community by xiu kuang (@xiu_kuang_f0402a0d68ab4e6).</description>
    <link>https://dev.to/xiu_kuang_f0402a0d68ab4e6</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4055844%2F8a56a357-8126-419f-b79f-cef34c19537f.png</url>
      <title>DEV Community: xiu kuang</title>
      <link>https://dev.to/xiu_kuang_f0402a0d68ab4e6</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/xiu_kuang_f0402a0d68ab4e6"/>
    <language>en</language>
    <item>
      <title>Building a Browser-Based Line Break Remover with Local-First Text Processing</title>
      <dc:creator>xiu kuang</dc:creator>
      <pubDate>Sat, 01 Aug 2026 02:28:59 +0000</pubDate>
      <link>https://dev.to/xiu_kuang_f0402a0d68ab4e6/building-a-browser-based-line-break-remover-with-local-first-text-processing-3k32</link>
      <guid>https://dev.to/xiu_kuang_f0402a0d68ab4e6/building-a-browser-based-line-break-remover-with-local-first-text-processing-3k32</guid>
      <description>&lt;p&gt;Removing line breaks looks like a one-regex job. &lt;code&gt;text.replace(/\n/g, '')&lt;/code&gt; and you're done. Then real text shows up, and it turns out line endings are a small historical mess.&lt;/p&gt;

&lt;p&gt;There are three different characters that can end a line: LF, CRLF, and CR. Text copied from Word, a spreadsheet, or a GitHub issue uses whichever one its origin platform chose, and a single paste can contain several at once. Remove only &lt;code&gt;\n&lt;/code&gt; and the &lt;code&gt;\r&lt;/code&gt; characters are still there. Remove everything and paragraph boundaries collapse into a wall of text.&lt;/p&gt;

&lt;p&gt;I built a line break remover as part of &lt;a href="https://www.textfixhub.com/" rel="noopener noreferrer"&gt;TextFixHub&lt;/a&gt;, a collection of free browser-based text utilities.&lt;/p&gt;

&lt;p&gt;You can try it here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.textfixhub.com/tools/line-break-remover" rel="noopener noreferrer"&gt;TextFixHub Line Break Remover&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Three modes, because the task is three different things
&lt;/h2&gt;

&lt;p&gt;"Remove line breaks" means something different depending on what the text is for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Replace with space&lt;/strong&gt; — single breaks become spaces; blank lines stay as paragraph breaks. The default, and the safest.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remove entirely&lt;/strong&gt; — every break is deleted. Words will run together. Useful when you know the input has no fragile spots.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Remove with space&lt;/strong&gt; — every break is deleted, but a space is added where each line ended, so words don't glue together.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first version had two modes. The gap showed up fast: paste &lt;code&gt;Hello\nWorld&lt;/code&gt;, pick "Remove entirely", get &lt;code&gt;HelloWorld&lt;/code&gt;. That's not what anyone wants, so a third mode exists now.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pipeline
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Strip the BOM if present.&lt;/li&gt;
&lt;li&gt;Normalize all line endings to LF.&lt;/li&gt;
&lt;li&gt;Apply the selected mode.&lt;/li&gt;
&lt;li&gt;Remove trailing whitespace.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The BOM
&lt;/h3&gt;

&lt;p&gt;Some files edited on Windows start with a byte-order mark (U+FEFF). It's invisible, but it is the first character, and it quietly breaks naive logic. One line handles it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;charCodeAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mh"&gt;0xfeff&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;slice&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Line endings are a historical accident
&lt;/h3&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Line ending&lt;/th&gt;
&lt;th&gt;Bytes&lt;/th&gt;
&lt;th&gt;Where it comes from&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;LF&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\n&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Unix, macOS, most web content&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CRLF&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\r\n&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Windows&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CR&lt;/td&gt;
&lt;td&gt;&lt;code&gt;\r&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Classic Mac OS (rare now, but real)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Mixed endings appear in the same input more often than you'd expect. The fix is to normalize first, in the right order — CRLF has to be handled before CR, otherwise &lt;code&gt;\r\n&lt;/code&gt; becomes &lt;code&gt;\n\n&lt;/code&gt; and invents a phantom blank line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CRLF_RE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\r\n&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;CR_RE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\r&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CRLF_RE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CR_RE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Protecting paragraph breaks
&lt;/h3&gt;

&lt;p&gt;"Replace with space" should keep paragraphs. Two or more consecutive newlines are a paragraph boundary, so they need to survive while single breaks turn into spaces.&lt;/p&gt;

&lt;p&gt;The trick is a placeholder. Swap the paragraph break for a character the input can't contain — NUL (&lt;code&gt;\0&lt;/code&gt;) — handle the single breaks, then put the paragraphs back:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;withParaBreaks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;DOUBLE_NEWLINE_RE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s1"&gt;0&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;withSpaces&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;withParaBreaks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;NEWLINE_RE&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt; &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;withSpaces&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\0&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three regex passes, no state machine, no index bookkeeping. The placeholder stays in my toolbox for any text transformation where some matches need to survive while others don't.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it stays in the browser
&lt;/h2&gt;

&lt;p&gt;The input never leaves the device. No upload, no server-side API, no account. For a text tool, all of the work is local anyway, so the deployment stays static and the privacy story is easy to verify — the code that touches your text is right in the browser, not hidden behind an API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing the edge cases
&lt;/h2&gt;

&lt;p&gt;The behavior above stays correct only if the tests pin it down. The suite covers:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;CRLF, LF, and CR endings individually&lt;/li&gt;
&lt;li&gt;Mixed endings in one input (&lt;code&gt;A\r\nB\nC\r&lt;/code&gt; → &lt;code&gt;A B C&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Paragraph preservation with 2 and 3 consecutive breaks&lt;/li&gt;
&lt;li&gt;Empty input and single-word input&lt;/li&gt;
&lt;li&gt;Trailing newlines&lt;/li&gt;
&lt;li&gt;The BOM case&lt;/li&gt;
&lt;li&gt;Large inputs: 100K+ characters processed in well under 500ms&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What I learned
&lt;/h2&gt;

&lt;p&gt;"Remove line breaks" is not one operation. It's at least three, and the difference between them matters to the user even when the user can't name it. &lt;code&gt;Hello\nWorld&lt;/code&gt; becoming &lt;code&gt;HelloWorld&lt;/code&gt; is the perfect example — paste a list, pick the wrong mode, get garbage, and no error message explains why.&lt;/p&gt;

&lt;p&gt;The placeholder trick generalizes: pick a character the input can't contain, and protecting part of a match while transforming the rest stops being scary.&lt;/p&gt;

&lt;p&gt;The finished tool is here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.textfixhub.com/tools/line-break-remover" rel="noopener noreferrer"&gt;TextFixHub Line Break Remover&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The other TextFixHub tools are at &lt;a href="https://www.textfixhub.com/" rel="noopener noreferrer"&gt;https://www.textfixhub.com/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you spot any mistakes here, please point them out — I'd appreciate it. Thanks for reading.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>javascript</category>
      <category>tools</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Building a Browser-Based Sentence Counter with Local-First Text Processing</title>
      <dc:creator>xiu kuang</dc:creator>
      <pubDate>Fri, 31 Jul 2026 02:14:15 +0000</pubDate>
      <link>https://dev.to/xiu_kuang_f0402a0d68ab4e6/building-a-browser-based-sentence-counter-with-local-first-text-processing-2b05</link>
      <guid>https://dev.to/xiu_kuang_f0402a0d68ab4e6/building-a-browser-based-sentence-counter-with-local-first-text-processing-2b05</guid>
      <description>&lt;p&gt;Many text utilities are simple enough to run entirely in the browser.&lt;/p&gt;

&lt;p&gt;A sentence counter is a good example. The browser already has everything it needs to accept text, analyze it, and display useful statistics. Sending the input to a remote server is often unnecessary.&lt;/p&gt;

&lt;p&gt;I built a small browser-based sentence counter as part of &lt;a href="https://www.textfixhub.com/" rel="noopener noreferrer"&gt;TextFixHub&lt;/a&gt;, a collection of free text utilities for everyday writing and editing.&lt;/p&gt;

&lt;p&gt;You can try it here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.textfixhub.com/tools/sentence-counter" rel="noopener noreferrer"&gt;TextFixHub Sentence Counter&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why process text locally?
&lt;/h2&gt;

&lt;p&gt;Text input can be sensitive. It may contain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Draft articles&lt;/li&gt;
&lt;li&gt;School assignments&lt;/li&gt;
&lt;li&gt;Internal notes&lt;/li&gt;
&lt;li&gt;Customer messages&lt;/li&gt;
&lt;li&gt;Code comments&lt;/li&gt;
&lt;li&gt;Unpublished content&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a basic counting tool, uploading this text to a server does not provide much additional value. Local processing has several useful properties:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The input does not need to leave the user's device.&lt;/li&gt;
&lt;li&gt;There is no text-processing API to maintain.&lt;/li&gt;
&lt;li&gt;The tool can respond without waiting for a network request.&lt;/li&gt;
&lt;li&gt;The application can work without a user account.&lt;/li&gt;
&lt;li&gt;The server does not need to store or process the submitted text.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This does not make every browser application private by default. Analytics, third-party scripts, error reporting, and hosting configuration still matter. It simply means that the core text analysis can remain local.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the tool calculates
&lt;/h2&gt;

&lt;p&gt;The sentence counter displays more than just a sentence total. It also calculates:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Sentence count&lt;/li&gt;
&lt;li&gt;Word count&lt;/li&gt;
&lt;li&gt;Character count with spaces&lt;/li&gt;
&lt;li&gt;Character count without spaces&lt;/li&gt;
&lt;li&gt;Paragraph count&lt;/li&gt;
&lt;li&gt;Line count&lt;/li&gt;
&lt;li&gt;Average sentence length&lt;/li&gt;
&lt;li&gt;Average word length&lt;/li&gt;
&lt;li&gt;Estimated reading time&lt;/li&gt;
&lt;li&gt;Estimated speaking time&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The additional statistics make the tool useful for editing and reviewing content, rather than only answering “How many sentences are there?”&lt;/p&gt;

&lt;h2&gt;
  
  
  A simple analysis pipeline
&lt;/h2&gt;

&lt;p&gt;The browser-side pipeline is intentionally straightforward:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Read the current value from the text input.&lt;/li&gt;
&lt;li&gt;Normalize the relevant whitespace.&lt;/li&gt;
&lt;li&gt;Detect sentence boundaries.&lt;/li&gt;
&lt;li&gt;Split the text into words, paragraphs, and lines.&lt;/li&gt;
&lt;li&gt;Calculate the derived statistics.&lt;/li&gt;
&lt;li&gt;Render the results immediately.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The important design choice is that the input stays in the browser throughout this process.&lt;/p&gt;

&lt;p&gt;A simplified version of the idea looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;type&lt;/span&gt; &lt;span class="nx"&gt;TextStats&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;sentences&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
  &lt;span class="na"&gt;words&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
  &lt;span class="na"&gt;characters&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
  &lt;span class="na"&gt;charactersWithoutSpaces&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
  &lt;span class="na"&gt;paragraphs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
  &lt;span class="na"&gt;lines&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;countWords&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;normalized&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

  &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nx"&gt;normalized&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;normalized&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;+/&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;countCharactersWithoutSpaces&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;string&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\s&lt;/span&gt;&lt;span class="sr"&gt;/g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;''&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The actual implementation also needs to handle empty input, whitespace-only input, paragraph boundaries, and the distinction between visible characters and whitespace.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sentence boundaries are not completely trivial
&lt;/h2&gt;

&lt;p&gt;Counting sentences looks easy until real text appears.&lt;/p&gt;

&lt;p&gt;A simple approach can count punctuation such as &lt;code&gt;.&lt;/code&gt;, &lt;code&gt;!&lt;/code&gt;, and &lt;code&gt;?&lt;/code&gt;. However, periods can also appear in:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Abbreviations&lt;/li&gt;
&lt;li&gt;Decimal numbers&lt;/li&gt;
&lt;li&gt;Domain names&lt;/li&gt;
&lt;li&gt;Email addresses&lt;/li&gt;
&lt;li&gt;Version numbers&lt;/li&gt;
&lt;li&gt;Initials&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This means that a sentence counter should not imply perfect linguistic understanding. It is a practical text utility with defined heuristics.&lt;/p&gt;

&lt;p&gt;For a lightweight browser tool, a transparent heuristic is often more useful than a large natural-language-processing dependency. The tool should also explain what it counts and avoid presenting an approximate result as a scientific linguistic measurement.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reading time and speaking time
&lt;/h2&gt;

&lt;p&gt;Reading and speaking time are estimates based on word count.&lt;/p&gt;

&lt;p&gt;For example, the application can use separate words-per-minute assumptions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;READING_WORDS_PER_MINUTE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;SPEAKING_WORDS_PER_MINUTE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;130&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;readingMinutes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nx"&gt;wordCount&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;READING_WORDS_PER_MINUTE&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;speakingMinutes&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;
  &lt;span class="nx"&gt;wordCount&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;SPEAKING_WORDS_PER_MINUTE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These numbers are not universal facts about every reader or speaker. They are simple reference estimates that help users understand the approximate size of their text.&lt;/p&gt;

&lt;p&gt;The interface should avoid suggesting false precision. Displaying “about 2 minutes” is generally more useful than displaying a value with several decimal places.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I used a static deployment
&lt;/h2&gt;

&lt;p&gt;The application is built with Next.js and TypeScript and deployed as a static website.&lt;/p&gt;

&lt;p&gt;The tool does not need a database or an application server to analyze text. This keeps the architecture small:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The UI runs in the browser.&lt;/li&gt;
&lt;li&gt;The text-processing functions are regular TypeScript modules.&lt;/li&gt;
&lt;li&gt;The page can be statically generated.&lt;/li&gt;
&lt;li&gt;The deployment surface is smaller than a server-based implementation.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A smaller architecture also makes the privacy explanation easier to verify: the main text operation is visible in the client-side application rather than hidden behind an API.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing the text-processing functions
&lt;/h2&gt;

&lt;p&gt;The UI is only one part of the tool. The text-processing functions should be tested independently with cases such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Empty input&lt;/li&gt;
&lt;li&gt;Whitespace-only input&lt;/li&gt;
&lt;li&gt;One sentence&lt;/li&gt;
&lt;li&gt;Multiple paragraphs&lt;/li&gt;
&lt;li&gt;Multiple line breaks&lt;/li&gt;
&lt;li&gt;Punctuation at the end of a sentence&lt;/li&gt;
&lt;li&gt;Text containing numbers&lt;/li&gt;
&lt;li&gt;Text containing Unicode characters&lt;/li&gt;
&lt;li&gt;Text with repeated spaces&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Separating the counting logic from the UI makes these cases easier to test and reduces the chance that a visual change breaks the underlying calculations.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I learned
&lt;/h2&gt;

&lt;p&gt;The main lesson was that small tools still need clear boundaries.&lt;/p&gt;

&lt;p&gt;A sentence counter does not need an account system, a database, or a text-processing API. It does need:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A clearly defined counting method&lt;/li&gt;
&lt;li&gt;Useful output beyond one number&lt;/li&gt;
&lt;li&gt;Reasonable handling of empty and unusual input&lt;/li&gt;
&lt;li&gt;Tests for the core functions&lt;/li&gt;
&lt;li&gt;A clear explanation of what happens to user text&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Local-first processing is not a complete privacy guarantee for an entire website. It is a practical architectural decision for the core task: the text entered into the tool does not need to be uploaded for the tool to work.&lt;/p&gt;

&lt;p&gt;The finished tool is available here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.textfixhub.com/tools/sentence-counter" rel="noopener noreferrer"&gt;Try the TextFixHub Sentence Counter&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The other TextFixHub tools are available at &lt;a href="https://www.textfixhub.com/" rel="noopener noreferrer"&gt;https://www.textfixhub.com/&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>javascript</category>
      <category>tools</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
