@wizhut_tech/wizjs 0.0.3 → 0.0.5

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,3 @@
1
+ # Lang / Checks
2
+
3
+ * **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,3 @@
1
+ ## lang / functools
2
+
3
+ * **reflexive(arg)**: Just a dumb method that returns `arg` as provided.
@@ -0,0 +1,8 @@
1
+ # Lang / Singleton
2
+
3
+ In-memory caching of an async function's result, ensuring that it will be called only once. Mimics similar python decorators. It can easily, be used to store class instance variables.
4
+
5
+ ### Module API
6
+
7
+ * **singleton(name, fn)**: register an `async` function (`fn`) by name.
8
+ * **getInstance(name)**: returns the instance for a specific `name`. Note that the `fn` is executed only when this method is called.
@@ -0,0 +1,3 @@
1
+ # Math / Numbers
2
+
3
+ * **toInteger(arg)**: Attempts to convert `arg` to `Integer`. Return `0` if the arg is `zero` or invalid value.
package/index.js CHANGED
@@ -1,12 +1,14 @@
1
1
  const singleton = require('./src/lang/singleton.js');
2
2
  const checks = require('./src/lang/checks.js');
3
3
  const numbers = require('./src/math/numbers.js');
4
+ const functools = require('./src/lang/functools.js');
4
5
 
5
6
 
6
7
  module.exports = {
7
8
  lang: {
8
9
  singleton: singleton,
9
- checks: checks
10
+ checks: checks,
11
+ functools: functools
10
12
  },
11
13
  math: {
12
14
  numbers: numbers
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wizhut_tech/wizjs",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "main": "index.js",
5
5
  "devDependencies": {
6
6
  "tap": "21.0.1"
package/readme.md CHANGED
@@ -1,5 +1,31 @@
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
+ Use by importing:
6
+
7
+ `const wizjs = require('@wizhut_tech/wizjs')`. Returns an object structured like:
8
+
9
+ ```
10
+ {
11
+ lang: {
12
+ checks: [functions],
13
+ singleton: [functions],
14
+ functools: [functions]
15
+ },
16
+ math: {
17
+ numbers: [functions]
18
+ }
19
+ }
20
+ ```
21
+
22
+ ### Language
23
+
24
+ * **Check** utility functions ... [[docs](docs/lang_checks.md)]
25
+ * Control-**Flow** utilities ... [[docs](docs/lang_flow.md)] -- *still in development* --
26
+ * **functools** ... [[docs](docs/lang_functools.md)]
27
+ * **Singleton** hack ... [[docs](docs/lang_singleton.md)]
28
+
29
+ ### Math
30
+
31
+ * Utilities around **numbers** ... [[docs](docs/math_numbers.md)]
@@ -0,0 +1,10 @@
1
+
2
+
3
+ function reflexive(arg) {
4
+ return arg;
5
+ }
6
+
7
+
8
+ module.exports = {
9
+ reflexive
10
+ }
@@ -6,7 +6,7 @@ const wrappers = {};
6
6
 
7
7
 
8
8
 
9
- function addSingleton(name, fn) {
9
+ function singleton(name, fn) {
10
10
  wrappers[name] = fn;
11
11
  }
12
12
 
@@ -30,6 +30,6 @@ async function getInstance(name){
30
30
 
31
31
 
32
32
  module.exports = {
33
- addSingleton,
33
+ singleton,
34
34
  getInstance
35
35
  }