@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.
@@ -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
+ });
@@ -5,5 +5,8 @@ const { reflexive } = require('../src/lang/functools.js');
5
5
 
6
6
  t.test('functools/reflexive', (t) => {
7
7
  t.equal(reflexive(null), null);
8
+ t.equal(reflexive(1), 1);
9
+ t.equal(reflexive('abcde'), 'abcde');
10
+ t.equal(reflexive(2.1), 2.1);
8
11
  t.end();
9
12
  });
@@ -9,5 +9,6 @@ t.test('numbers/toInteger', (t) => {
9
9
  t.equal(toInteger(1.0), 1);
10
10
  t.equal(toInteger('1'), 1);
11
11
  t.equal(toInteger(1), 1);
12
+ t.equal(toInteger('abcde'), 0);
12
13
  t.end();
13
- });
14
+ });
@@ -0,0 +1,2 @@
1
+ # Lang / Arrays
2
+
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
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@wizhut_tech/wizjs",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "main": "index.js",
5
5
  "devDependencies": {
6
- "tap": "21.0.1"
6
+ "tap": "21.0.2"
7
7
  },
8
8
  "description": "Simple but useful hacks for everyday javascript programming",
9
9
  "scripts": {
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
+ }
@@ -7,7 +7,13 @@ function toInteger(num) {
7
7
  }
8
8
 
9
9
  try {
10
- return parseInt(num, 10);
10
+ const r = parseInt(num, 10);
11
+
12
+ if (isNaN(r)) {
13
+ return 0;
14
+ }
15
+
16
+ return r;
11
17
  } catch (e) {
12
18
  return 0;
13
19
  }