explaingit

vinta/pangu.js

4,752TypeScriptAudience · developerComplexity · 1/5LicenseSetup · easy

TLDR

A JavaScript library that automatically inserts a space between Chinese, Japanese, or Korean characters and Latin letters or numbers, making mixed-language text easier to read on web pages or in Node.js apps.

Mindmap

mindmap
  root((pangu.js))
    What it does
      Auto-inserts spaces
      Mixed-script text
      DOM watcher mode
    Tech Stack
      TypeScript
      JavaScript
      Node.js
      Chrome Extension
    Use Cases
      Fix web page text
      Process strings in Node
      CLI text processing
    Audience
      Web developers
      Chinese content apps
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add to a web page to automatically space out Chinese text mixed with English words or digits as the page loads.

USE CASE 2

Use the Node.js API in a backend app or content pipeline to process mixed-script strings before saving or serving them.

USE CASE 3

Install the Chrome extension to improve readability on any website you browse without writing any code.

USE CASE 4

Process plain text files from the command line using the included CLI tool.

Tech stack

TypeScriptJavaScriptNode.jsChrome Extension

Getting it running

Difficulty · easy Time to first run · 5min
MIT license, use freely for any purpose including commercial, just keep the copyright notice.

In plain English

Pangu.js is a JavaScript library that automatically inserts a space between Chinese, Japanese, and Korean characters and Latin letters or numbers in text. When text mixes scripts such as Chinese alongside English words or digits, there is no automatic spacing between them, which many readers find harder to read. This library detects those boundaries and inserts a narrow space to improve readability. The project started as a Google Chrome browser extension that runs on web pages you visit, inserting spaces in real time as you browse. It is also available as a JavaScript library for developers who want to apply the same spacing in their own applications, either in a browser or in a Node.js environment. A command-line tool is included as well, so you can process plain text files directly from a terminal. For developers, the library exposes a few functions: one that processes a plain string and returns a spaced version, one that processes an HTML element in the page and updates its text in place, and one that watches the entire page for any DOM changes and automatically spaces new content as it appears. The library is designed for HTML pages and plain text, not for Markdown files, which the README notes explicitly. The same concept has been implemented by the community in Go, Python, Java, Ruby, Rust, Swift, and several other languages, all under the Pangu family name. The JavaScript version is published on npm and installable with a single command. It is a small, focused utility with no runtime dependencies and an MIT license.

Copy-paste prompts

Prompt 1
Using pangu.js in Node.js, write code to process an array of user-submitted strings and return them with proper spacing between Chinese and English characters.
Prompt 2
How do I integrate pangu.js into a React app so that Chinese text in rendered components is automatically spaced correctly?
Prompt 3
Show me how to use the pangu.js DOM watcher to automatically fix spacing on content that loads dynamically in a single-page app.
Open on GitHub → Explain another repo

← vinta on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.