1.1.0 • Published 2 years ago

kinetic-value v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

kinetic-value

Tiny and performant class for tracking the instantaneous velocity of a continuously changing value.

Install

npm install kinetic-value

Usage

import KineticValue from "kinetic-value";

// Create a kinetic value
const kv = new KineticValue(0);

setInterval(() => {
  // Increment by 10 every 20ms
  kv.set(kv.get() + 50);

  // Velocity will be about 500
  console.log(kv.velocity());
}, 20);

API Reference

new KineticValue(initialValue: number, timeout?: number, now?: number)

Creates a new kinetic value.

timeout is the number of milliseconds to wait until the value is considered stopped. Default 50.

get()

Returns the current tracked value.

set(value: number, now?: number)

Updates the tracked value.

velocity(now?: number)

Returns the instantaneous velocity of the tracked value in units / second.

stop()

Resets the velocity to 0.

Author

1.1.0

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago