1.0.7 • Published 7 years ago

recounter v1.0.7

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

recounter - Recursion Counter

A simple utility wrapper for recursive functions, adding a callCount key and clearCallCount() method. Requires reassigning the original function, so it's mostly useful for testing.

Use like this:

const recounter = require('recounter')

function countDownToZero(number){
  if(number < 1){
    console.log('Done!')
    return 0
  }
  console.log(number)
  number--
  return countDownToZero(number)
}

countDownToZero = recounter(countDownToZero)

countDownToZero(10)
console.log(countDownToZero.callCount) // -> 11

//set the call count to 0
countDownToZero.clearCallCount()
console.log(countDownToZero.callCount) // -> 0

//revert the function back to the original version
countDownToZero = countDownToZero.restore()
console.log(countDownToZero.callCount) // -> undefined
1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago