corebasic 1.0.5 → 1.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/libs/elabase.js CHANGED
@@ -32,7 +32,7 @@ let Events = {
32
32
 
33
33
 
34
34
 
35
- let url = "http://127.0.0.1"
35
+ const url = process.env.DIP_URL || "http://127.0.0.1"; // Set DIP_URL to "http://dip" (Prod) or http://dip-dev (Dev) in CI/CD
36
36
  let port = 9401
37
37
  let api = 'execute'
38
38
  let fullurl = `${url}:${port}/${api}`
@@ -47,8 +47,8 @@ let Elabase = {
47
47
  }
48
48
 
49
49
  let engine = Elabase.Engine.Lmdb
50
- let internal = {
51
- db: undefined,
50
+ let internal = {
51
+ db: undefined,
52
52
  engineName: engine === Elabase.Engine.Lmdb ? "lmdb" : (engine === Elabase.Engine.Sled ? "sled" : engine === Elabase.Engine.Sanakirja ? "sanakirja" : "lmdb")
53
53
  }
54
54
 
@@ -56,8 +56,8 @@ let db = internal.db // default database
56
56
 
57
57
  function start(dbName) {
58
58
  if (!Utils.isEmpty(dbName) && Utils.isEmpty(db)) {
59
- internal.db = dbName
60
- db = dbName
59
+ internal.db = "data/" + dbName
60
+ db = "data/" + dbName
61
61
  Utils.requisites.startElabase()
62
62
  }
63
63
  }
@@ -79,15 +79,17 @@ function insert(collection, value, _id) {
79
79
  })
80
80
  }
81
81
 
