npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

typo-ime

v0.0.3

Published

In-browser Pinyin-to-Hanzi IME with fuzzy search and bigram probabilistic suggestions

Downloads

19

Readme

typo-ime

In-browser Pinyin-to-Hanzi IME with fuzzy search and bigram probabilistic suggestions.


🔍 Features

  • Lightweight: No external dependencies, runs entirely in-browser.
  • High-performance: Web Worker offloads fuzzy-search + bigram logic.
  • Configurable: Set suggestion limits, button styles, custom commit callbacks.
  • Easy to integrate: Simple API to attach IME behavior to any input.

💾 Installation

npm install typo-ime
# or
yarn add typo-ime

🚀 Basic Usage (JavaScript)

  1. Import and initialize the IME:
import { TypoAPI } from 'typo-ime';

// Create and initialize
TypoAPI.create().then((ime) => {
  // Attach to your input and suggestion container
  ime.attach({
    inputEl: document.getElementById('pinyinInput'),
    suggestionsEl: document.getElementById('suggestions'),
    onCommit: (text) => console.log('Committed:', text)
  });
});
  1. Type Pinyin into the input, and watch fuzzy suggestions appear.

🛠️ Advanced Usage

A more detailed example showing all available options:

import { TypoAPI } from 'typo-ime';

(async () => {
  // 1. Create instance and wait for worker initialization
  const ime = await TypoAPI.create();

  // 2. Configure options
  const config = {
    inputEl: document.querySelector('#pinyinInput'),    // HTMLInputElement
    suggestionsEl: document.querySelector('#suggestions'),// HTMLElement
    onCommit: (finalText) => {
      // Called when user commits text (via click or form submit)
      console.log('User committed:', finalText);
      // You could insert the text into your chat, editor, etc.
    },
    suggestionLimit: 10,     // Max number of suggestions to display
    suggestionBtnClass: 'my-custom-btn', // Custom CSS classes for buttons
  };

  // 3. Attach IME behavior
  ime.attach(config);

  // 4. (Optional) Manually perform searches
  const results = await ime.search('ni', { key: 'pinyin', threshold: 0.3 }, null);
  console.log('Manual search results:', results);

  // 5. Terminate worker when done
  // ime.terminate();
})();

Option details:

| Option | Type | Default | Description | | -------------------- | ------------------------ | -------------------------------------------- | ------------------------------------------- | | inputEl | HTMLInputElement | — | Text field where user types Pinyin. | | suggestionsEl | HTMLElement | — | Container for suggestion buttons. | | onCommit | (text: string) => void | () => {} | Callback when a suggestion is committed. | | suggestionLimit | number | 15 | Maximum number of suggestions shown. | | suggestionBtnClass | string | 'btn btn-outline-secondary suggestion-btn' | CSS classes for styling suggestion buttons. |


📖 API Reference

TypoAPI.create(): Promise<TypoAPI>

Creates and initializes a new IME instance. Resolves once the Web Worker is ready.

instance.attach(options)

Attach IME behavior to DOM elements.

  • options.inputEl (HTMLInputElement): Input element for Pinyin.
  • options.suggestionsEl (HTMLElement): Container where suggestion buttons will be rendered.
  • options.onCommit (text: string) => void: Called when user commits a suggestion (click or form submit).
  • options.suggestionLimit (number, optional): Limit number of suggestions (default 15).
  • options.suggestionBtnClass (string, optional): CSS classes for suggestion buttons.

instance.search(query, options, previousWordHanzi?): Promise<Array>

Manually trigger a search. Returns an array of { item, score, bigramScore }.

  • query (string): Pinyin fragment to search.
  • options.key ('pinyin'|'hanzi'): Field to search on.
  • options.threshold (number, optional): Minimum similarity score (0-1). Default 0.6.
  • options.lengthTolerance (number, optional): Allowed length variance. Default 2.
  • previousWordHanzi (string|null, optional): Previous character context for bigram scoring.

instance.terminate()

Terminates the underlying Web Worker. Use when you no longer need the IME.


💡 Contributing

Pull requests and issues are welcome! Please read CONTRIBUTING.md for details.


📜 License

MIT © 2025 Brandon57l