@wizhut_tech/wizjs 0.0.6 → 0.0.7
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_arrays.test.js +14 -0
- package/__tests__/lang_functools.test.js +3 -0
- package/__tests__/math_numbers.test.js +2 -1
- package/docs/lang_arrays.md +2 -0
- package/index.js +2 -0
- package/package.json +2 -2
- package/readme.md +2 -0
- package/src/lang/arrays.js +25 -0
- package/src/math/numbers.js +7 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const t = require('tap');
|
|
2
|
+
|
|
3
|
+
const { compact } = require('../src/lang/arrays.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
t.test('arrays/compact', (t) => {
|
|
7
|
+
t.match(compact([1, 2, 3]), [1, 2, 3]);
|
|
8
|
+
t.match(compact([null, 2, 3]), [2, 3]);
|
|
9
|
+
t.match(compact([1, 2, undefined]), [1, 2]);
|
|
10
|
+
t.match(compact([null, 1, undefined]), [1]);
|
|
11
|
+
t.match(compact(null), []);
|
|
12
|
+
t.match(compact(undefined), []);
|
|
13
|
+
t.end();
|
|
14
|
+
});
|
package/index.js
CHANGED
|
@@ -2,10 +2,12 @@ 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
4
|
const functools = require('./src/lang/functools.js');
|
|
5
|
+
const arrays = require('./src/lang/arrays.js');
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
module.exports = {
|
|
8
9
|
lang: {
|
|
10
|
+
arrays: arrays,
|
|
9
11
|
singleton: singleton,
|
|
10
12
|
checks: checks,
|
|
11
13
|
functools: functools
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -9,6 +9,7 @@ Use by importing:
|
|
|
9
9
|
```
|
|
10
10
|
{
|
|
11
11
|
lang: {
|
|
12
|
+
arrays: [functions],
|
|
12
13
|
checks: [functions],
|
|
13
14
|
singleton: [functions],
|
|
14
15
|
functools: [functions]
|
|
@@ -21,6 +22,7 @@ Use by importing:
|
|
|
21
22
|
|
|
22
23
|
### Language
|
|
23
24
|
|
|
25
|
+
* **Arrays** utility functions ... [[docs](docs/lang_arrays.md)]
|
|
24
26
|
* **Check** utility functions ... [[docs](docs/lang_checks.md)]
|
|
25
27
|
* Control-**Flow** utilities ... [[docs](docs/lang_flow.md)] -- *still in development* --
|
|
26
28
|
* **functools** ... [[docs](docs/lang_functools.md)]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const { isNil } = require('./checks.js');
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
function compact(arr) {
|
|
5
|
+
if (isNil(arr)) {
|
|
6
|
+
return [];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const result = [];
|
|
10
|
+
|
|
11
|
+
for (let i = 0; i < arr.length; i++) {
|
|
12
|
+
if (isNil(arr[i])) {
|
|
13
|
+
continue;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
result.push(arr[i]);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
compact
|
|
25
|
+
}
|