@wizhut_tech/wizjs 0.0.4 → 0.0.6
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_checks.test.js +45 -2
- package/__tests__/lang_functools.test.js +9 -0
- package/docs/lang_checks.md +5 -3
- package/docs/lang_functools.md +3 -0
- package/docs/lang_singleton.md +1 -3
- package/docs/math_numbers.md +0 -2
- package/index.js +3 -1
- package/package.json +1 -1
- package/readme.md +22 -4
- package/src/lang/checks.js +31 -1
- package/src/lang/functools.js +10 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const t = require('tap');
|
|
2
2
|
|
|
3
|
-
const { isNil } = require('../src/lang/checks.js');
|
|
3
|
+
const { isNil, isArray, isObject, isNumber, isString } = require('../src/lang/checks.js');
|
|
4
|
+
|
|
4
5
|
|
|
5
6
|
|
|
6
7
|
t.test('checks/isNil', (t) => {
|
|
@@ -10,4 +11,46 @@ t.test('checks/isNil', (t) => {
|
|
|
10
11
|
t.equal(isNil(1.0), false);
|
|
11
12
|
t.equal(isNil('not-null-string'), false);
|
|
12
13
|
t.end();
|
|
13
|
-
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
t.test('checks/isArray', (t) => {
|
|
17
|
+
t.equal(isArray([]), true);
|
|
18
|
+
t.equal(isArray(1), false);
|
|
19
|
+
t.equal(isArray('misc'), false);
|
|
20
|
+
t.equal(isArray(null), false);
|
|
21
|
+
t.equal(isArray(undefined), false);
|
|
22
|
+
t.equal(isArray({}), false);
|
|
23
|
+
t.end();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
t.test('checks/isObject', (t) => {
|
|
27
|
+
t.equal(isObject(null), false);
|
|
28
|
+
t.equal(isObject(undefined), false);
|
|
29
|
+
t.equal(isObject(1), false);
|
|
30
|
+
t.equal(isObject('misc'), false);
|
|
31
|
+
t.equal(isObject({}), true);
|
|
32
|
+
t.equal(isObject([]), false);
|
|
33
|
+
t.end();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
t.test('checks/isNumber', (t) => {
|
|
37
|
+
t.equal(isNumber(null), false);
|
|
38
|
+
t.equal(isNumber(undefined), false);
|
|
39
|
+
t.equal(isNumber({}), false);
|
|
40
|
+
t.equal(isNumber([]), false);
|
|
41
|
+
t.equal(isNumber(1), true);
|
|
42
|
+
t.equal(isNumber(1.1), true);
|
|
43
|
+
t.equal(isNumber('misc'), false);
|
|
44
|
+
t.end();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
t.test('checks/isString', (t) => {
|
|
48
|
+
t.equal(isString(null), false);
|
|
49
|
+
t.equal(isString(undefined), false);
|
|
50
|
+
t.equal(isString({}), false);
|
|
51
|
+
t.equal(isString([]), false);
|
|
52
|
+
t.equal(isString(1), false);
|
|
53
|
+
t.equal(isString(1.1), false);
|
|
54
|
+
t.equal(isString('misc'), true);
|
|
55
|
+
t.end();
|
|
56
|
+
})
|
package/docs/lang_checks.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# Lang / Checks
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
* **
|
|
3
|
+
* **isNil(arg)**: Checks if the `arg` is `undefined` or `null` and returns `true` (or `false` otherwise).
|
|
4
|
+
* **isArray(arg)**: Checks if the `arg` is an `array` and return `true` else `false`
|
|
5
|
+
* **isObject(arg)**: Checks if the `arg` is an `object` and return `true` else `false`
|
|
6
|
+
* **isString(arg)**: Checks if the `arg` is a `string` and return `true` else `false`
|
|
7
|
+
* **isNumber(arg)**: Checks if the `arg` is a `number` and return `true` else `false`
|
package/docs/lang_singleton.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# Lang / Singleton
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Mimics similar python decorators. It can easily, be used to store class instance variables.
|
|
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.
|
|
6
4
|
|
|
7
5
|
### Module API
|
|
8
6
|
|
package/docs/math_numbers.md
CHANGED
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
package/readme.md
CHANGED
|
@@ -2,12 +2,30 @@
|
|
|
2
2
|
|
|
3
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
|
+
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
|
+
|
|
5
22
|
### Language
|
|
6
23
|
|
|
7
|
-
*
|
|
8
|
-
* Flow ... [
|
|
9
|
-
*
|
|
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)]
|
|
10
28
|
|
|
11
29
|
### Math
|
|
12
30
|
|
|
13
|
-
*
|
|
31
|
+
* Utilities around **numbers** ... [[docs](docs/math_numbers.md)]
|
package/src/lang/checks.js
CHANGED
|
@@ -3,7 +3,37 @@ function isNil(value) {
|
|
|
3
3
|
return value === null || value === undefined;
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
+
function isArray(value) {
|
|
7
|
+
return Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function isObject(value) {
|
|
11
|
+
if (isNil(value)) {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
if (isArray(value)) {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return typeof value === 'object';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
function isString(value) {
|
|
24
|
+
return typeof value === 'string';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
function isNumber(value) {
|
|
29
|
+
return typeof value === 'number';
|
|
30
|
+
}
|
|
31
|
+
|
|
6
32
|
|
|
7
33
|
module.exports = {
|
|
8
|
-
isNil
|
|
34
|
+
isNil,
|
|
35
|
+
isArray,
|
|
36
|
+
isObject,
|
|
37
|
+
isString,
|
|
38
|
+
isNumber
|
|
9
39
|
}
|