corebasic 1.0.164 → 1.0.166

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.
Files changed (2) hide show
  1. package/libs/utils.js +28 -0
  2. package/package.json +1 -1
package/libs/utils.js CHANGED
@@ -167,6 +167,32 @@ export function sum(array) { // Eg: sum([10,20,undefined, NaN, 40])
167
167
  return res;
168
168
  }
169
169
 
170
+ export function validityToMillisecs(start, validity) { // start is in ms
171
+ const now = new Date(start)
172
+
173
+ let count = parseIntValue(validity.split(' ')[0])
174
+ let period = validity.split(' ')[1].toLowerCase()
175
+
176
+
177
+ const timeline = {
178
+ year: _ => now.setYear(now.getFullYear() + count),
179
+ years: _ => now.setYear(now.getFullYear() + count),
180
+ month: _ => now.setMonth(now.getMonth() + count),
181
+ months: _ => now.setMonth(now.getMonth() + count),
182
+ day: _ => now.setDate(now.getDate() + count),
183
+ days: _ => now.setDate(now.getDate() + count),
184
+ week: _ => now.setDate(now.getDate() + (count * 7)),
185
+ weeks: _ => now.setDate(now.getDate() + (count * 7)),
186
+ hour: _ => now.setHours(now.getHours() + count),
187
+ hours: _ => now.setHours(now.getHours() + count),
188
+ minute: _ => now.setMinutes(now.getMinutes() + count),
189
+ minutes: _ => now.setMinutes(now.getMinutes() + count),
190
+ }
191
+
192
+ timeline[period]()
193
+
194
+ return now.getTime()
195
+ }
170
196
 
171
197
  // ----------------
172
198
  // JSON
@@ -239,6 +265,8 @@ export function parseMob(mob, code) {
239
265
  code = code ?? "IN"
240
266
  if (isEmpty(mob))
241
267
  return mob
268
+ if (mob.startsWith("MOB_"))
269
+ return mob
242
270
  mob = mob.trim().replace(/(,| |-|\+)/g, '') // remove comma, space, hyphen and plus
243
271
  mob = mob.startsWith("0") ? mob.replace(/^0*/,'') : mob // remove starting n zeroes
244
272
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corebasic",
3
3
  "type": "module",
4
- "version": "1.0.164",
4
+ "version": "1.0.166",
5
5
  "description": "",
6
6
  "main": "index.js",
7
7
  "scripts": {