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 🙏

© 2024 – Pkg Stats / Ryan Hefner

thermostat

v1.0.0

Published

Track an infinite curve of values given their inflection points. Or just program a thermostat.

Downloads

6

Readme

Thermostat

Track an infinite curve of values given their inflection points. Or just program a thermostat.

Thermostat represents an infinite function, ƒ(d) = ?, where d is a Date or Number, and ƒ(d) returns a Number, interpolating between all of the points previously added to that function. As I'm not really a math person (honest), I'll show you what I mean with an example.

Imagine the following curve repeats infinitely (each A is the same as the last):

1         C---D
         /     \
0   A---B       A'--

If you query a random point on this curve, it should give you a value between 0 and 1. That said, Thermostat (in an attempt to represent this curve as a function) only cares about A, B, C, and D (and how they repeat).

API

As usual, Thermostat can be included like so:

var thermostat = require('thermostat')

thermostat.lerp(p1, p2, x)

The simple lerp implementation core to the inner-workings of Thermostat, provided for convenience. p1 and p2 are Points (Objects with x and y Numbers), returning the Number result of linearly interpolating between those two points, to x.

curve = thermostat.createCurve(options)

Returns a new Curve instance with the provided options Object. The available options are:

  • period: Optional. The period of the curve. Set to 0 to disable repetition. Defaults to the number of milliseconds in one week.
  • points: Optional. An Array of { "x": Number|Date|String, "y": Number } pairs, each of which represents a single point on the curve at x with the value y. Defaults to the empty set which, while valid, isn't very interesting: each request returns 0.

y = curve(x)

Returns the Number value of the curve at x, represented as a Date, Number, or String.

A note on inputs

All x values can be either Dates, Numbers, or Strings, treated as follows:

  • Number: Used as-is.
  • Date: Coerced to a Number as defined by Date.valueOf()
  • String: Parsed as a Date, then coerced to a Number likewise.