2.0.1 • Published 10 years ago

range-interval v2.0.1

Weekly downloads
26
License
MIT
Repository
github
Last release
10 years ago

range-interval

Like setInterval, but called a configurable number of times.

Build Status

demo

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

2.0.1

10 years ago

2.0.0

10 years ago

1.0.0

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago

0.0.1

10 years ago