@bbn/bbn 2.0.175 → 2.0.178
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/dist/bbn.js +1 -1
- package/dist/bbn.js.map +1 -1
- package/dist/dt/classes/dt.js +13 -8
- package/dist/dt.js +1 -1
- package/dist/fn/ajax/getFileContent.d.ts +11 -0
- package/dist/fn/ajax/getFileContent.js +71 -0
- package/dist/fn.d.ts +2 -0
- package/dist/fn.js +2 -0
- package/package.json +1 -1
package/dist/dt/classes/dt.js
CHANGED
|
@@ -181,7 +181,8 @@ export class bbnDt {
|
|
|
181
181
|
throw new TypeError('Both arguments must be Temporal values');
|
|
182
182
|
}
|
|
183
183
|
const tz = Temporal.Now.timeZoneId();
|
|
184
|
-
|
|
184
|
+
let realUnit = unitsCorrespondence[unit] ? getRow(units, d => d[0] === unitsCorrespondence[unit])[1] : undefined;
|
|
185
|
+
realUnit = realUnit ? realUnit + 's' : undefined;
|
|
185
186
|
const isBbnDt = (x) => x instanceof bbnDt;
|
|
186
187
|
// --- helper: get underlying Temporal value if wrapper ---
|
|
187
188
|
const unwrap = (x) => isBbnDt(x) ? x.value : x;
|
|
@@ -224,17 +225,19 @@ export class bbnDt {
|
|
|
224
225
|
const rawB = unwrap(b);
|
|
225
226
|
if (rawA.constructor === rawB.constructor) {
|
|
226
227
|
const Ctor = rawA.constructor;
|
|
228
|
+
const comp = Ctor.compare(rawA, rawB);
|
|
227
229
|
if (realUnit === undefined) {
|
|
228
230
|
if (typeof Ctor.compare !== 'function') {
|
|
229
231
|
throw new TypeError('This Temporal type has no static compare');
|
|
230
232
|
}
|
|
231
|
-
return
|
|
233
|
+
return comp;
|
|
232
234
|
}
|
|
233
|
-
if (typeof rawA.until !== 'function')
|
|
235
|
+
if ((typeof rawA.until !== 'function')
|
|
236
|
+
|| (typeof rawA.since !== 'function')) {
|
|
234
237
|
throw new TypeError('This Temporal type does not support until/since');
|
|
235
238
|
}
|
|
236
|
-
const diff = rawA
|
|
237
|
-
//bbn.fn.log(['compare0', diff, realUnit, diff.sign, a.date(), b.date(), rawA.day, rawB.day]);
|
|
239
|
+
const diff = rawA[comp === 1 ? 'since' : 'until'](rawB, { smallestUnit: realUnit, largestUnit: realUnit, roundingMode: 'floor' });
|
|
240
|
+
//bbn.fn.log(['compare0', comp, diff, realUnit, diff.sign, a.date(), b.date(), rawA.day, rawB.day]);
|
|
238
241
|
return diff.sign;
|
|
239
242
|
}
|
|
240
243
|
// ---- CASE 2: different constructors, but convertible bbnDt kinds ----
|
|
@@ -250,13 +253,15 @@ export class bbnDt {
|
|
|
250
253
|
convertibleKinds.has(b.kind)) {
|
|
251
254
|
const za = toZdt(a);
|
|
252
255
|
const zb = toZdt(b);
|
|
256
|
+
const comp = Temporal.ZonedDateTime.compare(za, zb);
|
|
253
257
|
if (realUnit === undefined) {
|
|
254
|
-
return
|
|
258
|
+
return comp;
|
|
255
259
|
}
|
|
256
|
-
if (typeof za.until !== 'function')
|
|
260
|
+
if ((typeof za.until !== 'function')
|
|
261
|
+
|| (typeof za.since !== 'function')) {
|
|
257
262
|
throw new TypeError('ZonedDateTime does not support until/since');
|
|
258
263
|
}
|
|
259
|
-
const diff = za
|
|
264
|
+
const diff = za[comp === 1 ? 'since' : 'until'](zb, { smallestUnit: realUnit, largestUnit: realUnit, roundingMode: 'floor' });
|
|
260
265
|
//bbn.fn.log(['compare', diff, realUnit, diff.sign, a.date(), b.date(), za.day, zb.day]);
|
|
261
266
|
return diff.sign;
|
|
262
267
|
}
|
package/dist/dt.js
CHANGED
|
@@ -195,7 +195,7 @@ const dt = (value, inputFormat = null, cls = 'auto') => {
|
|
|
195
195
|
}
|
|
196
196
|
}
|
|
197
197
|
if (typeof value === 'number') {
|
|
198
|
-
return new bbnDtDateTime(Math.abs(value) < 99999999999 ?
|
|
198
|
+
return new bbnDtDateTime(Math.floor(Math.abs(value) < 99999999999 ? value * 1000 : value));
|
|
199
199
|
}
|
|
200
200
|
else if (value.__isBbnDt) {
|
|
201
201
|
return value;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Uploads a file in the browser and deal with its content.
|
|
3
|
+
*
|
|
4
|
+
* @method getFileContent
|
|
5
|
+
* @todo examples
|
|
6
|
+
* @global
|
|
7
|
+
* @memberof bbn.fn
|
|
8
|
+
*
|
|
9
|
+
* @returns {Promise}
|
|
10
|
+
*/
|
|
11
|
+
export default function getFileContent() {
|
|
12
|
+
let type = '';
|
|
13
|
+
let treatAs = 'text';
|
|
14
|
+
let success;
|
|
15
|
+
let failure;
|
|
16
|
+
let progress;
|
|
17
|
+
bbn.fn.each(arguments, (arg) => {
|
|
18
|
+
if (typeof arg === 'string') {
|
|
19
|
+
if (['binary', 'text'].includes(arg.toLowerCase())) {
|
|
20
|
+
treatAs = arg.toLowerCase();
|
|
21
|
+
}
|
|
22
|
+
else if (!type) {
|
|
23
|
+
type = arg;
|
|
24
|
+
if (type === 'image') {
|
|
25
|
+
type = "image/*";
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
else if (bbn.fn.isFunction(arg)) {
|
|
30
|
+
if (!success) {
|
|
31
|
+
success = arg;
|
|
32
|
+
}
|
|
33
|
+
else if (!failure) {
|
|
34
|
+
failure = arg;
|
|
35
|
+
}
|
|
36
|
+
else if (!progress) {
|
|
37
|
+
progress = arg;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
let input = document.createElement("input");
|
|
42
|
+
input.type = "file";
|
|
43
|
+
if (type) {
|
|
44
|
+
input.setAttribute("accept", type);
|
|
45
|
+
}
|
|
46
|
+
input.onchange = function (event) {
|
|
47
|
+
var _a;
|
|
48
|
+
const file = (_a = input.files) === null || _a === void 0 ? void 0 : _a[0];
|
|
49
|
+
if (!file)
|
|
50
|
+
return;
|
|
51
|
+
const reader = new FileReader();
|
|
52
|
+
if (treatAs === 'binary') {
|
|
53
|
+
reader.readAsArrayBuffer(file);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
reader.readAsText(file, `UTF-8`);
|
|
57
|
+
}
|
|
58
|
+
reader.onload = function ({ target }) {
|
|
59
|
+
if (success) {
|
|
60
|
+
success(target === null || target === void 0 ? void 0 : target.result);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
reader.onerror = function () {
|
|
64
|
+
if (failure) {
|
|
65
|
+
failure(`error reading file`);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
input.click();
|
|
70
|
+
}
|
|
71
|
+
;
|
package/dist/fn.d.ts
CHANGED
|
@@ -102,6 +102,7 @@ import getDeviceType from './fn/browser/getDeviceType.js';
|
|
|
102
102
|
import getEventData from './fn/browser/getEventData.js';
|
|
103
103
|
import getField from './fn/object/getField.js';
|
|
104
104
|
import getFieldValues from './fn/object/getFieldValues.js';
|
|
105
|
+
import getFileContent from './fn/ajax/getFileContent.js';
|
|
105
106
|
import getIndex from './fn/html/getIndex.js';
|
|
106
107
|
import getHtml from './fn/html/getHtml.js';
|
|
107
108
|
import getHTMLOfSelection from './fn/html/getHTMLOfSelection.js';
|
|
@@ -350,6 +351,7 @@ declare const _default: {
|
|
|
350
351
|
getEventData: typeof getEventData;
|
|
351
352
|
getField: typeof getField;
|
|
352
353
|
getFieldValues: typeof getFieldValues;
|
|
354
|
+
getFileContent: typeof getFileContent;
|
|
353
355
|
getIndex: typeof getIndex;
|
|
354
356
|
getHtml: typeof getHtml;
|
|
355
357
|
getHTMLOfSelection: typeof getHTMLOfSelection;
|
package/dist/fn.js
CHANGED
|
@@ -102,6 +102,7 @@ import getDeviceType from './fn/browser/getDeviceType.js';
|
|
|
102
102
|
import getEventData from './fn/browser/getEventData.js';
|
|
103
103
|
import getField from './fn/object/getField.js';
|
|
104
104
|
import getFieldValues from './fn/object/getFieldValues.js';
|
|
105
|
+
import getFileContent from './fn/ajax/getFileContent.js';
|
|
105
106
|
import getIndex from './fn/html/getIndex.js';
|
|
106
107
|
import getHtml from './fn/html/getHtml.js';
|
|
107
108
|
import getHTMLOfSelection from './fn/html/getHTMLOfSelection.js';
|
|
@@ -350,6 +351,7 @@ export default {
|
|
|
350
351
|
getEventData,
|
|
351
352
|
getField,
|
|
352
353
|
getFieldValues,
|
|
354
|
+
getFileContent,
|
|
353
355
|
getIndex,
|
|
354
356
|
getHtml,
|
|
355
357
|
getHTMLOfSelection,
|