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