@data-fair/lib-vue 1.23.0 → 1.23.2
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/format/bytes.js +19 -17
- package/format/field.js +21 -14
- package/locale-dayjs.d.ts +2 -2
- package/locale-dayjs.js +2 -2
- package/package.json +1 -1
- package/session.d.ts +1 -0
- package/session.js +1 -0
package/format/bytes.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
const locales = {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
export function formatBytes
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
fr: [[0, 'octet'], [1, 'octets'], [1000, 'ko'], [1000 * 1000, 'Mo'], [1000 * 1000 * 1000, 'Go'], [1000 * 1000 * 1000 * 1000, 'To'], [1000 * 1000 * 1000 * 1000 * 1000, 'Po']],
|
|
3
|
+
en: [[0, 'byte'], [1, 'bytes'], [1000, 'kb'], [1000 * 1000, 'Mb'], [1000 * 1000 * 1000, 'Gb'], [1000 * 1000 * 1000 * 1000, 'Tb'], [1000 * 1000 * 1000 * 1000 * 1000, 'Pb']]
|
|
4
|
+
};
|
|
5
|
+
export function formatBytes(bytes, locale = 'fr') {
|
|
6
|
+
const bytesInt = Math.abs(typeof bytes === 'string' ? parseInt(bytes, 10) : bytes);
|
|
7
|
+
const def = locales[locale] ?? locales.en;
|
|
8
|
+
for (let i = 0; i < def.length; i++) {
|
|
9
|
+
const step = def[i][0];
|
|
10
|
+
if (bytesInt < step || i === def.length - 1) {
|
|
11
|
+
const value = bytesInt / (def[i - 1][0] || 1);
|
|
12
|
+
let digits = 2;
|
|
13
|
+
if (value > 1)
|
|
14
|
+
digits = 1;
|
|
15
|
+
if (value > 10)
|
|
16
|
+
digits = 0;
|
|
17
|
+
return value.toLocaleString(locale, { maximumFractionDigits: digits }) + ' ' + def[i - 1][1];
|
|
18
|
+
}
|
|
16
19
|
}
|
|
17
|
-
|
|
18
|
-
return '' // this is only for strict typing, but the code cannot go there, the return in the loop is always called
|
|
20
|
+
return ''; // this is only for strict typing, but the code cannot go there, the return in the loop is always called
|
|
19
21
|
}
|
|
20
|
-
export default formatBytes
|
|
22
|
+
export default formatBytes;
|
package/format/field.js
CHANGED
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
// TODO: use locale-dayjs for localization of date formats
|
|
2
|
-
import dayjs from 'dayjs'
|
|
3
|
-
export function formatField
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
import dayjs from 'dayjs';
|
|
3
|
+
export function formatField(item, field) {
|
|
4
|
+
const value = item[field.key];
|
|
5
|
+
if (value === undefined || value === null || value === '')
|
|
6
|
+
return '';
|
|
7
|
+
if (field['x-labels']?.['' + item[field.key]])
|
|
8
|
+
return field['x-labels']['' + item[field.key]];
|
|
9
|
+
if (field.type === 'number' || field.type === 'integer')
|
|
10
|
+
return value.toLocaleString('fr');
|
|
11
|
+
if (typeof value === 'boolean')
|
|
12
|
+
return value ? 'Oui' : 'Non';
|
|
13
|
+
if (typeof value === 'string') {
|
|
14
|
+
if (field['x-refersTo'] === 'http://schema.org/Date' ||
|
|
11
15
|
field['x-refersTo'] === 'https://schema.org/startDate' ||
|
|
12
16
|
field['x-refersTo'] === 'https://schema.org/endDate' ||
|
|
13
17
|
field['x-refersTo'] === 'http://schema.org/dateCreated') {
|
|
14
|
-
|
|
18
|
+
if (field.format === 'date-time')
|
|
19
|
+
return dayjs(value).format('DD/MM/YYYY, HH[h]mm');
|
|
20
|
+
else
|
|
21
|
+
return dayjs(value).format('DD/MM/YYYY');
|
|
22
|
+
}
|
|
15
23
|
}
|
|
16
|
-
|
|
17
|
-
return '' + value
|
|
24
|
+
return '' + value;
|
|
18
25
|
}
|
|
19
|
-
export function getFieldLabel
|
|
20
|
-
|
|
26
|
+
export function getFieldLabel(field) {
|
|
27
|
+
return field.title || field['x-originalName'] || field.key;
|
|
21
28
|
}
|
package/locale-dayjs.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { App } from 'vue';
|
|
2
2
|
import dayjs from 'dayjs';
|
|
3
|
-
import 'dayjs/locale/fr';
|
|
4
|
-
import 'dayjs/locale/en';
|
|
3
|
+
import 'dayjs/locale/fr.js';
|
|
4
|
+
import 'dayjs/locale/en.js';
|
|
5
5
|
import { CreateDurationType } from 'dayjs/plugin/duration.js';
|
|
6
6
|
export type { ConfigType as DayjsConfigType } from 'dayjs';
|
|
7
7
|
declare module 'dayjs' {
|
package/locale-dayjs.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { inject } from 'vue';
|
|
2
2
|
import dayjs from 'dayjs';
|
|
3
|
-
import 'dayjs/locale/fr';
|
|
4
|
-
import 'dayjs/locale/en';
|
|
3
|
+
import 'dayjs/locale/fr.js';
|
|
4
|
+
import 'dayjs/locale/en.js';
|
|
5
5
|
import localizedFormat from 'dayjs/plugin/localizedFormat.js';
|
|
6
6
|
import relativeTime from 'dayjs/plugin/relativeTime.js';
|
|
7
7
|
import duration from 'dayjs/plugin/duration.js';
|
package/package.json
CHANGED
package/session.d.ts
CHANGED
package/session.js
CHANGED