@wizhut_tech/wizjs 0.0.8 → 0.1.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/__tests__/lang_itertools.test.js +21 -0
- package/docs/io_files.md +3 -0
- package/docs/lang_flow.md +1 -1
- package/docs/lang_itertools.md +4 -0
- package/index.js +9 -0
- package/package.json +2 -2
- package/readme.md +14 -1
- package/src/internal/exceptions.js +12 -0
- package/src/io/files.js +15 -0
- package/src/lang/flow.js +7 -9
- package/src/lang/itertools.js +25 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const t = require('tap');
|
|
2
|
+
|
|
3
|
+
const { cycle, fn_cycle } = require('../src/lang/itertools.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
t.test('itertools/cycle', (t) => {
|
|
7
|
+
// simple integer
|
|
8
|
+
const genOne = cycle(0, 1);
|
|
9
|
+
t.equal(genOne.next().value, 0);
|
|
10
|
+
t.equal(genOne.next().value, 1);
|
|
11
|
+
t.equal(genOne.next().value, 2);
|
|
12
|
+
|
|
13
|
+
// simple floating-point
|
|
14
|
+
const genTwo = cycle(0, 0.5);
|
|
15
|
+
t.equal(genTwo.next().value, 0);
|
|
16
|
+
t.equal(genTwo.next().value, 0.5);
|
|
17
|
+
t.equal(genTwo.next().value, 1);
|
|
18
|
+
t.equal(genTwo.next().value, 1.5);
|
|
19
|
+
|
|
20
|
+
t.end();
|
|
21
|
+
});
|
package/docs/io_files.md
ADDED
package/docs/lang_flow.md
CHANGED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
# Lang / itertools
|
|
2
|
+
|
|
3
|
+
* **cycle(start, step=1)**: A generator that counts from *start* with a specified *step*. Default stepping is *1*.
|
|
4
|
+
* **fn_cycle(start, step=1, fn)**: A generator that counts from *start* with a specified *step*. Default stepping is *1*. For each iteration the *fn* is called. To continue to the next iteration, the *fn* should return *true*. If not the iteration breaks,.
|
package/index.js
CHANGED
|
@@ -3,9 +3,15 @@ const checks = require('./src/lang/checks.js');
|
|
|
3
3
|
const numbers = require('./src/math/numbers.js');
|
|
4
4
|
const functools = require('./src/lang/functools.js');
|
|
5
5
|
const arrays = require('./src/lang/arrays.js');
|
|
6
|
+
const files = require('./src/io/files.js');
|
|
7
|
+
|
|
8
|
+
const { BadlyInitializedError } = require('./src/internal/exceptions.js');
|
|
6
9
|
|
|
7
10
|
|
|
8
11
|
module.exports = {
|
|
12
|
+
io: {
|
|
13
|
+
files: files,
|
|
14
|
+
},
|
|
9
15
|
lang: {
|
|
10
16
|
arrays: arrays,
|
|
11
17
|
singleton: singleton,
|
|
@@ -14,5 +20,8 @@ module.exports = {
|
|
|
14
20
|
},
|
|
15
21
|
math: {
|
|
16
22
|
numbers: numbers
|
|
23
|
+
},
|
|
24
|
+
exceptions: {
|
|
25
|
+
BadlyInitializedError
|
|
17
26
|
}
|
|
18
27
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -8,9 +8,13 @@ Use by importing:
|
|
|
8
8
|
|
|
9
9
|
```
|
|
10
10
|
{
|
|
11
|
+
io: {
|
|
12
|
+
files: [functions]
|
|
13
|
+
},
|
|
11
14
|
lang: {
|
|
12
15
|
arrays: [functions],
|
|
13
16
|
checks: [functions],
|
|
17
|
+
flow: [functions],
|
|
14
18
|
singleton: [functions],
|
|
15
19
|
functools: [functions]
|
|
16
20
|
},
|
|
@@ -20,12 +24,21 @@ Use by importing:
|
|
|
20
24
|
}
|
|
21
25
|
```
|
|
22
26
|
|
|
27
|
+
You can also import individual functions like the following snippet:
|
|
28
|
+
|
|
29
|
+
`const { lang: { checks : { isNil } } } = require('@wizhut_tech/wizjs');`
|
|
30
|
+
|
|
31
|
+
### I/O
|
|
32
|
+
|
|
33
|
+
* **Files** utility functions ... [[docs](docs/io_files.md)]
|
|
34
|
+
|
|
23
35
|
### Language
|
|
24
36
|
|
|
25
37
|
* **Arrays** utility functions ... [[docs](docs/lang_arrays.md)]
|
|
26
38
|
* **Check** utility functions ... [[docs](docs/lang_checks.md)]
|
|
27
|
-
* Control-**Flow** utilities ... [[docs](docs/lang_flow.md)]
|
|
39
|
+
* Control-**Flow** utilities ... [[docs](docs/lang_flow.md)]
|
|
28
40
|
* **functools** ... [[docs](docs/lang_functools.md)]
|
|
41
|
+
* **itertools** ... [[docs](docs/lang_itertools.md)]
|
|
29
42
|
* **Singleton** hack ... [[docs](docs/lang_singleton.md)]
|
|
30
43
|
|
|
31
44
|
### Math
|
package/src/io/files.js
ADDED
package/src/lang/flow.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
async execute() {
|
|
10
|
-
|
|
3
|
+
function if_exception(fn, fn_noexc, fn_exc) {
|
|
4
|
+
try {
|
|
5
|
+
fn();
|
|
6
|
+
fn_noexc();
|
|
7
|
+
} catch (error) {
|
|
8
|
+
fn_exc(error);
|
|
11
9
|
}
|
|
12
10
|
}
|
|
13
11
|
|
|
14
12
|
|
|
15
13
|
module.exports = {
|
|
16
|
-
|
|
14
|
+
if_exception
|
|
17
15
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
|
|
2
|
+
const {toInteger} = require("../math/numbers");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function* cycle(start=0, step=1) {
|
|
6
|
+
let iCount = toInteger(start);
|
|
7
|
+
const iStep = toInteger(step);
|
|
8
|
+
|
|
9
|
+
while (true) {
|
|
10
|
+
yield iCount;
|
|
11
|
+
iCount += step;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function fn_cycle(start, fn, step=1) {
|
|
16
|
+
const cycleGenerator = cycle(start, step);
|
|
17
|
+
|
|
18
|
+
while (fn(cycleGenerator.next().value)) { }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
cycle,
|
|
24
|
+
fn_cycle
|
|
25
|
+
};
|