countingup 0.2.3 → 0.2.5

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.
Files changed (3) hide show
  1. package/README.md +3 -2
  2. package/lib/index.js +39 -30
  3. 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, 'backwards') // 0
51
+ myCounter.count(5, countingup.Counter.DIRECTION.REVERSE) // 0
52
52
  ```
53
+ By default it will be forwards (countingup.Counter.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,36 +1,45 @@
1
- module.exports = mathUtils = {
2
- Counter: function Counter(base) {
1
+ const DIRECTION = {
2
+ FORWARDS: 'forwards',
3
+ REVERSE: 'reverse'
4
+ }
5
+
6
+
7
+ function Counter(base) {
8
+ if (base == null || !Number.isFinite(base)) base = 0
9
+ var counter = base
10
+ this.reset = function(base) {
3
11
  if (base == null || !Number.isFinite(base)) base = 0
4
- var counter = base
5
- this.reset = function(base) {
6
- if (base == null || !Number.isFinite(base)) base = 0
7
- counter = base
8
- return this
9
- }
10
- this.getCurrentNumber = function() {
11
- return counter
12
+ counter = base
13
+ return this
14
+ }
15
+ this.getCurrentNumber = function() {
16
+ return counter
17
+ }
18
+ this.count = function(increment, direction) {
19
+ if (increment == null) increment = 1
20
+ if (direction == null) direction = DIRECTION.FORWARDS
21
+ if (!Number.isFinite(increment) || !Number.isInteger(increment)) {
22
+ return console.error('Invalid increment')
12
23
  }
13
- this.count = function(increment, direction) {
14
- if (increment == null) increment = 1
15
- if (direction == null) direction = 'forwards'
16
- if (!Number.isFinite(increment) || !Number.isInteger(increment)) {
17
- return console.error('Invalid increment')
24
+ switch (direction) {
25
+ case DIRECTION.FORWARDS: {
26
+ counter += increment
27
+ return
28
+ }
29
+
30
+ case DIRECTION.REVERSE: {
31
+ counter -= increment
32
+ return
18
33
  }
19
- switch (direction) {
20
- case 'forwards': {
21
- counter += increment
22
- return
23
- }
24
-
25
- case 'backwards' || 'reverse': {
26
- counter -= increment
27
- return
28
- }
29
-
30
- default: {
31
- return console.error('Invalid direction')
32
- }
34
+
35
+ default: {
36
+ return console.error('Invalid direction')
33
37
  }
34
38
  }
35
39
  }
36
- }
40
+ }
41
+
42
+ Counter.DIRECTION = DIRECTION
43
+ module.exports = countingup = {
44
+ Counter
45
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "countingup",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "description": "Counter Class for JavaScrippt",
5
5
  "main": "index.js",
6
6
  "directories": {