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

mecab-ko-wasm

v0.5.0

Published

WebAssembly bindings for MeCab-Ko (Korean morphological analyzer)

Downloads

217

Readme

mecab-ko-wasm

WebAssembly bindings for MeCab-Ko, a Korean morphological analyzer.

This package enables Korean morphological analysis in web browsers and Node.js environments through WebAssembly.

Features

  • Fast: Compiled to WebAssembly for near-native performance
  • Lightweight: No external dependencies required in the browser
  • Cross-platform: Works in both browser and Node.js environments
  • Type-safe: Full TypeScript type definitions included

Installation

Using npm

npm install mecab-ko-wasm

Using yarn

yarn add mecab-ko-wasm

Usage

Browser (ES Modules)

import init, { Mecab } from 'mecab-ko-wasm';

async function analyze() {
  // Initialize the WASM module
  await init();

  // Create a Mecab instance
  const mecab = new Mecab();

  // Extract morphemes
  const morphs = mecab.morphs("안녕하세요");
  console.log(morphs); // ["안녕", "하", "세요"]

  // Get part-of-speech tags
  const posJson = mecab.pos("형태소 분석");
  const pos = JSON.parse(posJson);
  console.log(pos); // [["형태소", "NNG"], ["분석", "NNG"]]

  // Get detailed token information
  const tokens = mecab.tokenize("한국어 분석기");
  tokens.forEach(token => {
    console.log(`${token.surface}: ${token.pos}`);
  });
}

analyze();

Node.js

const { Mecab } = require('mecab-ko-wasm');

const mecab = new Mecab();

// Extract morphemes
const morphs = mecab.morphs("안녕하세요");
console.log(morphs); // ["안녕", "하", "세요"]

// Extract nouns
const nouns = mecab.nouns("형태소 분석기입니다");
console.log(nouns); // ["형태소", "분석기"]

// Wakati tokenization
const words = mecab.wakati("한국어 처리");
console.log(words); // ["한국어", "처리"]

TypeScript

import init, { Mecab, WasmToken } from 'mecab-ko-wasm';

async function analyze(text: string): Promise<void> {
  await init();

  const mecab = new Mecab();

  // Tokenize with full information
  const tokens: WasmToken[] = mecab.tokenize(text);
  tokens.forEach((token: WasmToken) => {
    console.log({
      surface: token.surface,
      pos: token.pos,
      start: token.start,
      end: token.end,
    });
  });

  // Extract morphemes
  const morphs: string[] = mecab.morphs(text);
  console.log('Morphemes:', morphs);
}

analyze("한국어 형태소 분석");

API Reference

Mecab

The main class for Korean morphological analysis.

Constructor

new Mecab(): Mecab

Creates a new Mecab instance with the default dictionary.

Throws: Error if initialization fails

Methods

tokenize(text: string): WasmToken[]

Tokenizes the input text and returns detailed token information.

Parameters:

  • text: Input text to analyze

Returns: Array of WasmToken objects containing surface form, POS tag, and position information

Example:

const tokens = mecab.tokenize("안녕하세요");
// [
//   { surface: "안녕", pos: "NNG", start: 0, end: 6, ... },
//   { surface: "하", pos: "XSV", start: 6, end: 9, ... },
//   ...
// ]
morphs(text: string): string[]

Extracts morphemes from the input text.

Parameters:

  • text: Input text to analyze

Returns: Array of morpheme strings

Example:

const morphs = mecab.morphs("안녕하세요");
// ["안녕", "하", "세요"]
pos(text: string): string

Extracts part-of-speech tagged pairs as a JSON string.

Parameters:

  • text: Input text to analyze

Returns: JSON string containing an array of [surface, pos] pairs

Example:

const posJson = mecab.pos("안녕하세요");
const pos = JSON.parse(posJson);
// [["안녕", "NNG"], ["하", "XSV"], ["세요", "EP+EF"]]
nouns(text: string): string[]

Extracts only nouns from the input text.

Parameters:

  • text: Input text to analyze

Returns: Array of noun strings

Example:

const nouns = mecab.nouns("형태소 분석기입니다");
// ["형태소", "분석기"]
wakati(text: string): string[]

Performs wakati (space-separated) tokenization.

Parameters:

  • text: Input text to analyze

Returns: Array of morpheme strings

Example:

const words = mecab.wakati("형태소 분석");
// ["형태소", "분석"]

WasmToken

Represents a single token with detailed morphological information.

Properties

  • surface: string - The surface form (표면형) of the token
  • pos: string - Part-of-speech tag (품사 태그)
  • start: number - Start position in bytes
  • end: number - End position in bytes
  • reading: string | undefined - Reading of the token (if available)
  • lemma: string | undefined - Base form/lemma (if available)

Methods

toJSON(): string

Converts the token to a JSON string.

Returns: JSON string representation of the token

Building from Source

Prerequisites

  • Rust (1.75+)
  • wasm-pack
cargo install wasm-pack

Build

# Build for browser
wasm-pack build --target web

# Build for Node.js
wasm-pack build --target nodejs

# Build for bundlers (webpack, etc.)
wasm-pack build --target bundler

Development

# Run tests
wasm-pack test --node

# Run tests in browser (requires Chrome/Firefox)
wasm-pack test --headless --firefox

Part-of-Speech Tags

MeCab-Ko uses the Sejong corpus POS tag set. Common tags include:

  • NNG: General noun (일반 명사)
  • NNP: Proper noun (고유 명사)
  • VV: Verb (동사)
  • VA: Adjective (형용사)
  • MAG: General adverb (일반 부사)
  • JKS: Subjective case particle (주격 조사)
  • JKO: Objective case particle (목적격 조사)
  • EP: Pre-final ending (선어말 어미)
  • EF: Final ending (어말 어미)

For a complete list, see Sejong POS Tags.

Performance

MeCab-Ko WASM provides near-native performance through WebAssembly compilation:

  • Tokenization: ~1-2ms for typical sentences (10-20 words)
  • Memory: ~2-5MB WASM module size (with dictionary)
  • Initialization: ~10-50ms first load (cached afterwards)

Browser Compatibility

  • Chrome/Edge 57+
  • Firefox 52+
  • Safari 11+
  • Node.js 12+

License

Licensed under either of:

  • Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
  • MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)

at your option.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Related Projects

Acknowledgments

This project is based on MeCab-Ko, originally developed by the Eunjeon project.