ccounter

Just a simple counter that when comes to the end go back to zero and when go less than zero return to total index

Usage no npm install needed!

<script type="module">
  import ccounter from 'https://cdn.skypack.dev/ccounter';
</script>

README

Counter

Just a simple counter that when comes to the end go back to zero and when go less than zero return to total index

Properties:
index //current index
total //total items
prev //previous index
next //next index

Example:

var totalLength = 3
// Starts from 0, you can specify a start index as second parameter
var counter = Counter(totalLength, startIndex)
counter.inc() // counter = 1
counter.inc() // counter = 2
counter.dec() // counter = 1
counter.dec() // counter = 0
counter.dec() // counter = 2