@wizhut_tech/wizjs 0.0.1 → 0.0.3

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,13 @@
1
+ const t = require('tap');
2
+
3
+ const { isNil } = require('../src/lang/checks.js');
4
+
5
+
6
+ t.test('checks/isNil', (t) => {
7
+ t.equal(isNil(null), true);
8
+ t.equal(isNil(undefined), true);
9
+ t.equal(isNil(1), false);
10
+ t.equal(isNil(1.0), false);
11
+ t.equal(isNil('not-null-string'), false);
12
+ t.end();
13
+ });
@@ -0,0 +1,13 @@
1
+ const t = require('tap');
2
+
3
+ const { toInteger } = require('../src/math/numbers.js');
4
+
5
+
6
+ t.test('numbers/toInteger', (t) => {
7
+ t.equal(toInteger(null), 0);
8
+ t.equal(toInteger(undefined), 0);
9
+ t.equal(toInteger(1.0), 1);
10
+ t.equal(toInteger('1'), 1);
11
+ t.equal(toInteger(1), 1);
12
+ t.end();
13
+ });
package/index.js CHANGED
@@ -1,8 +1,14 @@
1
1
  const singleton = require('./src/lang/singleton.js');
2
+ const checks = require('./src/lang/checks.js');
3
+ const numbers = require('./src/math/numbers.js');
2
4
 
3
5
 
4
6
  module.exports = {
5
7
  lang: {
6
- singleton: singleton
8
+ singleton: singleton,
9
+ checks: checks
10
+ },
11
+ math: {
12
+ numbers: numbers
7
13
  }
8
14
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wizhut_tech/wizjs",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "main": "index.js",
5
5
  "devDependencies": {
6
6
  "tap": "21.0.1"
@@ -0,0 +1,9 @@
1
+
2
+ function isNil(value) {
3
+ return value === null || value === undefined;
4
+ }
5
+
6
+
7
+ module.exports = {
8
+ isNil
9
+ }
@@ -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 = {};
@@ -11,11 +12,11 @@ function addSingleton(name, fn) {
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
 
@@ -0,0 +1,19 @@
1
+ const { isNil } = require('../lang/checks.js');
2
+
3
+
4
+ function toInteger(num) {
5
+ if (isNil(num)) {
6
+ return 0;
7
+ }
8
+
9
+ try {
10
+ return parseInt(num, 10);
11
+ } catch (e) {
12
+ return 0;
13
+ }
14
+ }
15
+
16
+
17
+ module.exports = {
18
+ toInteger
19
+ }