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

ml-handler

v1.0.0

Published

A promise-based ML inference library for the browser

Readme

ml-axios

A promise-based Machine Learning inference library for the browser, inspired by the simplicity of Axios. Built on top of TensorFlow.js.

Features

  • 🚀 Promise-based API: Familiar syntax for developers used to Axios.
  • 🔄 Interceptors: Powerful request and response interceptors for pre-processing inputs and post-processing predictions.
  • 🧠 Smart Model Loading: Automatically detects and loads both Graph and Layers models (including support for TFHub).
  • 🖼️ Automatic Input Handling: seamless conversion from HTML images/video elements to Tensors.
  • 🧹 Memory Management: Automatic tensor disposal to prevent memory leaks.
  • ⏱️ Performance Metrics: Returns inference latency and backend device information.

Installation

npm install ml-axios @tensorflow/tfjs

Usage

Basic Inference

import ml from 'ml-axios';

async function runInference() {
  // 1. Load a model (e.g., MobileNet from TFHub)
  const modelUrl = 'https://tfhub.dev/google/tfjs-model/imagenet/mobilenet_v2_100_224/classification/3/default/1';
  const model = await ml.load(modelUrl);

  // 2. Get your input (e.g., an image element)
  const imgElement = document.getElementById('my-image');

  // 3. Predict
  const response = await ml.predict(model, imgElement);

  console.log('Prediction Data:', response.data);
  console.log('Latency:', response.latency, 'ms');
  console.log('Device:', response.device);
}

runInference();

Creating Custom Instances

You can create independent instances with their own configuration and interceptors.

import { create } from 'ml-axios';

const customMl = create({
  // custom config
});

customMl.interceptors.request.push(...);

Using Interceptors

You can use interceptors to transform data before it reaches the model (Request Interceptors) or after the model returns a prediction (Response Interceptors).

import ml from 'ml-axios';

// Request Interceptor: Pre-process input
ml.interceptors.request.push(async (input) => {
  console.log('Pre-processing input...');
  // Perform operations like resizing, normalization, etc.
  return input;
});

// Response Interceptor: Post-process prediction
ml.interceptors.response.push(async (prediction) => {
  console.log('Post-processing prediction...');
  // Convert tensor to array, filter results, etc.
  const values = await prediction.data();
  return values;
});

API

ml.load(modelUrl: string)

Loads a TensorFlow.js model. It attempts to load as a GraphModel first (common for TFHub), and falls back to a LayersModel.

  • modelUrl: The URL of the model.
  • Returns: A Promise that resolves to the loaded model.

ml.predict(model: any, input: any)

Runs inference on the provided input using the loaded model.

  • model: The loaded TensorFlow.js model.
  • input: The input data (HTMLImageElement, HTMLVideoElement, Tensor, etc.).
  • Returns: A Promise resolving to an object containing:
    • data: The prediction result (Tensor or processed data).
    • latency: Time taken for inference in milliseconds.
    • device: The active TensorFlow backend (e.g., 'webgl', 'cpu').

ml.interceptors

  • request: Array of functions to transform input before inference.
  • response: Array of functions to transform output after inference.

Development

  1. Clone the repository
  2. Install dependencies:
    npm install
  3. Start development server:
    npm run dev
  4. Build for production:
    npm run build

License

MIT