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

backoff-strategies

v1.1.0

Published

Collection of backoff strategies with a common API

Downloads

1,339

Readme

node-backoff-strategies

A genericised set of backoff-suitable algorithms.

Installation

npm install backoff-strategies

General Options

  • minValue (default: 0) - the smallest value that may be returned
  • maxValue (default: Infinity) - the largest value that may be returned
  • multiplier (default: 1) - the scaling factor of the return value
  • randomisationFactor (default: 0) - increase the returned value by a random amount
  • zeroMeansZero (default: true) - overrides all other settings to always return 0 when i=0`
  • i (default: 0) - the initial i value (when using strategy.next() for generation)

General Methods

  • get(i) - returns the computed value for this step according to the strategy
  • next() - returns get(i) for the current i value, then increments i
  • reset() - resets i to zero

Usage

Linear Strategy

A monotonically increasing strategy, e.g. 0,1,2,3,4,5

const Strategies = require('backoff-strategies');

var linearBackoff = new Strategies.Linear();

console.log(linearBackoff.next()); // 0
console.log(linearBackoff.next()); // 1
console.log(linearBackoff.next()); // 2

console.log(linearBackoff.get(6)); // 6

Defined Strategy

A predefined strategy for granular control

const Strategies = require('backoff-strategies');

var definedBackoff = new Strategies.Defined({values: [1, 5, 6, 3]});

console.log(definedBackoff.next()); // 1
console.log(definedBackoff.next()); // 5
console.log(definedBackoff.next()); // 6
console.log(definedBackoff.next()); // 3
console.log(definedBackoff.next()); // 3

console.log(definedBackoff.get(6)); // 3

Fibonnaci Strategy

A strategy increasing according to a Fabonacci sequence (1,1,2,3,5,8,13)

const Strategies = require('backoff-strategies');

var fibonacciBackoff = new Strategies.Fibonacci({zeroMeansZero: false});

console.log(fibonacciBackoff.next()); // 1
console.log(fibonacciBackoff.next()); // 1
console.log(fibonacciBackoff.next()); // 2
console.log(fibonacciBackoff.next()); // 3

console.log(fibonacciBackoff.get(6)); // 13

Exponential Strategy

An exponentially increasing strategy: Math.pow(this.factor, i - 1)

This accepts an additional factor option.

const Strategies = require('backoff-strategies');

var expBackoff = new Strategies.Exponential({
    randomisationFactor: 0.5,
    multiplier: 10,
    maxValue: 300
});

console.log(expBackoff.next()); // 0
console.log(expBackoff.next()); // 13 - between 10 and 15
console.log(expBackoff.next()); // 26 - between 20 and 30
console.log(expBackoff.next()); // 57 - between 40 and 60

console.log(expBackoff.get(5)); // 167 - between 160 and 240

Polynomial Strategy

A polynomially increasing strategy: Math.pow(i, this.factor)

This accepts an additional factor option.

const Strategies = require('backoff-strategies');

var polyBackoff = new Strategies.Polynomial({
    factor: 3
});

console.log(polyBackoff.next()); // 0
console.log(polyBackoff.next()); // 1
console.log(polyBackoff.next()); // 2 * 2 * 2 =8
console.log(polyBackoff.next()); // 3 * 3 * 3 = 27
console.log(polyBackoff.get(5)); // 5 * 5 * 5 = 125