JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 615
  • Score
    100M100P100Q112078F
  • License UNLICENSED

Counter Class for JavaScrippt

Package Exports

  • countingup
  • countingup/index.js
  • countingup/lib

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (countingup) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Countingup

Countingup is a library that provides a Counter class to count up and down with customizations.

Installation

Using npm:

$ npm install countingup

In Node.js

const countingup = require('countingup')

Counter class

The Counter class provides a tool to count numbers.

Initializing

const Counter = countingup.Counter
const myCounter = new Counter()

Counting

myCounter.count()
console.log(myCounter.getCurrentNumber()) // 1

Resetting

myCounter.reset()
console.log(myCounter.getCurrentNumber()) // 0

Bonus Features

Customizing the Increment

myCounter.count()
console.log(myCounter.getCurrentNumber()) // 1
myCounter.count(3)
console.log(myCounter.getCurrentNumber()) // 4

Customizing the Direction

This allows you to change the direction so it counts down and subtracts

myCounter.reset()
myCounter.count(5)
console.log(myCounter.getCurrentNumber()) // 5
myCounter.count(5, 'backwards') // 0

Customizing the Starting Number

const myCounter2 = new Counter(4)
console.log(myCounter2.getCurrentNumber()) // 4
myCounter2.reset(3)
console.log(myCounter2.getCurrentNumber()) // 3