82
- function query(collection, query) {
82
+ function query(collection, query, options) {
83
83
  var arg = {
84
84
  collection: collection,
85
- query: query
85
+ query: query,
86
+ options: options ? options : {},
86
87
  }
87
88
  return new Promise((resolve, reject) => resolve())
88
89
  .then(() => execute(arg))
89
90
  }
90
91
 
92
+
91
93
  function collectionArray(col) {
92
94
  var type = Object.prototype.toString.call(col)
93
95
  if (type === '[object Array]') {
@@ -105,11 +107,12 @@ function collectionArray(col) {
105
107
  }
106
108
 
107
109
 
108
- function update(collection, query, update) {
110
+ function update(collection, query, update, options) {
109
111
  var arg = {
110
112
  collection: collection,
111
113
  query: query,
112
114
  update: update,
115
+ options: options ? options : {},
113
116
  }
114
117
  return new Promise((resolve, reject) => resolve())
115
118
  .then(() => execute(arg))
package/libs/utils.js CHANGED
@@ -5,10 +5,17 @@ let pipeline = { execute: execute }
5
5
  module.exports = {
6
6
  uid,
7
7
  isEmpty,
8
+ isEmptyJson,
8
9
  parseFloatValue,
9
10
  parseIntValue,
10
11
  now,
11
12
  pipeline,
13
+ toDate,
14
+ toAppDate,
15
+ deepCopy,
16
+ getDatesBetweenTwoDates,
17
+ formatAMPM,
18
+ sum
12
19
  }
13
20
 
14
21
  function uid() {
@@ -21,6 +28,12 @@ function isEmpty(str) { // returns true for undefined
21
28
  return str.match(/\S/) ? false : true // matches a non space character
22
29
  }
23
30
 
31
+ function isEmptyJson(json) {
32
+ for (var i in json)
33
+ return false
34
+ return true
35
+ }
36
+
24
37
  // --------------
25
38
  // Parse Numbers
26
39
  // --------------
@@ -36,6 +49,129 @@ function parseIntValue(val) {
36
49
  function now() {
37
50
  return new Date()
38
51
  }
52
+ function toAppDate(date) { // New
53
+ if (Object.prototype.toString.call(date) === '[object String]')
54
+ date = new Date(date)
55
+
56
+ var temp = date
57
+ if (isNaN(temp) || date === '')
58
+ return ''
59
+
60
+ var day = temp.getDate().toString()
61
+ if(day.length === 1) day = "0"+day
62
+ var month = (temp.getMonth() + 1).toString()
63
+ if(month.length == 1) month = "0"+month
64
+ return (day + "/" + month + "/" + temp.getFullYear().toString())
65
+ }
66
+
67
+ // ----------------
68
+ // Pipeline Execute
69
+ // ----------------
70
+
71
+
72
+ function execute(pipeline, errfn) {
73
+ startPipeline(pipeline, 0, undefined, errfn)
74
+ }
75
+
76
+ function startPipeline(pipeline, index, data, errfn) {
77
+ index = index == undefined ? 0 : index
78
+ if (index == pipeline.length)
79
+ return
80
+ pipeline[index](data).then(data => startPipeline(pipeline, index + 1, data)).catch(err => { if (errfn) errfn(err) } )
81
+ }
82
+
83
+ function toDate(arg, currentTime) { // New
84
+
85
+ var st = arg.split('/')
86
+
87
+ var temp = new Date(st[2],parseInt(st[1]) - 1, st[0]);
88
+ temp.setHours(0) ; temp.setMinutes(0); temp.setSeconds(0); temp.setMilliseconds(0)
89
+
90
+ if (currentTime) {
91
+ var curdate = getCurrentDate()
92
+ temp.setHours(curdate.getHours())
93
+ temp.setMinutes(curdate.getMinutes())
94
+ temp.setSeconds(curdate.getSeconds())
95
+ temp.setMilliseconds(curdate.getMilliseconds())
96
+ }
97
+
98
+ if (isNaN(temp))
99
+ return undefined
100
+ return temp
101
+ }
102
+
103
+ function toAppDate(date) { // New
104
+ if (Object.prototype.toString.call(date) === '[object String]')
105
+ date = new Date(date)
106
+
107
+ var temp = date
108
+ if (isNaN(temp) || date === '')
109
+ return ''
110
+
111
+ var day = temp.getDate().toString()
112
+ if(day.length === 1) day = "0"+day
113
+ var month = (temp.getMonth() + 1).toString()
114
+ if(month.length == 1) month = "0"+month
115
+ return (day + "/" + month + "/" + temp.getFullYear().toString())
116
+ }
117
+
118
+ function getDatesBetweenTwoDates(start, end) {
119
+ var arr = [];
120
+ var dt = new Date(start);
121
+
122
+ dt.setHours(0)
123
+ dt.setMinutes(0)
124
+ dt.setSeconds(0)
125
+ dt.setMilliseconds(0)
126
+
127
+ while (dt <= end) {
128
+ arr.push(new Date(dt));
129
+ dt.setDate(dt.getDate() + 1);
130
+ }
131
+ return arr;
132
+ }
133
+
134
+ function deepCopy(obj) {
135
+ if (Object.prototype.toString.call(obj) === '[object Array]') {
136
+ var out = [], i = 0, len = obj.length;
137
+ for ( ; i < len; i++ ) {
138
+ if (Object.prototype.toString.call(obj[i]) === '[object Date]')
139
+ out[i] = new Date(obj[i])
140
+ else
141
+ out[i] = arguments.callee(obj[i]);
142
+ }
143
+ return out;
144
+ }
145
+ if (typeof obj === 'object') {
146
+ var out = {}, i;
147
+ for ( i in obj ) {
148
+ if (Object.prototype.toString.call(obj[i]) === '[object Date]')
149
+ out[i] = new Date(obj[i])
150
+ else
151
+ out[i] = arguments.callee(obj[i]);
152
+ }
153
+ return out;
154
+ }
155
+ return obj;
156
+ }
157
+
158
+
159
+ function formatAMPM(date) {
160
+ var hours = date.getHours();
161
+ var minutes = date.getMinutes();
162
+ var ampm = hours >= 12 ? 'pm' : 'am';
163
+ hours = hours % 12;
164
+ hours = hours ? hours : 12; // the hour '0' should be '12'
165
+ minutes = minutes < 10 ? '0'+minutes : minutes;
166
+ var strTime = hours + ':' + minutes + ' ' + ampm;
167
+ return strTime;
168
+ }
169
+ function sum(array) { // Eg: sum([10,20,undefined, NaN, 40])
170
+ var res = 0
171
+ for (var i in array)
172
+ res += parseFloat(array[i]) ? parseFloat(array[i]) : 0
173
+ return res;
174
+ }
39
175
 
40
176
 
41
177
  // ----------------
@@ -53,3 +189,4 @@ function startPipeline(pipeline, index, data, errfn) {
53
189
  return
54
190
  pipeline[index](data).then(data => startPipeline(pipeline, index + 1, data)).catch(err => { if (errfn) errfn(err) } )
55
191
  }
192
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corebasic",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {