countingup 0.2.3 → 0.2.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 +3 -2
- package/lib/index.js +11 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -48,8 +48,9 @@ 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,
|
|
51
|
+
myCounter.count(5, countingup.DIRECTION.REVERSE) // 0
|
|
52
52
|
```
|
|
53
|
+
By default it will be forwards (countingup.DIRECTION.FORWARDS)
|
|
53
54
|
|
|
54
55
|
Customizing the Starting Number
|
|
55
56
|
|
|
@@ -58,4 +59,4 @@ const myCounter2 = new Counter(4)
|
|
|
58
59
|
console.log(myCounter2.getCurrentNumber()) // 4
|
|
59
60
|
myCounter2.reset(3)
|
|
60
61
|
console.log(myCounter2.getCurrentNumber()) // 3
|
|
61
|
-
```
|
|
62
|
+
```
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
module.exports =
|
|
1
|
+
module.exports = countingup = {
|
|
2
|
+
DIRECTION: {
|
|
3
|
+
FORWARDS: 'forwards',
|
|
4
|
+
REVERSE: 'reverse'
|
|
5
|
+
},
|
|
2
6
|
Counter: function Counter(base) {
|
|
3
7
|
if (base == null || !Number.isFinite(base)) base = 0
|
|
4
8
|
var counter = base
|
|
@@ -12,25 +16,25 @@ module.exports = mathUtils = {
|
|
|
12
16
|
}
|
|
13
17
|
this.count = function(increment, direction) {
|
|
14
18
|
if (increment == null) increment = 1
|
|
15
|
-
if (direction == null) direction =
|
|
19
|
+
if (direction == null) direction = countingup.DIRECTION.FORWARDS
|
|
16
20
|
if (!Number.isFinite(increment) || !Number.isInteger(increment)) {
|
|
17
21
|
return console.error('Invalid increment')
|
|
18
22
|
}
|
|
19
23
|
switch (direction) {
|
|
20
|
-
case
|
|
24
|
+
case countingup.DIRECTION.FORWARDS: {
|
|
21
25
|
counter += increment
|
|
22
26
|
return
|
|
23
27
|
}
|
|
24
|
-
|
|
25
|
-
case
|
|
28
|
+
|
|
29
|
+
case countingup.DIRECTION.REVERSE: {
|
|
26
30
|
counter -= increment
|
|
27
31
|
return
|
|
28
32
|
}
|
|
29
|
-
|
|
33
|
+
|
|
30
34
|
default: {
|
|
31
35
|
return console.error('Invalid direction')
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
|
-
}
|
|
40
|
+
}
|