countingup 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -48,7 +48,7 @@ This allows you to change the direction so it counts down and subtracts
48
48
  myCounter.reset()
49
49
  myCounter.count(5)
50
50
  console.log(myCounter.getCurrentNumber()) // 5
51
- myCounter.count(5, 'reverse') // 0
51
+ myCounter.count(5, 'backwards') // 0
52
52
  ```
53
53
 
54
54
  Customizing the Starting Number
package/lib/index.js CHANGED
@@ -477,5 +477,38 @@ module.exports = mathUtils = {
477
477
  else return number - (number * 2)
478
478
  }
479
479
  },
480
- Counter: require('./Counter')
480
+ Counter: function Counter(base) {
481
+ if (base == null || !Number.isFinite(base)) base = 0
482
+ var counter = base
483
+ this.reset = function(base) {
484
+ if (base == null || !Number.isFinite(base)) base = 0
485
+ counter = base
486
+ return this
487
+ }
488
+ this.getCurrentNumber = function() {
489
+ return counter
490
+ }
491
+ this.count = function(increment, direction) {
492
+ if (increment == null) increment = 1
493
+ if (direction == null) direction = 'forwards'
494
+ if (!Number.isFinite(increment) || !Number.isInteger(increment)) {
495
+ return console.error('Invalid increment')
496
+ }
497
+ switch (direction) {
498
+ case 'forwards': {
499
+ counter += increment
500
+ return
501
+ }
502
+
503
+ case 'backwards' || 'reverse': {
504
+ counter -= increment
505
+ return
506
+ }
507
+
508
+ default: {
509
+ return console.error('Invalid direction')
510
+ }
511
+ }
512
+ }
513
+ }
481
514
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "countingup",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Math Utils for JavaScript",
5
5
  "main": "index.js",
6
6
  "directories": {