@wizhut_tech/wizjs 0.0.9 → 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.
@@ -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/lang_flow.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # Lang / flow
2
2
 
3
- **Still in development**
3
+ * **if_exception(fn, fn_noexc, fn_exc)**: executes *fn*. if it throws an exception then it calls *fn_exc*, else *fn_noexc*.
@@ -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
@@ -5,6 +5,8 @@ const functools = require('./src/lang/functools.js');
5
5
  const arrays = require('./src/lang/arrays.js');
6
6
  const files = require('./src/io/files.js');
7
7
 
8
+ const { BadlyInitializedError } = require('./src/internal/exceptions.js');
9
+
8
10
 
9
11
  module.exports = {
10
12
  io: {
@@ -18,5 +20,8 @@ module.exports = {
18
20
  },
19
21
  math: {
20
22
  numbers: numbers
23
+ },
24
+ exceptions: {
25
+ BadlyInitializedError
21
26
  }
22
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wizhut_tech/wizjs",
3
- "version": "0.0.9",
3
+ "version": "0.1.0",
4
4
  "main": "index.js",
5
5
  "devDependencies": {
6
6
  "tap": "21.1.0"
package/readme.md CHANGED
@@ -14,6 +14,7 @@ Use by importing:
14
14
  lang: {
15
15
  arrays: [functions],
16
16
  checks: [functions],
17
+ flow: [functions],
17
18
  singleton: [functions],
18
19
  functools: [functions]
19
20
  },
@@ -23,7 +24,7 @@ Use by importing:
23
24
  }
24
25
  ```
25
26
 
26
- You can also import individual functions like the following:
27
+ You can also import individual functions like the following snippet:
27
28
 
28
29
  `const { lang: { checks : { isNil } } } = require('@wizhut_tech/wizjs');`
29
30
 
@@ -35,8 +36,9 @@ You can also import individual functions like the following:
35
36
 
36
37
  * **Arrays** utility functions ... [[docs](docs/lang_arrays.md)]
37
38
  * **Check** utility functions ... [[docs](docs/lang_checks.md)]
38
- * Control-**Flow** utilities ... [[docs](docs/lang_flow.md)] -- *still in development* --
39
+ * Control-**Flow** utilities ... [[docs](docs/lang_flow.md)]
39
40
  * **functools** ... [[docs](docs/lang_functools.md)]
41
+ * **itertools** ... [[docs](docs/lang_itertools.md)]
40
42
  * **Singleton** hack ... [[docs](docs/lang_singleton.md)]
41
43
 
42
44
  ### Math
@@ -0,0 +1,12 @@
1
+
2
+
3
+ class BadlyInitializedError extends Error {
4
+ constructor(message, ...args) {
5
+ super(message);
6
+ }
7
+ }
8
+
9
+
10
+ module.exports = {
11
+ BadlyInitializedError
12
+ };
package/src/lang/flow.js CHANGED
@@ -1,17 +1,15 @@
1
1
 
2
2
 
3
- class TransactionItem {
4
- constructor(task, fallback) {
5
- this.task = task;
6
- this.fallback = fallback;
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
+ };