while2 1.0.0 → 2.0.0

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
@@ -1,47 +1,32 @@
1
- # While2
1
+ # `while2`
2
+ `while2` is a while statement, but 10x and function-oriented. Also, it includes a built-in index value.
2
3
 
3
- ### What is while2
4
- While2 is while statements, but different syntax. Also it includes a built-in index value.
5
-
6
- ```javascript
7
- const w2 = require('./lib/while2')
8
-
9
- new w2(true)
10
- .do((i, breakLoop) => {
11
- if (i > 3) breakLoop() // prints 0, 1, 2, 3 then stops
12
- console.log(i)
13
- })
14
- .end()
4
+ ## Installation
5
+ ```bash
6
+ $ npm install while2
15
7
  ```
16
- ### Installation
17
8
 
18
- ```npm install while2```
9
+ ## Usage
19
10
 
20
- ```javascript
21
- const w2 = require('while2')
22
- ```
23
-
24
- ### Syntax
25
-
26
- To use while2, first import the module. It is recommended to call it "w2".
11
+ To use while2, first import the module. It is recommended to call it `w2`.
27
12
 
28
13
  ```javascript
29
14
  const w2 = require('while2')
30
15
  ```
31
16
 
32
- For every while2 statement, you will create a new instance of w2, as it is a class, and pass a condition, and for everything that you want to run while the condition is true, put .do() and then pass in a function in the parentheses. Always type .end() at the end to run the while loop in the background.
17
+ For every while2 statement, you will create a new instance of `w2`, as it is a class, and pass a condition. For everything that you want to run while the condition is true, put `.do(...)` and then pass in a function in the parentheses. Always type `.end()`at the end to run the while loop or it won't work
33
18
 
34
19
  ```javascript
35
20
  const w2 = require('while2')
36
21
 
37
- new w2(true)
22
+ new w2(true) // equivalent to while (true)
38
23
  .do(() => {
39
24
  // anything here will run again and again forever
40
25
  })
41
26
  .end() // this line makes sure that the while loop is ran in the background. if you don't include this nothing will happen
42
27
  ```
43
28
 
44
- ### Features: Builtin Index
29
+ ### Built-in index
45
30
 
46
31
  While2 includes an i parameter that will automatically increment every time the do function is run.
47
32
 
@@ -55,12 +40,12 @@ new w2(true)
55
40
  .end()
56
41
  ```
57
42
 
58
- ### Features: BreakLoop Function
43
+ ### Breaking the loop
59
44
 
60
- While2 includes a breakLoop parameter function so that you can break your while loop.
45
+ While2 includes a `breakLoop` parameter function so that you can break your while loop.
61
46
 
62
47
  ```javascript
63
- const w2 = require('./lib/while2')
48
+ const w2 = require('while2')
64
49
 
65
50
  new w2(true)
66
51
  .do((i, breakLoop) => {
@@ -68,4 +53,7 @@ new w2(true)
68
53
  console.log(i)
69
54
  })
70
55
  .end()
71
- ```
56
+ ```
57
+
58
+ ## License
59
+ No license, do whatever you want
package/index.js CHANGED
@@ -1 +1,32 @@
1
- module.exports = require('./lib/while2')
1
+ const breakError = {}
2
+
3
+ class w2 {
4
+ constructor(condition) {
5
+ if (!this instanceof w2) return new w2()
6
+ this.condition = condition
7
+ this.i = 0
8
+ return this
9
+ }
10
+ do(cb) {
11
+ this.doHandler = cb
12
+ return this
13
+ }
14
+ end() {
15
+ try {
16
+ while (this.condition) {
17
+ this.doHandler(this.i, () => {
18
+ throw breakError
19
+ }) // pass in the function to break the loop
20
+ this.i += 1
21
+ }
22
+ } catch(err) {
23
+ if (err === breakError) return
24
+
25
+ throw err
26
+ }
27
+ }
28
+ }
29
+
30
+
31
+
32
+ module.exports = w2
package/package.json CHANGED
@@ -1,14 +1,29 @@
1
1
  {
2
2
  "name": "while2",
3
- "version": "1.0.0",
4
- "description": "for when while loops aren't verbose enoughs",
3
+ "version": "2.0.0",
4
+ "description": "10x while loop",
5
+ "keywords": [
6
+ "while",
7
+ "while2",
8
+ "declaration",
9
+ "statement"
10
+ ],
11
+ "homepage": "https://github.com/10xEngineersQualityProgramming/while2#readme",
12
+ "bugs": {
13
+ "url": "https://github.com/10xEngineersQualityProgramming/while2/issues"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/10xEngineersQualityProgramming/while2.git"
18
+ },
19
+ "license": "UNLICENSED",
20
+ "author": "me",
21
+ "type": "commonjs",
5
22
  "main": "index.js",
6
23
  "directories": {
7
24
  "lib": "lib"
8
25
  },
9
26
  "scripts": {
10
27
  "test": "echo \"Error: no test specified\" && exit 1"
11
- },
12
- "author": "me",
13
- "license": "UNLICENSED"
28
+ }
14
29
  }
package/lib/while2.js DELETED
@@ -1,32 +0,0 @@
1
- const breakError = {}
2
-
3
- class w2 {
4
- constructor(condition) {
5
- if (!this instanceof w2) return new w2()
6
- this.condition = condition
7
- this.i = 0
8
- return this
9
- }
10
- do(cb) {
11
- this.doHandler = cb
12
- return this
13
- }
14
- end() {
15
- try {
16
- while (this.condition) {
17
- this.doHandler(this.i, () => {
18
- throw breakError
19
- }) // pass in the function to break the loop
20
- this.i += 1
21
- }
22
- } catch(err) {
23
- if (err === breakError) return
24
-
25
- throw err
26
- }
27
- }
28
- }
29
-
30
-
31
-
32
- module.exports = w2
package/test.js DELETED
@@ -1,7 +0,0 @@
1
- const w2 = require('./lib/while2')
2
- new w2(true)
3
- .do((i, breakLoop) => {
4
- if (i > 3) breakLoop()
5
- console.log(i)
6
- })
7
- .end()