@engine9-io/input-tools 1.3.8 → 1.4.0
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/file/tools.js +1 -1
- package/index.js +76 -5
- package/package.json +1 -1
package/file/tools.js
CHANGED
@@ -226,12 +226,12 @@ function bool(x, _defaultVal) {
|
|
226
226
|
module.exports = {
|
227
227
|
bool,
|
228
228
|
getTempFilename,
|
229
|
+
getTempDir,
|
229
230
|
downloadFile,
|
230
231
|
getBatchTransform,
|
231
232
|
getDebatchTransform,
|
232
233
|
getFile,
|
233
234
|
getManifest,
|
234
235
|
getPacketFiles,
|
235
|
-
getTempDir,
|
236
236
|
streamPacket,
|
237
237
|
};
|
package/index.js
CHANGED
@@ -20,6 +20,7 @@ const {
|
|
20
20
|
getFile,
|
21
21
|
downloadFile,
|
22
22
|
getTempFilename,
|
23
|
+
getTempDir,
|
23
24
|
streamPacket,
|
24
25
|
getPacketFiles,
|
25
26
|
getBatchTransform,
|
@@ -57,6 +58,73 @@ function getStringArray(s, nonZeroLength) {
|
|
57
58
|
return a;
|
58
59
|
}
|
59
60
|
|
61
|
+
function isValidDate(d) {
|
62
|
+
// we WANT to use isNaN, not the Number.isNaN -- we're checking the date type
|
63
|
+
// eslint-disable-next-line no-restricted-globals
|
64
|
+
return d instanceof Date && !isNaN(d);
|
65
|
+
}
|
66
|
+
|
67
|
+
function relativeDate(s, _initialDate) {
|
68
|
+
let initialDate = _initialDate;
|
69
|
+
if (!s || s === 'none') return null;
|
70
|
+
if (typeof s.getMonth === 'function') return s;
|
71
|
+
// We actually want a double equals here to test strings as well
|
72
|
+
// eslint-disable-next-line eqeqeq
|
73
|
+
if (parseInt(s, 10) == s) {
|
74
|
+
const r = new Date(parseInt(s, 10));
|
75
|
+
if (!isValidDate(r)) throw new Error(`Invalid integer date:${s}`);
|
76
|
+
return r;
|
77
|
+
}
|
78
|
+
|
79
|
+
if (initialDate) {
|
80
|
+
initialDate = new Date(initialDate);
|
81
|
+
} else {
|
82
|
+
initialDate = new Date();
|
83
|
+
}
|
84
|
+
|
85
|
+
let r = s.match(/^([+-]{1})([0-9]+)([YyMwdhms]{1})([.a-z]*)$/);
|
86
|
+
|
87
|
+
if (r) {
|
88
|
+
let period = null;
|
89
|
+
switch (r[3]) {
|
90
|
+
case 'Y':
|
91
|
+
case 'y': period = 'years'; break;
|
92
|
+
|
93
|
+
case 'M': period = 'months'; break;
|
94
|
+
case 'w': period = 'weeks'; break;
|
95
|
+
case 'd': period = 'days'; break;
|
96
|
+
case 'h': period = 'hours'; break;
|
97
|
+
case 'm': period = 'minutes'; break;
|
98
|
+
case 's': period = 'seconds'; break;
|
99
|
+
default: period = 'minutes'; break;
|
100
|
+
}
|
101
|
+
|
102
|
+
let d = dayjs(initialDate);
|
103
|
+
|
104
|
+
if (r[1] === '+') {
|
105
|
+
d = d.add(parseInt(r[2], 10), period);
|
106
|
+
} else {
|
107
|
+
d = d.subtract(parseInt(r[2], 10), period);
|
108
|
+
}
|
109
|
+
if (!isValidDate(d.toDate())) throw new Error(`Invalid date configuration:${r}`);
|
110
|
+
if (r[4]) {
|
111
|
+
const opts = r[4].split('.').filter(Boolean);
|
112
|
+
if (opts[0] === 'start') d = d.startOf(opts[1] || 'day');
|
113
|
+
else if (opts[0] === 'end') d = d.endOf(opts[1] || 'day');
|
114
|
+
else throw new Error(`Invalid relative date,unknown options:${r[4]}`);
|
115
|
+
}
|
116
|
+
|
117
|
+
return d.toDate();
|
118
|
+
}
|
119
|
+
if (s === 'now') {
|
120
|
+
r = dayjs(new Date()).toDate();
|
121
|
+
return r;
|
122
|
+
}
|
123
|
+
r = dayjs(new Date(s)).toDate();
|
124
|
+
if (!isValidDate(r)) throw new Error(`Invalid Date: ${s}`);
|
125
|
+
return r;
|
126
|
+
}
|
127
|
+
|
60
128
|
/*
|
61
129
|
When comparing two objects, some may come from a file (thus strings), and some from
|
62
130
|
a database or elsewhere (not strings), so for deduping make sure to make them all strings
|
@@ -321,11 +389,14 @@ module.exports = {
|
|
321
389
|
list,
|
322
390
|
downloadFile,
|
323
391
|
extract,
|
392
|
+
ForEachEntry,
|
393
|
+
FileUtilities,
|
324
394
|
getBatchTransform,
|
325
395
|
getDebatchTransform,
|
326
396
|
getManifest,
|
327
397
|
getFile,
|
328
398
|
getStringArray,
|
399
|
+
getTempDir,
|
329
400
|
getTempFilename,
|
330
401
|
getTimelineEntryUUID,
|
331
402
|
getPacketFiles,
|
@@ -335,13 +406,13 @@ module.exports = {
|
|
335
406
|
getUUIDTimestamp,
|
336
407
|
getEntryTypeId,
|
337
408
|
handlebars,
|
409
|
+
isValidDate,
|
410
|
+
makeStrings,
|
411
|
+
relativeDate,
|
412
|
+
streamPacket,
|
413
|
+
TIMELINE_ENTRY_TYPES,
|
338
414
|
uuidIsValid,
|
339
415
|
uuidv4,
|
340
416
|
uuidv5,
|
341
417
|
uuidv7,
|
342
|
-
makeStrings,
|
343
|
-
ForEachEntry,
|
344
|
-
FileUtilities,
|
345
|
-
streamPacket,
|
346
|
-
TIMELINE_ENTRY_TYPES,
|
347
418
|
};
|