@wizhut_tech/wizjs 0.0.9 → 0.1.1

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
@@ -4,6 +4,10 @@ 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
6
  const files = require('./src/io/files.js');
7
+ const flow = require('./src/lang/flow.js');
8
+ const itertools = require('./src/lang/itertools.js');
9
+
10
+ const { BadlyInitializedError } = require('./src/internal/exceptions.js');
7
11
 
8
12
 
9
13
  module.exports = {
@@ -13,10 +17,15 @@ module.exports = {
13
17
  lang: {
14
18
  arrays: arrays,
15
19
  singleton: singleton,
20
+ flow: flow,
16
21
  checks: checks,
17
- functools: functools
22
+ functools: functools,
23
+ itertools: itertools
18
24
  },
19
25
  math: {
20
26
  numbers: numbers
27
+ },
28
+ exceptions: {
29
+ BadlyInitializedError
21
30
  }
22
31
  }
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.1",
4
4
  "main": "index.js",
5
5
  "devDependencies": {
6
6
  "tap": "21.1.0"
package/readme.md CHANGED
@@ -14,8 +14,10 @@ Use by importing:
14
14
  lang: {
15
15
  arrays: [functions],
16
16
  checks: [functions],
17
+ flow: [functions],
17
18
  singleton: [functions],
18
- functools: [functions]
19
+ functools: [functions],
20
+ itertools: [functions]
19
21
  },
20
22
  math: {
21
23
  numbers: [functions]
@@ -23,7 +25,7 @@ Use by importing:
23
25
  }
24
26
  ```
25
27
 
26
- You can also import individual functions like the following:
28
+ You can also import individual functions like the following snippet:
27
29
 
28
30
  `const { lang: { checks : { isNil } } } = require('@wizhut_tech/wizjs');`
29
31
 
@@ -35,10 +37,15 @@ You can also import individual functions like the following:
35
37
 
36
38
  * **Arrays** utility functions ... [[docs](docs/lang_arrays.md)]
37
39
  * **Check** utility functions ... [[docs](docs/lang_checks.md)]
38
- * Control-**Flow** utilities ... [[docs](docs/lang_flow.md)] -- *still in development* --
40
+ * Control-**Flow** utilities ... [[docs](docs/lang_flow.md)]
39
41
  * **functools** ... [[docs](docs/lang_functools.md)]
42
+ * **itertools** ... [[docs](docs/lang_itertools.md)]
40
43
  * **Singleton** hack ... [[docs](docs/lang_singleton.md)]
41
44
 
42
45
  ### Math
43
46
 
44
47
  * Utilities around **numbers** ... [[docs](docs/math_numbers.md)]
48
+
49
+ ## Contact
50
+
51
+ This library is actively developed and maintained by [wizhut.tech](http://wizhut.tech)
@@ -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
+ };