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

ts-classify

v0.2.0

Published

Fast text classification with SVM and Nearest Centroid (WebAssembly)

Readme

ts-classify

Fast text classification via SVM, compiled to WebAssembly.

Features

  • Sparse vectors - efficient for high-dimensional data (text, trigrams)
  • Binary serialization - train once, load instantly
  • Written in Rust, compiled to WASM for near-native performance in the browser

Installation

npm install ts-classify

Classifiers

All classifiers use the same sparse data format: flat Float64Array of [index, value, index, value, ...] pairs.

import init, { JsOneVsRestSVM, JsMulticlassSVM, JsNearestCentroid, JsSVM } from 'ts-classify';

await init();

JsOneVsRestSVM

Multiclass SVM using one-vs-rest strategy. Trains K classifiers for K classes. Best for large numbers of classes.

const svm = new JsOneVsRestSVM();
svm.train(samplesFlat, sampleLengths, labels);
const prediction = svm.predict(sampleFlat);
const margins = svm.margins(sampleFlat); // [class0, margin0, class1, margin1, ...]

JsMulticlassSVM

Multiclass SVM using one-vs-one strategy. Trains K(K-1)/2 classifiers, predicts by voting. Often more accurate for smaller numbers of classes.

const svm = new JsMulticlassSVM();
svm.train(samplesFlat, sampleLengths, labels);
const prediction = svm.predict(sampleFlat);

JsNearestCentroid

Computes the centroid of each class and predicts by cosine similarity. Very fast to train, no hyperparameters.

const nc = new JsNearestCentroid();
nc.train(samplesFlat, sampleLengths, labels);
const prediction = nc.predict(sampleFlat);
const similarities = nc.margins(sampleFlat); // [class0, sim0, class1, sim1, ...]

JsSVM

Binary SVM for two-class problems. Labels are -1.0 or 1.0.

const svm = new JsSVM();
svm.train(samplesFlat, sampleLengths, labels); // labels: Float64Array of -1.0/1.0
const prediction = svm.predict(sampleFlat);     // returns -1.0 or 1.0
const margin = svm.margin(sampleFlat);           // raw decision value

Data format

// Flat sparse format: [idx, val, idx, val, ...]
const samplesFlat = new Float64Array([
    0, -2.0, 1, 0.0,  // sample 0: 2 pairs
    0, 1.0, 1, 1.0,   // sample 1: 2 pairs
]);
const sampleLengths = new Uint32Array([2, 2]);  // pairs per sample
const labels = new Int32Array([0, 1]);           // class IDs (or Float64Array for JsSVM)

Serialization

All classifiers support binary serialization:

const bytes = svm.to_bytes();
const loaded = JsOneVsRestSVM.from_bytes(bytes);

Performance

Scaling (coordinate descent, OvR):

| Classes | Classifiers | Train | Predict | |---------|-------------|-------|---------| | 10 | 10 | 511µs | 144ns | | 50 | 50 | 560µs | 743ns | | 100 | 100 | 1.4ms | 1.6µs | | 5000 | 5000 | ~50-100ms | ~80µs |

Building from source

Requires Rust and wasm-pack.

wasm-pack build --target web --no-default-features

Run tests (native):

cargo test --release

License

MIT