@wizhut_tech/wizjs 0.0.2 → 0.0.4

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.
@@ -1,7 +1,7 @@
1
1
  const t = require('tap');
2
2
 
3
3
 
4
- const { getInstance, addSingleton } = require('../src/lang/singleton.js');
4
+ const { getInstance, singleton } = require('../src/lang/singleton.js');
5
5
 
6
6
 
7
7
  t.test('singleton/null-test', async (t) => {
@@ -12,11 +12,11 @@ t.test('singleton/null-test', async (t) => {
12
12
 
13
13
  t.test('singleton/simple-tests', async (t) => {
14
14
  // numbers
15
- addSingleton('number-wrapper', async () => 1);
15
+ singleton('number-wrapper', async () => 1);
16
16
  t.equal(await getInstance('number-wrapper'), 1)
17
17
 
18
18
  // null
19
- addSingleton('null-wrapper', async () => null);
19
+ singleton('null-wrapper', async () => null);
20
20
  t.equal(await getInstance('null-wrapper'), null);
21
21
 
22
22
  t.end();
@@ -0,0 +1,5 @@
1
+ # Lang / Checks
2
+
3
+ Import as `require('wizjs/lang/checks.js')`.
4
+
5
+ * **isNil(arg)**: Check if the `arg` is `undefined` or `null` and returns `true` (or `false` otherwise).
@@ -0,0 +1,3 @@
1
+ # Lang / flow
2
+
3
+ **Still in development**
@@ -0,0 +1,10 @@
1
+ # Lang / Singleton
2
+
3
+ Import with `require('wizjs/lang/singleton.js')`. In-memory caching of an async function's result, ensuring that it will be called only once.
4
+
5
+ Mimics similar python decorators. It can easily, be used to store class instance variables.
6
+
7
+ ### Module API
8
+
9
+ * **singleton(name, fn)**: register an `async` function (`fn`) by name.
10
+ * **getInstance(name)**: returns the instance for a specific `name`. Note that the `fn` is executed only when this method is called.
@@ -0,0 +1,5 @@
1
+ # Math / Numbers
2
+
3
+ Import as `require('wizjs/math/numbers.js')`.
4
+
5
+ * **toInteger(arg)**: Attempts to convert `arg` to `Integer`. Return `0` if the arg is `zero` or invalid value.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wizhut_tech/wizjs",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "main": "index.js",
5
5
  "devDependencies": {
6
6
  "tap": "21.0.1"
package/readme.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Wizjs
2
2
 
3
- A Javascript library (a few selected dependencies only) that contains utilities for enjoy-full every day programming.
3
+ A Javascript library (a few selected dependencies only) that contains utilities for enjoy-full every day programming. No, this library will not become another `lodash` :).
4
4
 
5
- ## Usage
5
+ ### Language
6
+
7
+ * Checks ... [documentation](docs/lang_checks.md)
8
+ * Flow ... [documentation](docs/lang_flow.md)
9
+ * Singleton ... [documentation](docs/lang_singleton.md)
10
+
11
+ ### Math
12
+
13
+ * Numbers ... [documentation](docs/math_numbers.md)
@@ -0,0 +1,17 @@
1
+
2
+
3
+ class TransactionItem {
4
+ constructor(task, fallback) {
5
+ this.task = task;
6
+ this.fallback = fallback;
7
+ }
8
+
9
+ async execute() {
10
+
11
+ }
12
+ }
13
+
14
+
15
+ module.exports = {
16
+
17
+ };
@@ -1,3 +1,4 @@
1
+ const { isNil } = require('./checks.js');
1
2
 
2
3
 
3
4
  const instances = {};
@@ -5,17 +6,17 @@ const wrappers = {};
5
6
 
6
7
 
7
8
 
8
- function addSingleton(name, fn) {
9
+ function singleton(name, fn) {
9
10
  wrappers[name] = fn;
10
11
  }
11
12
 
12
13
 
13
14
  async function getInstance(name){
14
- if (instances[name] !== undefined) {
15
+ if (!isNil(instances[name])) {
15
16
  return instances[name];
16
17
  }
17
18
 
18
- if (wrappers[name] === undefined) {
19
+ if (isNil(wrappers[name])) {
19
20
  return null;
20
21
  }
21
22
 
@@ -29,6 +30,6 @@ async function getInstance(name){
29
30
 
30
31
 
31
32
  module.exports = {
32
- addSingleton,
33
+ singleton,
33
34
  getInstance
34
35
  }
@@ -1,4 +1,3 @@
1
-
2
1
  const { isNil } = require('../lang/checks.js');
3
2
 
4
3