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

@wlearn/core

v0.2.0

Published

Runtime core for wlearn: matrix helpers, bundle format, registry, pipeline

Readme

@wlearn/core

Runtime core for wlearn: matrix helpers, bundle format, model registry, pipeline, preprocessing, metrics, and cross-validation. No WASM. No heavy dependencies.

Part of wlearn (GitHub, all packages).

Install

npm install @wlearn/core

Quick start

const { Pipeline, load, accuracy, crossValScore } = require('@wlearn/core')
const { LinearModel } = require('@wlearn/liblinear')

// Build a pipeline
const model = await LinearModel.create({ task: 'classification' })
const pipe = new Pipeline([['clf', model]])

pipe.fit(X, y)
const preds = pipe.predict(X_test)
console.log('accuracy:', accuracy(y_test, preds))

// Save / load
const bytes = pipe.save()
const restored = await load(bytes)

pipe.dispose()

API

Matrix utilities

Convert user input to typed arrays for WASM consumption.

  • normalizeX(X) -- number[][] | DenseMatrix to contiguous DenseMatrix
  • normalizeY(y) -- number[] | TypedArray to Float64Array
  • makeDense(data, rows, cols) -- create DenseMatrix from typed array
  • validateMatrix(m) -- validate matrix structure and dimensions

Bundle format

Portable binary format for model artifacts. Language-agnostic, deterministic.

  • encodeBundle(manifest, artifacts) -- encode to Uint8Array
  • decodeBundle(bytes) -- decode to { manifest, toc, blobs }
  • validateBundle(bytes) -- decode + verify SHA-256 hashes

Artifacts are { id, mediaType?, data: Uint8Array } objects. The manifest includes typeId, params, and metadata. See @wlearn/types for full shapes.

Registry

Global loader dispatcher. Model packages register themselves on import.

  • register(typeId, loaderFn) -- register a deserializer
  • load(bytes) -- async: decode bundle, dispatch to registered loader
  • loadSync(bytes) -- sync variant (limited to sync loaders)
  • getRegistry() -- inspect registered loaders

Pipeline

Sequential composition of transformers and estimators.

  • new Pipeline(steps) -- steps is [name, estimator][]
  • pipe.fit(X, y) -- fit all steps in order
  • pipe.predict(X) -- transform + predict
  • pipe.score(X, y) -- transform + score
  • pipe.save() / Pipeline.load(bytes) -- serialize/deserialize
  • pipe.dispose() -- dispose all steps

Preprocessing

  • StandardScaler -- zero mean, unit variance
  • MinMaxScaler -- scale to [0, 1]
  • Preprocessor -- base transformer class

Metrics

Classification: accuracy, confusionMatrix, precisionScore, recallScore, f1Score, logLoss, rocAuc

Regression: r2Score, meanSquaredError, meanAbsoluteError

const { accuracy, f1Score, r2Score } = require('@wlearn/core')

accuracy(yTrue, yPred)                        // number
f1Score(yTrue, yPred, { average: 'macro' })   // number
r2Score(yTrue, yPred)                         // number

Cross-validation

  • kFold(n, k?, opts?) -- k-fold split indices
  • stratifiedKFold(y, k?, opts?) -- stratified k-fold
  • trainTestSplit(n, opts?) -- single train/test split
  • crossValScore(ModelClass, X, y, opts?) -- evaluate with CV
  • getScorer(name) -- get scoring function by name ('accuracy', 'r2', 'neg_mse')

createModelClass

Factory for building unified model classes from separate classifier/regressor implementations. Handles automatic task detection, async WASM pre-loading, and lifecycle management.

const { createModelClass } = require('@wlearn/core')

// Task-agnostic model (same class handles both tasks)
const XGBModel = createModelClass(XGBModelImpl, XGBModelImpl, {
  name: 'XGBModel',
  load: loadXGB   // async WASM loader, called in create()
})

// Split model (separate classifier/regressor classes)
const MLPModel = createModelClass(MLPClassifier, MLPRegressor, {
  name: 'MLPModel'
})

The returned class supports:

  • Model.create(params) -- async factory. Pass task: 'classification' or task: 'regression' to select explicitly, or omit to auto-detect from y at fit() time.
  • model.fit(X, y) -- trains the model. Auto-detects task from labels if not set.
  • model.predict(X), model.predictProba(X), model.score(X, y) -- proxied to inner model.
  • model.save() / Model.load(bytes) -- serialize/deserialize.
  • model.dispose() -- free resources.
  • model.task -- the detected or specified task.
  • Extra methods and getters from the inner classes are discovered and proxied automatically.

Auto-detection rules: if y is Int32Array, task is classification. Otherwise, if any value is non-integer, task is regression. If all values are integers and there are 20 or fewer unique values, task is classification; otherwise regression.

Errors

WlearnError, BundleError, RegistryError, ValidationError, NotFittedError, DisposedError

Utilities

  • sha256Sync(data) -- pure JS SHA-256
  • makeLCG(seed?) -- deterministic LCG random number generator
  • shuffle(arr, rng) -- in-place shuffle
  • isPromiseLike(x) / lift(x, fn) -- MaybePromise utilities

License

MIT