<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Javascript on JsonKit Blog</title>
    <link>https://jsokit.com/blog/tags/javascript/</link>
    <description>Recent content in Javascript on JsonKit Blog</description>
    <generator>Hugo</generator>
    <language>en</language>
    <copyright>© 2025 JsonKit</copyright>
    <lastBuildDate>Tue, 12 May 2026 15:16:32 +0000</lastBuildDate>
    <atom:link href="https://jsokit.com/blog/tags/javascript/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>Word Counter: Unicode Handling and Regex Edge Cases in Mixed Chinese-English Text</title>
      <link>https://jsokit.com/blog/posts/word-counter-unicode-handling-and-regex-edge-cases-in-mixed-chinese-english-text/</link>
      <pubDate>Tue, 12 May 2026 15:16:32 +0000</pubDate>
      <guid>https://jsokit.com/blog/posts/word-counter-unicode-handling-and-regex-edge-cases-in-mixed-chinese-english-text/</guid>
      <description>Word Counter: Unicode Handling and Regex Edge Cases in Mixed Chinese-English Text Writing articles, tweets, documentation—you always need to count words. Many word counters exist, but when mixing Chinese and English, the results are often wrong. The culprit? Improper Unicode character handling and regex edge cases.&#xA;The Core Logic of Word Counting 1. Character Count Seems simple—just text.length, right? Not quite.&#xA;const text = &amp;#34;Hello 世界&amp;#34; console.log(text.length) // 8, correct But here&amp;rsquo;s the catch—Emoji and special characters:</description>
    </item>
    <item>
      <title>From Handshake to Heartbeat: Building a WebSocket Online Testing Tool</title>
      <link>https://jsokit.com/blog/posts/from-handshake-to-heartbeat-building-a-websocket-online-testing-tool/</link>
      <pubDate>Mon, 11 May 2026 16:42:42 +0000</pubDate>
      <guid>https://jsokit.com/blog/posts/from-handshake-to-heartbeat-building-a-websocket-online-testing-tool/</guid>
      <description>From Handshake to Heartbeat: Building a WebSocket Online Testing Tool Recently, I was developing a real-time chat feature with WebSocket on the backend. Debugging was painful—browser DevTools&amp;rsquo; Network panel shows WebSocket frames, but it&amp;rsquo;s not intuitive. So I built an online testing tool and documented the implementation process.&#xA;WebSocket Connection Lifecycle WebSocket isn&amp;rsquo;t just a simple TCP socket—it has a complete handshake and state management mechanism:&#xA;const ws = new WebSocket(&amp;#39;wss://example.</description>
    </item>
    <item>
      <title>Unit Converter: From Floating-Point Precision to Temperature Offsets</title>
      <link>https://jsokit.com/blog/posts/unit-converter-from-floating-point-precision-to-temperature-offsets/</link>
      <pubDate>Sat, 09 May 2026 17:52:56 +0000</pubDate>
      <guid>https://jsokit.com/blog/posts/unit-converter-from-floating-point-precision-to-temperature-offsets/</guid>
      <description>Unit Converter: From Floating-Point Precision to Temperature Offsets I recently needed to convert between inches and centimeters for a project. Wrote a quick formula, but the result didn&amp;rsquo;t match the design specs—that&amp;rsquo;s when I realized unit conversion isn&amp;rsquo;t as simple as it looks.&#xA;Basic Conversion: The Base Unit Method The obvious approach is direct formulas:&#xA;// Inch to centimeter const inchToCm = (inch) =&amp;gt; inch * 2.54 // Centimeter to inch const cmToInch = (cm) =&amp;gt; cm / 2.</description>
    </item>
    <item>
      <title>JavaScript Timezone Conversion: From Unix Timestamps to IANA Identifiers</title>
      <link>https://jsokit.com/blog/posts/javascript-timezone-conversion-from-unix-timestamps-to-iana-identifiers/</link>
      <pubDate>Fri, 08 May 2026 17:18:37 +0000</pubDate>
      <guid>https://jsokit.com/blog/posts/javascript-timezone-conversion-from-unix-timestamps-to-iana-identifiers/</guid>
      <description>JavaScript Timezone Conversion: From Unix Timestamps to IANA Identifiers Recently built a cross-timezone meeting scheduler and stepped into quite a few timezone pitfalls. Let me share what I learned about JavaScript timezone handling.&#xA;The Essence: Unix Timestamps Have No Timezone Here&amp;rsquo;s a core concept: timestamps are timezone-agnostic.&#xA;const now = Date.now() // 1714838400000 - milliseconds since UTC 1970-01-01 // Beijing: 2024-05-04 20:00:00 // New York: 2024-05-04 08:00:00 // Same timestamp, different displays No matter where you are on Earth, Date.</description>
    </item>
    <item>
      <title>Text Deduplication Algorithms: From Set to Efficient Implementation</title>
      <link>https://jsokit.com/blog/posts/text-deduplication-algorithms-from-set-to-efficient-implementation/</link>
      <pubDate>Wed, 06 May 2026 14:17:41 +0000</pubDate>
      <guid>https://jsokit.com/blog/posts/text-deduplication-algorithms-from-set-to-efficient-implementation/</guid>
      <description>Text Deduplication Algorithms: From Set to Efficient Implementation Duplicate data is everywhere. Log analysis, user list cleaning, keyword extraction&amp;hellip; the scenarios are endless. Let&amp;rsquo;s dive into several deduplication approaches and their performance characteristics.&#xA;The Simplest Solution: Set Deduplication JavaScript&amp;rsquo;s Set is built for uniqueness:&#xA;function dedupeLines(text) { const lines = text.split(&amp;#39;\n&amp;#39;) return [...new Set(lines)].join(&amp;#39;\n&amp;#39;) } One line. Done. But there are caveats:&#xA;Order not guaranteed: Set doesn&amp;rsquo;t preserve insertion order (though modern JS engines mostly do) Case-sensitive: &amp;quot;Apple&amp;quot; and &amp;quot;apple&amp;quot; are treated as different items Empty lines: Blank lines get deduplicated too Order-Preserving Deduplication If you need to keep the original order, use Set + filter:</description>
    </item>
    <item>
      <title>From String Concatenation to Parameterized Queries: Building a Safe SQL Builder</title>
      <link>https://jsokit.com/blog/posts/from-string-concatenation-to-parameterized-queries-building-a-safe-sql-builder/</link>
      <pubDate>Sat, 02 May 2026 13:32:23 +0000</pubDate>
      <guid>https://jsokit.com/blog/posts/from-string-concatenation-to-parameterized-queries-building-a-safe-sql-builder/</guid>
      <description>From String Concatenation to Parameterized Queries: Building a Safe SQL Builder During a recent code review, I found this pattern scattered throughout the codebase:&#xA;const sql = `SELECT * FROM users WHERE id = ${userId}` Convenient? Yes. Secure? Absolutely not. This is a textbook SQL injection vulnerability. If userId comes from user input and someone passes &#39; OR &#39;1&#39;=&#39;1, your entire users table is compromised.&#xA;I decided to build a SQL query builder tool that generates common queries quickly while avoiding the security pitfalls of manual SQL writing.</description>
    </item>
    <item>
      <title>Set Operations in JavaScript: From Math Symbols to Code</title>
      <link>https://jsokit.com/blog/posts/set-operations-in-javascript-from-math-symbols-to-code/</link>
      <pubDate>Fri, 01 May 2026 17:59:48 +0000</pubDate>
      <guid>https://jsokit.com/blog/posts/set-operations-in-javascript-from-math-symbols-to-code/</guid>
      <description>Set Operations in JavaScript: From Math Symbols to Code I used to write nested loops when comparing two lists—finding common items, merging with deduplication, calculating differences. The code was messy. Then I discovered JavaScript&amp;rsquo;s Set object, which is practically built for this.&#xA;Mathematical Foundation Quick refresher:&#xA;Union (A ∪ B): All elements in A or B Intersection (A ∩ B): Elements in both A and B Difference (A - B): Elements in A but not in B Symmetric Difference (A △ B): Elements in either A or B, but not both Mathematically, set elements are unique and unordered.</description>
    </item>
    <item>
      <title>Building a Regex Tester: Real-time Highlighting and Performance Optimization</title>
      <link>https://jsokit.com/blog/posts/building-a-regex-tester-real-time-highlighting-and-performance-optimization/</link>
      <pubDate>Tue, 28 Apr 2026 15:26:37 +0000</pubDate>
      <guid>https://jsokit.com/blog/posts/building-a-regex-tester-real-time-highlighting-and-performance-optimization/</guid>
      <description>Building a Regex Tester: Real-time Highlighting and Performance Optimization I was working on form validation recently, dealing with various regular expressions. Testing each regex change required a page refresh - too tedious. So I built my own regex tester. Here&amp;rsquo;s how it works.&#xA;How Regex Engines Work JavaScript uses a backtracking regex engine. Think of it as &amp;ldquo;trial and error&amp;rdquo;:&#xA;const regex = /a+b/ const text = &amp;#39;aaab&amp;#39; // Engine execution: // 1.</description>
    </item>
    <item>
      <title>Understanding Radix Conversion: From Binary to Hexadecimal Algorithms</title>
      <link>https://jsokit.com/blog/posts/understanding-radix-conversion-from-binary-to-hexadecimal-algorithms/</link>
      <pubDate>Sat, 25 Apr 2026 09:14:41 +0000</pubDate>
      <guid>https://jsokit.com/blog/posts/understanding-radix-conversion-from-binary-to-hexadecimal-algorithms/</guid>
      <description>Understanding Radix Conversion: From Binary to Hexadecimal Algorithms While building a radix converter tool, I revisited the fundamentals of number base conversion. Although parseInt and toString handle most cases, understanding the underlying algorithms is crucial for dealing with edge cases.&#xA;JavaScript Built-in Conversion The simplest approach uses JavaScript&amp;rsquo;s built-in methods. Number.prototype.toString(radix) converts decimal to any base:&#xA;const num = 255 num.toString(2) // &amp;#34;11111111&amp;#34; (binary) num.toString(8) // &amp;#34;377&amp;#34; (octal) num.toString(16) // &amp;#34;ff&amp;#34; (hexadecimal) Reverse conversion uses parseInt(string, radix):</description>
    </item>
    <item>
      <title>Building a Placeholder Image Generator with Canvas API: From Basics to Performance</title>
      <link>https://jsokit.com/blog/posts/building-a-placeholder-image-generator-with-canvas-api-from-basics-to-performance/</link>
      <pubDate>Wed, 22 Apr 2026 17:56:14 +0000</pubDate>
      <guid>https://jsokit.com/blog/posts/building-a-placeholder-image-generator-with-canvas-api-from-basics-to-performance/</guid>
      <description>Building a Placeholder Image Generator with Canvas API: From Basics to Performance As a frontend developer, I often need placeholder images: design assets aren&amp;rsquo;t ready, images are missing, or I&amp;rsquo;m building a quick prototype. I used to rely on services like placehold.co or picsum.photos, but network issues or specific style requirements led me to build my own.&#xA;Canvas API Basics The core is the Canvas API. Here&amp;rsquo;s the simplest implementation:</description>
    </item>
  </channel>
</rss>
