hysteresis
An implementation of hysteresis in JavaScript
Installation
$ npm install hysteresis
$ bower install littlebits/hysteresis
Example
There are a variety of use-cases for hysteresis. One use-case at littleBits is that we use it to avoid jittery event inference in the cloudBit's data stream.
Here is a naive example:
var Hysteresis = var createServer = createServer var server =
API
Hysteresis
Hysteresis(threshold, config) -> (check(number) -> 0 | 1 | 2)`
Instantiate a hysteresis instance. You must provide a threshold
and may optionally provide a config
object that tweaks behaviour.
config
exposes the following options:
initialSide
– May be1
or0
, defaults tonull
causingside
bootstrapping to be resolved using first receivednumber
initialBias
– May be1
or0
, defaults to1
initialIsChange
– May beBoolean
, defaults totrue
checkType
– May be'crosses'
or'crossesOrMeets'
, defaults to'crossesOrMeets'
The constructor returns a check
function that accepts number
and returns one of the following codes:
check(number) -> 0 | 1 | 2
0
– the number did not cross the threshold1
– the number fell below the threshold2
– the number rose above the threshold
For more details please read the annotated source code and review the tests.