Skip to content

ArtskydJ/range-interval

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

range-interval

Like setInterval, but called a configurable number of times.

Build Status

demo

examples

// example/example1.js
var rangeInterval = require('range-interval')

var text = 'hello'
var opts = {
	start: 0,
	step: 1,
	end: text.length-1,
	interval: 200
}

rangeInterval(opts, function (index) {
	console.log(text[index])
})

// h (printed after 200ms)
// e (printed after 400ms)
// l (printed after 600ms)
// l (printed after 800ms)
// o (printed after 1000ms)
// example/example2.js
var rangeInterval = require('range-interval')

var text = '0123456789abcdef'
var str = ''
rangeInterval({
	start: 2,
	step: 3,
	end: text.length-1,
	interval: 200
}, function (index) {
	str += text[index]
}, function () {
	console.log(str)
})
// 258be (printed after 1000ms)

api

var rangeInterval = require('range-interval')

rangeInterval(opts, each[, cb])

The each function is called every opts.interval milliseconds. It is passed a number that starts at opts.start, and steps opts.step closer each iteration, until it gets to opts.end. Then the cb is called.

  • opts is an object of options with the following properties:
    • start is the starting number. Optional, defaults to 0.
    • step is the amount the number is incremented on each iteration. (This can be negative.) Optional, defaults to 1.
    • end is the number at which the loop ends. Required.
    • interval is the number of ms between each iteration. Required.
  • each is a function that is passed the following arguments:
    • number is a number between opts.start and opts.end that is incremented by opts.step each iteration.
  • cb is an optional function that is called after opts.end is reached. No arguments are passed to it.

install

Install using npm

npm install range-interval

license

MIT

About

⏰ Like setInterval, but called a configurable number of times

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published