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

@harbik/splinefit

v0.4.1

Published

B-spline curve and surface fitting — pure-Rust Dierckx engine with ergonomic API

Readme

splinefit

B-spline curve fitting in WebAssembly. Fit smoothing, interpolating, or cardinal cubic splines to data and evaluate, integrate, or find roots -- all in the browser, with no server required.

Built from a pure-Rust translation of the classic Dierckx FITPACK library (the same engine behind SciPy's splrep/splev).

Installation

npm install @harbik/splinefit

Or use directly from a CDN:

<script type="module">
  import init, { CubicSpline } from "https://esm.sh/@harbik/splinefit";
  await init();
  // ...
</script>

Quick start

import init, { CubicSpline } from "@harbik/splinefit";
await init();

// Sample data: sin(x) on [0, 2pi]
const x = Float64Array.from({ length: 50 }, (_, i) => i * 2 * Math.PI / 49);
const y = x.map(Math.sin);

// Fit a smoothing spline (rms = 0.05)
const spline = CubicSpline.smoothing(x, y, 0.05);

// Evaluate at 200 points
const xNew = Float64Array.from({ length: 200 }, (_, i) => i * 2 * Math.PI / 199);
const yFit = spline.evaluate(xNew); // Float64Array

console.log(yFit[0]);  // ~0.0
console.log(yFit[100]); // ~1.0

API

Constructors

All constructors take Float64Array inputs. x must be strictly increasing and have the same length as y (minimum 4 points).

CubicSpline.smoothing(x, y, rms)

Fit a smoothing spline. rms controls the trade-off between smoothness and closeness of fit: smaller values produce more knots and a tighter fit.

const spline = CubicSpline.smoothing(x, y, 0.05);

CubicSpline.interpolating(x, y)

Fit an interpolating spline that passes exactly through every data point.

const spline = CubicSpline.interpolating(x, y);

CubicSpline.cardinal(x, y, dt)

Fit a spline on a fixed equidistant knot grid with spacing dt.

const spline = CubicSpline.cardinal(x, y, 0.5);

Methods

spline.evaluate(x) -> Float64Array

Evaluate the spline at each value in x.

const yFit = spline.evaluate(new Float64Array([0.5, 1.0, 1.5]));

spline.integral(a, b) -> number

Compute the definite integral of the spline over [a, b].

const area = spline.integral(0, Math.PI); // integral of sin(x) from 0 to pi ~ 2.0

spline.roots() -> Float64Array

Find all interior zeros of the spline, returned in ascending order. Zeros at the domain boundaries may not be included.

const zeros = spline.roots(); // e.g. [3.14159...]

spline.knots() -> Float64Array

Return the knot vector.

console.log(spline.knots()); // Float64Array [0, 0, 0, 0, ..., 6.28, 6.28, 6.28, 6.28]

spline.coefficients() -> Float64Array

Return the B-spline coefficients.

spline.num_knots -> number

Number of knots (getter property, no parentheses).

console.log(spline.num_knots); // e.g. 12

TypeScript

Type definitions (.d.ts) are included automatically. Your editor will provide full autocompletion and type checking.

Examples

Smoothing noisy sensor data

const spline = CubicSpline.smoothing(timestamps, readings, 0.1);
const smooth = spline.evaluate(timestamps);

Finding zero crossings

const spline = CubicSpline.interpolating(x, y);
const crossings = spline.roots();
console.log(`Signal crosses zero at: ${Array.from(crossings).join(", ")}`);

Computing area under a curve

const spline = CubicSpline.interpolating(x, y);
const area = spline.integral(x[0], x[x.length - 1]);
console.log(`Total area: ${area}`);

How it works

This package is compiled from the Rust crate splinefit to WebAssembly using wasm-pack. It runs the same numerical algorithms as SciPy's splrep/splev (Paul Dierckx' FITPACK), translated line-by-line from the original Fortran into Rust.

No server, no network calls, no native dependencies -- the spline fitting runs entirely in your browser or Node.js process.

License

Apache-2.0 OR MIT