MCPcopy
hub / github.com/vinta/pangu.js

github.com/vinta/pangu.js @v7.2.1 sqlite

repository ↗ · DeepWiki ↗ · release v7.2.1 ↗
204 symbols 523 edges 69 files 0 documented · 0%
README

為什麼你們就是不能加個空格呢?

jsDelivr Hits npm Downloads npm Version Chrome Web Store Version

如果你跟我一樣,每次看到網頁上的中文字和英文、數字、符號擠在一塊,就會坐立難安,忍不住想在它們之間加個空格。這個 Google Chrome 外掛正是你在網路世界走跳所需要的東西,它會自動替你在網頁中所有的中文字和半形的英文、數字、符號之間插入空白。

漢學家稱這個空白字元為「盤古之白」,因為它劈開了全形字和半形字之間的混沌。另有研究顯示,打字的時候不喜歡在中文和英文之間加空格的人,感情路都走得很辛苦,有七成的比例會在 34 歲的時候跟自己不愛的人結婚,而其餘三成的人最後只能把遺產留給自己的貓。畢竟愛情跟書寫都需要適時地留白。

與大家共勉之。

Installation

For Users

For Developers

Usage

npm install pangu --save-exact

Learn more on npm.

Browser

UMD (Script Tag)

<script src="https://github.com/vinta/pangu.js/raw/v7.2.1/pangu/dist/browser/pangu.umd.js"></script>
<script>
  const text = pangu.spacingText('當你凝視著bug,bug也凝視著你');
  // text = '當你凝視著 bug,bug 也凝視著你'

  // Process specific elements using spacingNode()
  pangu.spacingNode(document.getElementById('main'));
  document.querySelectorAll('.comment').forEach((el) => pangu.spacingNode(el));
  document.querySelectorAll('p').forEach((el) => pangu.spacingNode(el));

  document.addEventListener('DOMContentLoaded', () => {
    // listen to any DOM change and automatically perform spacing via MutationObserver()
    pangu.autoSpacingPage();
  });
</script>

ES Modules

<script type="module">
  import { pangu } from 'pangu/browser';

  const text = pangu.spacingText('這個人老是在寫程式,是不是有bin啊?');
  // text = '這個人老是在寫程式,是不是有 bin 啊?'

  // Process specific elements using spacingNode()
  pangu.spacingNode(document.getElementById('main'));
  document.querySelectorAll('.comment').forEach((el) => pangu.spacingNode(el));
  document.querySelectorAll('p').forEach((el) => pangu.spacingNode(el));
</script>

Also on:

  • https://cdn.jsdelivr.net/npm/pangu@7.2.1/dist/browser/pangu.umd.js
  • https://unpkg.com/pangu@7.2.1/dist/browser/pangu.umd.js

Node.js

import pangu from 'pangu';
// or
const pangu = require('pangu');

const text = pangu.spacingText('不能信任那些Terminal或Editor用白底的人');
// text = '不能信任那些 Terminal 或 Editor 用白底的人'

const content = await pangu.spacingFile('/path/to/text.txt');

You SHOULD NOT use pangu.js to spacing Markdown documents, this library is specially designed for HTML webpages and plain texts without any markup language. See issue #127.

CLI

$ pangu "與PM戰鬥的人,應當小心自己不要成為PM"
與 PM 戰鬥的人,應當小心自己不要成為 PM

$ pangu --check "盤古新聞網:工程師會議中默不作聲,PM 恐成最大贏家"

$ pangu --help
usage: pangu [-h] [-v] [-t] [-f] [-c] text_or_path

pangu.js -- Paranoid text spacing for good readability, to automatically
insert whitespace between CJK and half-width characters (alphabetical letters,
numerical digits and symbols).

positional arguments:
  text_or_path   the text or file path to apply spacing

optional arguments:
  -h, --help     show this help message and exit
  -v, --version  show program's version number and exit
  -t, --text     specify the input value is a text
  -f, --file     specify the input value is a file path
  -c, --check    check if text has proper spacing (exit 0 if yes, 1 if no)

Testing

You need to install Node.js.

$ git clone https://github.com/vinta/pangu.js.git && cd pangu.js
$ npm install                          # install dependencies
$ npx playwright install --with-deps   # install headless browsers for testing
$ npm run test                         # run all tests (unit + browser)

License

Released under the MIT License.

Author

Extension points exported contracts — how you extend this code

AutoSpacingPageConfig (Interface)
(no doc)
src/browser/pangu.ts
Window (Interface)
(no doc)
browser-extensions/chrome/src/content-script.ts
VisibilityDetectorConfig (Interface)
(no doc)
src/browser/visibility-detector.ts
Settings (Interface)
(no doc)
browser-extensions/chrome/src/utils/types.ts
TaskSchedulerConfig (Interface)
(no doc)
src/browser/task-scheduler.ts
PingMessage (Interface)
(no doc)
browser-extensions/chrome/src/utils/types.ts
Window (Interface)
(no doc)
src/browser/pangu.umd.ts
ManualSpacingMessage (Interface)
(no doc)
browser-extensions/chrome/src/utils/types.ts

Core symbols most depended-on inside this repo

spacingText
called by 416
src/shared/index.ts
spacingNode
called by 34
src/browser/pangu.ts
loadFixture
called by 21
tests/browser/pangu.playwright.ts
testPattern
called by 17
tests/browser/urlpattern.playwright.ts
getCachedSettings
called by 17
browser-extensions/chrome/src/utils/settings.ts
spacingPage
called by 14
src/browser/pangu.ts
isElementVisuallyHidden
called by 9
src/browser/pangu.ts
renderUrlList
called by 9
browser-extensions/chrome/src/options.ts

Shape

Method 133
Class 36
Function 25
Interface 10

Languages

TypeScript100%

Modules by API surface

browser-extensions/chrome/vendors/pangu/pangu.umd.js65 symbols
browser-extensions/chrome/src/popup.ts22 symbols
browser-extensions/chrome/src/options.ts21 symbols
src/browser/pangu.ts19 symbols
src/browser/task-scheduler.ts15 symbols
src/shared/index.ts12 symbols
src/browser/dom-walker.ts9 symbols
src/browser/visibility-detector.ts7 symbols
browser-extensions/chrome/src/utils/types.ts5 symbols
src/node/index.ts4 symbols
src/node/index.cjs.ts4 symbols
src/node/cli.ts3 symbols

Dependencies from manifests, versioned

@playwright/test1.56.1 · 1×
@types/chrome0.0.326 · 1×
@types/node24.0.2 · 1×
eslint9.29.0 · 1×
eslint-config-prettier10.1.5 · 1×
nodemon3.1.10 · 1×
pangu7.2.1 · 1×
prettier3.5.3 · 1×
typescript5.8.3 · 1×
typescript-eslint8.56.1 · 1×

For agents

$ claude mcp add pangu.js \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact