pangu.js is a text spacing tool that automatically inserts spaces between Chinese characters and English letters, numbers, and symbols in JavaScript environments.
The tool solves the problem of mixed-script text appearing cramped and difficult to read. It works by applying spacing rules between full-width Chinese characters and half-width Latin characters, numbers, and punctuation. The core library uses regex-based pattern matching for standard cases. The Chrome extension builds on this with an AI Spacing feature that handles ambiguous symbols where context matters. For example, the plus sign in "18+" should not be spaced (meaning "or more"), but in "2 + Mario Kart" it should be spaced (as an operator). Rather than relying on fixed rules, the extension uses Chrome's Prompt API to run Gemini Nano locally on the device, allowing semantic judgment without sending data to external servers.
Developers should choose this tool if they need to automatically format mixed Chinese-English text in web applications or browser extensions. The library is available as an npm package for JavaScript projects. The Chrome extension is the most accessible form for end users who want automatic spacing across all web pages they visit. The project also maintains implementations in multiple programming languages, so developers working in Python, Go, Java, and other languages have equivalent options available.
Development activity shows a methodical approach to prompt engineering. The project uses an AI agent to propose and test spacing rules against the actual Gemini Nano model running in Chrome, rather than guessing at prompts. When test cases fail, the agent interviews the model to understand why and searches for alternative approaches. This iterative refinement cycle means the prompts are validated against real model behavior rather than theoretical assumptions.