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 🙏

© 2026 – Pkg Stats / Ryan Hefner

multilingual-tokenizer

v1.0.0

Published

A Node.js library for tokenizing text in Thai, English, Japanese, and Korean using regex

Readme

Multilingual Tokenizer

A Node.js library for tokenizing text in multiple languages (Thai, English, Japanese, and Korean) using regex-based approaches.

Features

  • Support for tokenizing text in:
    • English
    • Thai
    • Japanese
    • Korean
  • Automatic language detection
  • Token classification (word, number, punctuation, etc.)
  • Normalization options
  • Whitespace preservation options
  • Simple, lightweight implementation using regular expressions

Installation

npm install multilingual-tokenizer

Usage

const {
  MultilingualTokenizer,
  TOKEN_TYPES,
} = require("multilingual-tokenizer");

// Create a new tokenizer instance
const tokenizer = new MultilingualTokenizer({
  preserveWhitespace: true, // Keep whitespace tokens
  normalizeText: true, // Apply Unicode normalization
});

// Tokenize English text
const englishText = "Hello, world!";
const englishTokens = tokenizer.tokenize(englishText);
console.log(englishTokens);

// Tokenize Thai text
const thaiText = "สวัสดีครับ";
const thaiTokens = tokenizer.tokenize(thaiText);
console.log(thaiTokens);

// Tokenize Japanese text
const japaneseText = "こんにちは、世界!";
const japaneseTokens = tokenizer.tokenize(japaneseText);
console.log(japaneseTokens);

// Tokenize Korean text
const koreanText = "안녕하세요, 세계!";
const koreanTokens = tokenizer.tokenize(koreanText);
console.log(koreanTokens);

// Force language selection
const forcedTokens = tokenizer.tokenize(englishText, "japanese");

// Extract only word tokens
const words = tokenizer.extractWords(englishTokens);

Token Structure

Each token is represented as an object with two properties:

{
  type: 'WORD',  // One of the values from TOKEN_TYPES
  value: 'Hello' // The actual token text
}

The available token types are:

  • WORD - Words and word-like constructs
  • NUMBER - Numeric values
  • SPACE - Whitespace (spaces, tabs, newlines)
  • PUNCTUATION - Punctuation marks
  • SYMBOL - Symbols (#, $, %, etc.)
  • OTHER - Unclassified characters

API Reference

Constructor

const tokenizer = new MultilingualTokenizer(options);

Options:

  • preserveWhitespace (default: false): Whether to include whitespace tokens in the output
  • normalizeText (default: true): Whether to apply Unicode normalization before tokenization

Methods

tokenize(text, language = null)

Tokenizes the input text. If language is not provided, it will be automatically detected.

  • text (string): The text to tokenize
  • language (string, optional): Force a specific language tokenizer ('english', 'thai', 'japanese', 'korean')
  • Returns: Array of token objects

detectLanguage(text)

Detects the dominant language in the text.

  • text (string): The text to analyze
  • Returns: String with language code ('english', 'thai', 'japanese', 'korean')

extractWords(tokens)

Extracts only the word tokens from an array of tokens.

  • tokens (array): Array of token objects
  • Returns: Array of strings (word values)

detokenize(tokens)

Converts tokens back to text.

  • tokens (array): Array of token objects
  • Returns: String of reconstructed text

Important Notes

This library uses regex-based tokenization, which is a simplified approach. For production use in applications requiring high accuracy in specific languages:

  • Thai: Consider using dictionary-based approaches (e.g., thai-tokenizer)
  • Japanese: Consider using morphological analyzers (e.g., kuromoji)
  • Korean: Consider using more sophisticated tokenizers (e.g., node-mecab-ya)

This library is intended for basic tokenization needs or cases where a lightweight solution is required.

License

MIT