@mgdis/core-ui-helpers 1.2.2 → 1.3.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/dist/angular/index.cjs +27 -0
- package/dist/angular/index.cjs.map +1 -0
- package/dist/angular/index.d.ts +21 -0
- package/dist/angular/index.js +25 -0
- package/dist/angular/index.js.map +1 -0
- package/dist/angular/index.umd.js +33 -0
- package/dist/angular/index.umd.js.map +1 -0
- package/dist/locale/index.cjs +190 -0
- package/dist/locale/index.cjs.map +1 -0
- package/dist/locale/index.d.ts +110 -0
- package/dist/locale/index.js +181 -0
- package/dist/locale/index.js.map +1 -0
- package/dist/locale/index.umd.js +196 -0
- package/dist/locale/index.umd.js.map +1 -0
- package/dist/playwright/index.cjs +137 -0
- package/dist/playwright/index.cjs.map +1 -0
- package/dist/playwright/index.d.ts +39 -0
- package/dist/playwright/index.js +133 -0
- package/dist/playwright/index.js.map +1 -0
- package/dist/playwright/index.umd.js +143 -0
- package/dist/playwright/index.umd.js.map +1 -0
- package/dist/stencil/index.cjs +363 -0
- package/dist/stencil/index.cjs.map +1 -0
- package/dist/stencil/index.d.ts +222 -0
- package/dist/stencil/index.js +357 -0
- package/dist/stencil/index.js.map +1 -0
- package/dist/stencil/index.umd.js +369 -0
- package/dist/stencil/index.umd.js.map +1 -0
- package/dist/storybook/index.cjs +2335 -0
- package/dist/storybook/index.cjs.map +1 -0
- package/dist/storybook/index.d.ts +85 -0
- package/dist/storybook/index.js +2329 -0
- package/dist/storybook/index.js.map +1 -0
- package/dist/storybook/index.umd.js +2341 -0
- package/dist/storybook/index.umd.js.map +1 -0
- package/dist/tests/index.cjs +315 -0
- package/dist/tests/index.cjs.map +1 -0
- package/dist/tests/index.d.ts +100 -0
- package/dist/tests/index.js +309 -0
- package/dist/tests/index.js.map +1 -0
- package/dist/tests/index.umd.js +321 -0
- package/dist/tests/index.umd.js.map +1 -0
- package/dist/utils/index.cjs +441 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.ts +265 -0
- package/dist/utils/index.js +417 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.umd.js +447 -0
- package/dist/utils/index.umd.js.map +1 -0
- package/dist/vue/index.cjs +1935 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +35 -0
- package/dist/vue/index.js +1933 -0
- package/dist/vue/index.js.map +1 -0
- package/dist/vue/index.umd.js +1941 -0
- package/dist/vue/index.umd.js.map +1 -0
- package/package.json +4 -1
- package/CHANGELOG.md +0 -101
- package/json-doc.test.json +0 -264
- package/rollup.config.mjs +0 -61
- package/src/angular/index.spec.ts +0 -8
- package/src/angular/index.ts +0 -1
- package/src/angular/mg-angular-logger/index.ts +0 -1
- package/src/angular/mg-angular-logger/mg-angular-logger.conf.ts +0 -3
- package/src/angular/mg-angular-logger/mg-angular-logger.spec.ts +0 -40
- package/src/angular/mg-angular-logger/mg-angular-logger.ts +0 -24
- package/src/locale/index.spec.ts +0 -24
- package/src/locale/index.ts +0 -1
- package/src/locale/locale.spec.ts +0 -291
- package/src/locale/locale.ts +0 -201
- package/src/playwright/config/index.ts +0 -43
- package/src/playwright/index.spec.ts +0 -16
- package/src/playwright/index.ts +0 -4
- package/src/playwright/utils/__snapshots__/utils.spec.ts.snap +0 -48
- package/src/playwright/utils/index.ts +0 -1
- package/src/playwright/utils/utils.spec.ts +0 -50
- package/src/playwright/utils/utils.ts +0 -77
- package/src/stencil/ide/__snapshots__/cem.spec.ts.snap +0 -248
- package/src/stencil/ide/__snapshots__/ide.spec.ts.snap +0 -414
- package/src/stencil/ide/cem.spec.ts +0 -35
- package/src/stencil/ide/cem.ts +0 -96
- package/src/stencil/ide/ide.spec.ts +0 -29
- package/src/stencil/ide/ide.ts +0 -221
- package/src/stencil/ide/index.ts +0 -2
- package/src/stencil/index.spec.ts +0 -16
- package/src/stencil/index.ts +0 -2
- package/src/stencil/normalize-boolean-attributes/index.ts +0 -1
- package/src/stencil/normalize-boolean-attributes/normalize-boolean-attributes.spec.ts +0 -63
- package/src/stencil/normalize-boolean-attributes/normalize-boolean-attributes.ts +0 -40
- package/src/storybook/index.spec.ts +0 -19
- package/src/storybook/index.ts +0 -1
- package/src/storybook/stencil/__snapshots__/stencil.spec.ts.snap +0 -329
- package/src/storybook/stencil/index.ts +0 -1
- package/src/storybook/stencil/stencil-shim.d.ts +0 -1
- package/src/storybook/stencil/stencil.conf.ts +0 -4
- package/src/storybook/stencil/stencil.spec.ts +0 -170
- package/src/storybook/stencil/stencil.ts +0 -377
- package/src/tests/index.spec.ts +0 -20
- package/src/tests/index.ts +0 -1
- package/src/tests/unit/__snapshots__/unit.spec.ts.snap +0 -52
- package/src/tests/unit/index.ts +0 -1
- package/src/tests/unit/unit.conf.ts +0 -16
- package/src/tests/unit/unit.spec.ts +0 -206
- package/src/tests/unit/unit.ts +0 -333
- package/src/utils/attributes/class-list/class-list.spec.ts +0 -36
- package/src/utils/attributes/class-list/class-list.ts +0 -51
- package/src/utils/attributes/class-list/index.ts +0 -1
- package/src/utils/attributes/id/id.spec.ts +0 -54
- package/src/utils/attributes/id/id.ts +0 -47
- package/src/utils/attributes/id/index.ts +0 -1
- package/src/utils/attributes/index.ts +0 -3
- package/src/utils/attributes/to-kebab-case/index.ts +0 -1
- package/src/utils/attributes/to-kebab-case/to-kebab-case.spec.ts +0 -29
- package/src/utils/attributes/to-kebab-case/to-kebab-case.ts +0 -23
- package/src/utils/components/__snapshots__/components.spec.ts.snap +0 -313
- package/src/utils/components/components.conf.ts +0 -11
- package/src/utils/components/components.spec.ts +0 -192
- package/src/utils/components/components.ts +0 -152
- package/src/utils/components/index.ts +0 -2
- package/src/utils/date/date.spec.ts +0 -12
- package/src/utils/date/date.ts +0 -20
- package/src/utils/date/index.ts +0 -1
- package/src/utils/elements/elements.spec.ts +0 -17
- package/src/utils/elements/elements.ts +0 -18
- package/src/utils/elements/index.ts +0 -1
- package/src/utils/index.spec.ts +0 -84
- package/src/utils/index.ts +0 -8
- package/src/utils/number/index.ts +0 -1
- package/src/utils/number/number.spec.ts +0 -14
- package/src/utils/number/number.ts +0 -6
- package/src/utils/object/index.ts +0 -2
- package/src/utils/object/object.conf.ts +0 -4
- package/src/utils/object/object.spec.ts +0 -110
- package/src/utils/object/object.ts +0 -27
- package/src/utils/string/index.ts +0 -1
- package/src/utils/string/string.spec.ts +0 -54
- package/src/utils/string/string.ts +0 -39
- package/src/utils/windows/index.ts +0 -1
- package/src/utils/windows/windows.spec.ts +0 -69
- package/src/utils/windows/windows.ts +0 -50
- package/src/vue/index.spec.ts +0 -8
- package/src/vue/index.ts +0 -1
- package/src/vue/mg-model/index.ts +0 -1
- package/src/vue/mg-model/mg-model.conf.ts +0 -6
- package/src/vue/mg-model/mg-model.spec.ts +0 -50
- package/src/vue/mg-model/mg-model.ts +0 -55
- package/tsconfig.json +0 -17
- package/typedoc.json +0 -14
- package/vitest.config.mts +0 -13
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { ConfigType } from './mg-angular-logger.conf';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Set window logger custom rules for angular and mg-components
|
|
5
|
-
* @param config - logger configuration object
|
|
6
|
-
* @example
|
|
7
|
-
* ```js
|
|
8
|
-
* // main.js
|
|
9
|
-
* import { defineCustomElements } from '@mgdis/mg-components/loader';
|
|
10
|
-
* import { setMgAngularLogger } from '@mgdis/core-ui-helpers/dist/angular';
|
|
11
|
-
*
|
|
12
|
-
* // need to be set before `defineCustomElements` call
|
|
13
|
-
* setMgAngularLogger({level: 'error'});
|
|
14
|
-
* defineCustomElements();
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
export const setMgAngularLogger = (config: ConfigType = { level: 'log' }): void => {
|
|
18
|
-
const error = console.error;
|
|
19
|
-
console.error = (...args: unknown[]) => {
|
|
20
|
-
// filter error when it come from a mg-components component error
|
|
21
|
-
if (config.level === 'error' || !args.some((arg) => arg instanceof Error && arg.message.startsWith('<mg-')))
|
|
22
|
-
error.call(console, ...args);
|
|
23
|
-
};
|
|
24
|
-
};
|
package/src/locale/index.spec.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
defineLocales,
|
|
4
|
-
localeByte,
|
|
5
|
-
localeCurrency,
|
|
6
|
-
localeDate,
|
|
7
|
-
localeDatePattern,
|
|
8
|
-
localeNumber,
|
|
9
|
-
localePercent,
|
|
10
|
-
localeUnit,
|
|
11
|
-
} from '.';
|
|
12
|
-
|
|
13
|
-
describe('locale', () => {
|
|
14
|
-
test('import', () => {
|
|
15
|
-
expect(localeDatePattern).toBeDefined();
|
|
16
|
-
expect(localeCurrency).toBeDefined();
|
|
17
|
-
expect(localeNumber).toBeDefined();
|
|
18
|
-
expect(localePercent).toBeDefined();
|
|
19
|
-
expect(localeUnit).toBeDefined();
|
|
20
|
-
expect(localeDate).toBeDefined();
|
|
21
|
-
expect(localeByte).toBeDefined();
|
|
22
|
-
expect(defineLocales).toBeDefined();
|
|
23
|
-
});
|
|
24
|
-
});
|
package/src/locale/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './locale';
|
|
@@ -1,291 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
localeCurrency,
|
|
4
|
-
localeNumber,
|
|
5
|
-
localeDate,
|
|
6
|
-
localePercent,
|
|
7
|
-
localeUnit,
|
|
8
|
-
defineLocales,
|
|
9
|
-
localeDatePattern,
|
|
10
|
-
localeByte,
|
|
11
|
-
} from './locale';
|
|
12
|
-
|
|
13
|
-
const messagesFr = { lang: 'fr' };
|
|
14
|
-
const messagesEn = { lang: 'en' };
|
|
15
|
-
const messages = { en: messagesEn, fr: messagesFr };
|
|
16
|
-
|
|
17
|
-
describe('locale', () => {
|
|
18
|
-
describe.each(['en', 'fr'])('locale: %s', (locale) => {
|
|
19
|
-
describe('localeCurrency', () => {
|
|
20
|
-
test('Should Format number to the locale currency', () => {
|
|
21
|
-
const formatedCurrency = localeCurrency(1234567890.12, locale, 'EUR');
|
|
22
|
-
expect(formatedCurrency).toEqual(locale === 'en' ? '€1,234,567,890.12' : '1 234 567 890,12\xa0€');
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe('localeNumber', () => {
|
|
27
|
-
test('Should Format number to the locale', () => {
|
|
28
|
-
const formatedCurrency = localeNumber(1234567890.12, locale);
|
|
29
|
-
expect(formatedCurrency).toEqual(locale === 'en' ? '1,234,567,890.12' : '1 234 567 890,12');
|
|
30
|
-
});
|
|
31
|
-
test('Should Format number to the locale and manage 00 in decimal returned value', () => {
|
|
32
|
-
const formatedCurrency = localeNumber(1234567890, locale, 2);
|
|
33
|
-
expect(formatedCurrency).toEqual(locale === 'en' ? '1,234,567,890.00' : '1 234 567 890,00');
|
|
34
|
-
});
|
|
35
|
-
test.each([0, 5])(
|
|
36
|
-
'Should Format number to the locale and format the decimal length, case length %s',
|
|
37
|
-
(length) => {
|
|
38
|
-
const formatedCurrency = localeNumber(1234567890, locale, length);
|
|
39
|
-
const decimal = length > 0 ? '00000' : null;
|
|
40
|
-
const localePoint = locale === 'en' ? '.' : ',';
|
|
41
|
-
const integer = locale === 'en' ? '1,234,567,890' : '1 234 567 890';
|
|
42
|
-
expect(formatedCurrency).toEqual(integer + (decimal ? localePoint + decimal : ''));
|
|
43
|
-
}
|
|
44
|
-
);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
describe('localeDatePattern', () => {
|
|
48
|
-
test.each([
|
|
49
|
-
{ locale: 'fr', expected: 'dd/mm/yyyy' },
|
|
50
|
-
{ locale: 'en', expected: 'mm/dd/yyyy' },
|
|
51
|
-
])('Should get date pattern', ({ locale, expected }) => {
|
|
52
|
-
const pattern = localeDatePattern(locale);
|
|
53
|
-
expect(pattern).toEqual(expected);
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('localeDate', () => {
|
|
58
|
-
test.each([undefined, '', 'blu'])('Should return empty string: %s', (date) => {
|
|
59
|
-
const formatedDate = localeDate(date, locale);
|
|
60
|
-
expect(formatedDate).toEqual('');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('Should return formated date', () => {
|
|
64
|
-
const formatedDate = localeDate('2022-06-02', locale);
|
|
65
|
-
expect(formatedDate).toEqual(locale === 'en' ? '6/2/2022' : '02/06/2022');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('Should return formated date with given timeZone config', () => {
|
|
69
|
-
const formatedDate = localeDate('2022-06-02', locale, { timeZone: 'America/New_York' });
|
|
70
|
-
expect(formatedDate).toEqual(locale === 'en' ? '6/1/2022' : '01/06/2022');
|
|
71
|
-
});
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
describe('defineLocales', () => {
|
|
75
|
-
test('Should return navigator locale', () => {
|
|
76
|
-
const locales = defineLocales(messages, locale)(document.createElement('div'));
|
|
77
|
-
expect(locales.locale).toEqual('en-US');
|
|
78
|
-
expect(locales.messages).toMatchObject(messagesEn);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
test('Should return default locale', () => {
|
|
82
|
-
const navigatorBackup = window.navigator;
|
|
83
|
-
globalThis.window.navigator = {} as Navigator;
|
|
84
|
-
const locales = defineLocales(messages, locale)(document.createElement('div'));
|
|
85
|
-
expect(locales.locale).toEqual(locale);
|
|
86
|
-
expect(locales.messages).toMatchObject({ lang: locale });
|
|
87
|
-
|
|
88
|
-
// reset default navigator default value
|
|
89
|
-
globalThis.window.navigator = navigatorBackup;
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('Should return matching locale', () => {
|
|
93
|
-
const div = document.createElement('div');
|
|
94
|
-
div.lang = 'fr-FR';
|
|
95
|
-
const locales = defineLocales(messages, locale)(div);
|
|
96
|
-
expect(locales.locale).toEqual(div.lang);
|
|
97
|
-
expect(locales.messages).toMatchObject(messagesFr);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
test('Should return default locale messages when requested does not exist', () => {
|
|
101
|
-
const div = document.createElement('div');
|
|
102
|
-
div.lang = 'ca';
|
|
103
|
-
const locales = defineLocales(messages, locale)(div);
|
|
104
|
-
expect(locales.locale).toEqual(div.lang);
|
|
105
|
-
expect(locales.messages).toMatchObject({ lang: locale });
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
test('Should handle empty messages object', () => {
|
|
109
|
-
const div = document.createElement('div');
|
|
110
|
-
div.lang = 'fr';
|
|
111
|
-
const locales = defineLocales({}, 'en')(div);
|
|
112
|
-
expect(locales.locale).toEqual('fr');
|
|
113
|
-
expect(locales.messages).toMatchObject({ lang: 'en' });
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
test('Should return default object when messages and default locale are not found', () => {
|
|
117
|
-
const div = document.createElement('div');
|
|
118
|
-
div.lang = 'fr';
|
|
119
|
-
const locales = defineLocales({ it: { lang: 'it' } }, 'es')(div);
|
|
120
|
-
expect(locales.locale).toEqual('fr');
|
|
121
|
-
expect(locales.messages).toMatchObject({ lang: 'es' });
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
describe('localePercent', () => {
|
|
126
|
-
test.each([
|
|
127
|
-
[0.42, 'en', 2, '42.00%'],
|
|
128
|
-
[0.42, 'fr', 2, '42,00 %'],
|
|
129
|
-
[1.23, 'en', 1, '123.0%'],
|
|
130
|
-
[1.23, 'fr', 1, '123,0 %'],
|
|
131
|
-
[0, 'fr', 0, '0 %'],
|
|
132
|
-
[0, 'en', 0, '0%'],
|
|
133
|
-
[1, 'fr', 0, '100 %'],
|
|
134
|
-
[1, 'en', 0, '100%'],
|
|
135
|
-
[-0.5, 'fr', 2, '-50,00 %'],
|
|
136
|
-
[-0.5, 'en', 2, '-50.00%'],
|
|
137
|
-
[Number.POSITIVE_INFINITY, 'fr', 0, '∞ %'],
|
|
138
|
-
[Number.POSITIVE_INFINITY, 'en', 0, '∞%'],
|
|
139
|
-
[Number.NEGATIVE_INFINITY, 'fr', 0, '-∞ %'],
|
|
140
|
-
[Number.NEGATIVE_INFINITY, 'en', 0, '-∞%'],
|
|
141
|
-
[NaN, 'fr', 0, 'NaN %'],
|
|
142
|
-
[NaN, 'en', 0, 'NaN%'],
|
|
143
|
-
])('Should format %s value correctly for locale %s with %s decimals', (value, locale, decimals, expected) => {
|
|
144
|
-
const result = localePercent(value, locale, decimals);
|
|
145
|
-
// Normalize spaces before comparison
|
|
146
|
-
expect(result.replace(/\s/g, ' ')).toBe(expected.replace(/\s/g, ' '));
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test('Should handle undefined decimal length', () => {
|
|
150
|
-
expect(localePercent(0.42, 'fr').replace(/\s/g, ' ')).toBe('42 %'.replace(/\s/g, ' '));
|
|
151
|
-
expect(localePercent(0.42, 'en').replace(/\s/g, ' ')).toBe('42%'.replace(/\s/g, ' '));
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
describe('localeUnit', () => {
|
|
156
|
-
test.each([
|
|
157
|
-
[1234567890.12, 'fr', 'kilometer', 'short', 2, '1 234 567 890,12 km'],
|
|
158
|
-
[23, 'fr', 'celsius', 'short', 0, '23 °C'],
|
|
159
|
-
[10, 'fr', 'kilometer', 'long', 0, '10 kilomètres'],
|
|
160
|
-
[1234567890.12, 'en', 'kilometer', 'short', 2, '1,234,567,890.12 km'],
|
|
161
|
-
[23, 'en', 'celsius', 'short', 0, '23°C'],
|
|
162
|
-
[10, 'en', 'kilometer', 'long', 0, '10 kilometers'],
|
|
163
|
-
])(
|
|
164
|
-
'Should format %s value correctly for locale %s with unit %s',
|
|
165
|
-
(value, locale, unit, unitDisplay, decimals, expected) => {
|
|
166
|
-
const result = localeUnit(
|
|
167
|
-
value,
|
|
168
|
-
locale,
|
|
169
|
-
unit,
|
|
170
|
-
unitDisplay as Intl.NumberFormatOptions['unitDisplay'],
|
|
171
|
-
decimals
|
|
172
|
-
);
|
|
173
|
-
// Normalize spaces before comparison
|
|
174
|
-
expect(result.replace(/\s/g, ' ')).toBe(expected.replace(/\s/g, ' '));
|
|
175
|
-
}
|
|
176
|
-
);
|
|
177
|
-
|
|
178
|
-
test('Should respect decimal length', () => {
|
|
179
|
-
expect(localeUnit(1234.567, 'en', 'kilometer', 'short', 2).replace(/\s/g, ' ')).toBe(
|
|
180
|
-
'1,234.57 km'.replace(/\s/g, ' ')
|
|
181
|
-
);
|
|
182
|
-
expect(localeUnit(1234.567, 'fr', 'kilometer', 'short', 2).replace(/\s/g, ' ')).toBe(
|
|
183
|
-
'1 234,57 km'.replace(/\s/g, ' ')
|
|
184
|
-
);
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
test('Should use default unitDisplay and decimalLength when not provided', () => {
|
|
188
|
-
expect(localeUnit(1234, 'en', 'kilometer').replace(/\s/g, ' ')).toBe('1,234 km');
|
|
189
|
-
expect(localeUnit(1234, 'fr', 'kilometer').replace(/\s/g, ' ')).toBe('1 234 km');
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
test('Should use default unitDisplay when only decimalLength is provided', () => {
|
|
193
|
-
expect(localeUnit(1234.567, 'en', 'kilometer', undefined, 2).replace(/\s/g, ' ')).toBe('1,234.57 km');
|
|
194
|
-
expect(localeUnit(1234.567, 'fr', 'kilometer', undefined, 2).replace(/\s/g, ' ')).toBe('1 234,57 km');
|
|
195
|
-
});
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
describe('localeByte', () => {
|
|
199
|
-
test.each([
|
|
200
|
-
{
|
|
201
|
-
octets: 0,
|
|
202
|
-
expected: {
|
|
203
|
-
fr: '0\u00A0octet',
|
|
204
|
-
en: '0 bytes',
|
|
205
|
-
},
|
|
206
|
-
},
|
|
207
|
-
{
|
|
208
|
-
octets: 1,
|
|
209
|
-
expected: {
|
|
210
|
-
fr: '1\u00A0octet',
|
|
211
|
-
en: '1 byte',
|
|
212
|
-
},
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
octets: 500,
|
|
216
|
-
expected: {
|
|
217
|
-
fr: '500\u00A0octets',
|
|
218
|
-
en: '500 bytes',
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
{
|
|
222
|
-
octets: 1024,
|
|
223
|
-
expected: {
|
|
224
|
-
fr: '1\u202fko',
|
|
225
|
-
en: '1 kB',
|
|
226
|
-
},
|
|
227
|
-
},
|
|
228
|
-
{
|
|
229
|
-
octets: 1536,
|
|
230
|
-
expected: {
|
|
231
|
-
fr: '1,5\u202fko',
|
|
232
|
-
en: '1.5 kB',
|
|
233
|
-
},
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
octets: 1048576,
|
|
237
|
-
expected: {
|
|
238
|
-
fr: '1\u202fMo',
|
|
239
|
-
en: '1 MB',
|
|
240
|
-
},
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
octets: 1572864,
|
|
244
|
-
expected: {
|
|
245
|
-
fr: '1,5\u202fMo',
|
|
246
|
-
en: '1.5 MB',
|
|
247
|
-
},
|
|
248
|
-
},
|
|
249
|
-
{
|
|
250
|
-
octets: 1073741824,
|
|
251
|
-
expected: {
|
|
252
|
-
fr: '1\u202fGo',
|
|
253
|
-
en: '1 GB',
|
|
254
|
-
},
|
|
255
|
-
},
|
|
256
|
-
{
|
|
257
|
-
octets: 1610612736,
|
|
258
|
-
expected: {
|
|
259
|
-
fr: '1,5\u202fGo',
|
|
260
|
-
en: '1.5 GB',
|
|
261
|
-
},
|
|
262
|
-
},
|
|
263
|
-
{
|
|
264
|
-
octets: 1099511627776,
|
|
265
|
-
expected: {
|
|
266
|
-
fr: '1\u202fTo',
|
|
267
|
-
en: '1 TB',
|
|
268
|
-
},
|
|
269
|
-
},
|
|
270
|
-
{
|
|
271
|
-
octets: 1649267441664,
|
|
272
|
-
expected: {
|
|
273
|
-
fr: '1,5\u202fTo',
|
|
274
|
-
en: '1.5 TB',
|
|
275
|
-
},
|
|
276
|
-
},
|
|
277
|
-
])('Should format $octets octets to string', ({ octets, expected }) => {
|
|
278
|
-
const res = localeByte(octets, locale);
|
|
279
|
-
expect(res).toEqual(expected[locale as 'en' | 'fr']);
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
test('Should throw error with negative octets', () => {
|
|
283
|
-
expect(() => localeByte(-10, locale)).toThrowError('localeByte - size must be a positive number.');
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
test.each([undefined, null, NaN, []])('Should throw error with %s octets', (value) => {
|
|
287
|
-
expect(() => localeByte(value as number, locale)).toThrowError('localeByte - size must be a positive number.');
|
|
288
|
-
});
|
|
289
|
-
});
|
|
290
|
-
});
|
|
291
|
-
});
|
package/src/locale/locale.ts
DELETED
|
@@ -1,201 +0,0 @@
|
|
|
1
|
-
import { dateRegExp } from '../utils/date';
|
|
2
|
-
import type { ObjectType } from '../utils/object';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Gets the date pattern based on the specified locale.
|
|
6
|
-
* @param locale - the locale to refer to
|
|
7
|
-
* @returns date pattern
|
|
8
|
-
* @example
|
|
9
|
-
* ```ts
|
|
10
|
-
* localeDatePattern('fr') // 'dd/mm/yyyy'
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
|
-
export const localeDatePattern = (locale: string) => {
|
|
14
|
-
const year = { value: '2023', pattern: 'yyyy' };
|
|
15
|
-
const month = { value: '12', pattern: 'mm' };
|
|
16
|
-
const day = { value: '24', pattern: 'dd' };
|
|
17
|
-
return localeDate([year.value, month.value, day.value].join('-'), locale, { timeZone: 'UTC' })
|
|
18
|
-
.replace(year.value, year.pattern)
|
|
19
|
-
.replace(month.value, month.pattern)
|
|
20
|
-
.replace(day.value, day.pattern);
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Get locale and messages
|
|
25
|
-
* We load the defined locale but for now we only support the first subtag for messages
|
|
26
|
-
* @param element - element we need to get the language
|
|
27
|
-
* @param messages - messages to use
|
|
28
|
-
* @param defaultLocale - default messages locale
|
|
29
|
-
* @returns messages object
|
|
30
|
-
*/
|
|
31
|
-
const localeMessages = (
|
|
32
|
-
element: HTMLElement,
|
|
33
|
-
messages: ObjectType,
|
|
34
|
-
defaultLocale: string
|
|
35
|
-
): { locale: string; messages: ObjectType } => {
|
|
36
|
-
// Get local
|
|
37
|
-
const closestLangAttribute: HTMLElement | null = element.closest('[lang]');
|
|
38
|
-
const closestLang: string[] = Intl.NumberFormat.supportedLocalesOf(closestLangAttribute?.lang as string);
|
|
39
|
-
const locale =
|
|
40
|
-
closestLang.length > 0 && typeof closestLang[0] === 'string' ? closestLang[0] : navigator.language || defaultLocale;
|
|
41
|
-
// Only keep first subtag
|
|
42
|
-
const localeSubtag = locale.split('-').shift() as string;
|
|
43
|
-
|
|
44
|
-
// If messages is empty, return a default object
|
|
45
|
-
if (Object.keys(messages).length === 0) {
|
|
46
|
-
return {
|
|
47
|
-
locale,
|
|
48
|
-
messages: { lang: defaultLocale },
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Return
|
|
53
|
-
return {
|
|
54
|
-
locale,
|
|
55
|
-
messages: (messages[localeSubtag] ?? messages[defaultLocale] ?? { lang: defaultLocale }) as ObjectType,
|
|
56
|
-
};
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Format number to the locale currency
|
|
61
|
-
* @param number - number to format
|
|
62
|
-
* @param locale - locale to apply
|
|
63
|
-
* @param currency - currency to apply
|
|
64
|
-
* @returns formatted currency
|
|
65
|
-
* @example
|
|
66
|
-
* ```ts
|
|
67
|
-
* localeCurrency(1234567890.12, 'fr', 'EUR') // '1 234 567 890,12\xa0€'
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
export const localeCurrency = (number: number, locale: string, currency: string): string =>
|
|
71
|
-
new Intl.NumberFormat(locale, { style: 'currency', currency }).format(number);
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Format number to locale
|
|
75
|
-
* @param number - number to format
|
|
76
|
-
* @param locale - locale to apply
|
|
77
|
-
* @param decimalLength - decimal length to apply
|
|
78
|
-
* @returns formatted number
|
|
79
|
-
* @example
|
|
80
|
-
* ```ts
|
|
81
|
-
* localeNumber(1234567890.12, 'fr') // 1 234 567 890,12
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
export const localeNumber = (number: number, locale: string, decimalLength: number = 0): string =>
|
|
85
|
-
new Intl.NumberFormat(locale, { minimumFractionDigits: decimalLength }).format(Number(number));
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Convert bytes number to locale string representation
|
|
89
|
-
* @param number - size in bytes
|
|
90
|
-
* @param locale - locale to apply
|
|
91
|
-
* @returns bytes in locale string format
|
|
92
|
-
*/
|
|
93
|
-
export const localeByte = (number: number, locale: string): string => {
|
|
94
|
-
if (typeof number !== 'number' || Number.isNaN(number) || number < 0) {
|
|
95
|
-
throw new Error('localeByte - size must be a positive number.');
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
const base = 1024;
|
|
99
|
-
const units: string[] = ['byte', 'kilobyte', 'megabyte', 'gigabyte', 'terabyte'];
|
|
100
|
-
|
|
101
|
-
// find appropriate unit base on size and base power
|
|
102
|
-
const unitIndex = units.findIndex((_, key) => number < Math.pow(base, key + 1));
|
|
103
|
-
|
|
104
|
-
// convert number to string with unit
|
|
105
|
-
return Intl.NumberFormat(locale, {
|
|
106
|
-
minimumFractionDigits: 0,
|
|
107
|
-
maximumFractionDigits: 2,
|
|
108
|
-
unit: units[unitIndex],
|
|
109
|
-
unitDisplay: units[unitIndex] === 'byte' ? 'long' : 'short',
|
|
110
|
-
style: 'unit',
|
|
111
|
-
}).format(number / Math.pow(base, unitIndex));
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Format number as percentage based on locale
|
|
116
|
-
* @param number - number to format
|
|
117
|
-
* @param locale - locale to apply
|
|
118
|
-
* @param decimalLength - decimal length to apply
|
|
119
|
-
* @returns formatted percentage
|
|
120
|
-
* @example
|
|
121
|
-
* ```ts
|
|
122
|
-
* localePercent(0.42, 'fr', 2) // '42,00 %'
|
|
123
|
-
* localePercent(0.42, 'en', 2) // '42.00%'
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
export const localePercent = (number: number, locale: string, decimalLength: number = 0): string => {
|
|
127
|
-
return new Intl.NumberFormat(locale, {
|
|
128
|
-
style: 'percent',
|
|
129
|
-
minimumFractionDigits: decimalLength,
|
|
130
|
-
maximumFractionDigits: decimalLength,
|
|
131
|
-
}).format(number);
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Format number with standardized unit based on locale using Intl unit formatting
|
|
136
|
-
* @param number - number to format
|
|
137
|
-
* @param locale - locale to apply
|
|
138
|
-
* @param unit - standardized unit (e.g., 'kilometer', 'kilogram', 'celsius')
|
|
139
|
-
* @param unitDisplay - how to display the unit ('short', 'long', 'narrow')
|
|
140
|
-
* @param decimalLength - decimal length to apply
|
|
141
|
-
* @returns formatted number with localized unit
|
|
142
|
-
* @example
|
|
143
|
-
* ```ts
|
|
144
|
-
* localeUnit(1234567890.12, 'fr', 'kilometer') // '1 234 567 890,12 km'
|
|
145
|
-
* localeUnit(23, 'fr', 'celsius') // '23 °C'
|
|
146
|
-
* localeUnit(10, 'fr', 'kilometer', 0, 'long') // '10 kilomètres'
|
|
147
|
-
* ```
|
|
148
|
-
*/
|
|
149
|
-
export const localeUnit = (
|
|
150
|
-
number: number,
|
|
151
|
-
locale: string,
|
|
152
|
-
unit: Intl.NumberFormatOptions['unit'],
|
|
153
|
-
unitDisplay: Intl.NumberFormatOptions['unitDisplay'] = 'short',
|
|
154
|
-
decimalLength: number = 0
|
|
155
|
-
): string => {
|
|
156
|
-
return new Intl.NumberFormat(locale, {
|
|
157
|
-
style: 'unit',
|
|
158
|
-
unit,
|
|
159
|
-
unitDisplay,
|
|
160
|
-
minimumFractionDigits: decimalLength,
|
|
161
|
-
maximumFractionDigits: decimalLength,
|
|
162
|
-
}).format(number);
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Locale date format
|
|
167
|
-
* @param date - date to format
|
|
168
|
-
* @param locale - locale to apply
|
|
169
|
-
* @param config - DateTimeFormatOptions object to apply
|
|
170
|
-
* @returns formatted date
|
|
171
|
-
* @example
|
|
172
|
-
* ```ts
|
|
173
|
-
* localeDate('2022-06-02', 'fr') // '02/06/2022'
|
|
174
|
-
* ```
|
|
175
|
-
*/
|
|
176
|
-
export const localeDate = (date: string | undefined, locale: string, config?: Intl.DateTimeFormatOptions): string =>
|
|
177
|
-
typeof date !== 'string' || date === '' || !dateRegExp.test(date)
|
|
178
|
-
? ''
|
|
179
|
-
: new Intl.DateTimeFormat(locale, config).format(new Date(date));
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Get Intl object
|
|
183
|
-
* @param messages - locales to render in object format. `ex: { en: { porp: "test" }, fr: { porp: "test" }}`.
|
|
184
|
-
* @param defaultLocale - fallback locale to render. `ex: 'en'`.
|
|
185
|
-
* @returns from the element passed in return function you will get the matching messages object
|
|
186
|
-
* @example
|
|
187
|
-
* ```ts
|
|
188
|
-
* import en from './en/messages.json';
|
|
189
|
-
* import fr from './fr/messages.json';
|
|
190
|
-
* import { defineLocales } from '@mgdis/core-ui-helpers/dist/utils';
|
|
191
|
-
*
|
|
192
|
-
* const defaultLocale = 'en';
|
|
193
|
-
* const messages = { en, fr };
|
|
194
|
-
*
|
|
195
|
-
* export const initLocales = defineLocales(messages, defaultLocale);
|
|
196
|
-
* ```
|
|
197
|
-
*/
|
|
198
|
-
export const defineLocales =
|
|
199
|
-
(messages: ObjectType, defaultLocale: 'fr' | 'en') =>
|
|
200
|
-
(element: HTMLElement): { locale: string; messages: ObjectType } =>
|
|
201
|
-
localeMessages(element, messages, defaultLocale);
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { type PlaywrightTestConfig } from '@playwright/test';
|
|
2
|
-
|
|
3
|
-
const config: PlaywrightTestConfig = {
|
|
4
|
-
testMatch: '*.e2e.ts',
|
|
5
|
-
snapshotPathTemplate: '{testFileDir}/__screenshots__/{arg}-{projectName}{ext}',
|
|
6
|
-
/* Maximum time one test can run for. */
|
|
7
|
-
timeout: 30 * 1000,
|
|
8
|
-
expect: {
|
|
9
|
-
/**
|
|
10
|
-
* Maximum time expect() should wait for the condition to be met.
|
|
11
|
-
* For example in `await expect(locator).toHaveText();`
|
|
12
|
-
*/
|
|
13
|
-
timeout: 5000,
|
|
14
|
-
},
|
|
15
|
-
/* Run tests in files in parallel */
|
|
16
|
-
fullyParallel: true,
|
|
17
|
-
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
|
18
|
-
forbidOnly: !!process.env.CI,
|
|
19
|
-
/* Retry on CI only */
|
|
20
|
-
retries: process.env.CI ? 2 : 0,
|
|
21
|
-
/* Stop on CI on first failure */
|
|
22
|
-
maxFailures: process.env.CI ? 1 : 0,
|
|
23
|
-
/* Opt out of parallel tests on CI. */
|
|
24
|
-
workers: process.env.CI ? 1 : undefined,
|
|
25
|
-
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
|
26
|
-
reporter: [
|
|
27
|
-
['html', { open: 'never' }],
|
|
28
|
-
['junit', { outputFile: 'results.xml' }],
|
|
29
|
-
],
|
|
30
|
-
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
|
31
|
-
use: {
|
|
32
|
-
headless: true,
|
|
33
|
-
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
|
|
34
|
-
actionTimeout: 0,
|
|
35
|
-
/* Base URL to use in actions like `await page.goto('/')`. */
|
|
36
|
-
// baseURL: 'http://localhost:3000',
|
|
37
|
-
|
|
38
|
-
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
|
39
|
-
trace: 'on-first-retry',
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export default config;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { describe, expect, test } from 'vitest';
|
|
2
|
-
import { playwrightBaseConfig, renderAttributes, renderProperties } from '.';
|
|
3
|
-
|
|
4
|
-
describe('playwright', () => {
|
|
5
|
-
describe('config', () => {
|
|
6
|
-
test('import', () => {
|
|
7
|
-
expect(playwrightBaseConfig).toBeDefined();
|
|
8
|
-
});
|
|
9
|
-
});
|
|
10
|
-
describe('utils', () => {
|
|
11
|
-
test('import', () => {
|
|
12
|
-
expect(renderAttributes).toBeDefined();
|
|
13
|
-
expect(renderProperties).toBeDefined();
|
|
14
|
-
});
|
|
15
|
-
});
|
|
16
|
-
});
|
package/src/playwright/index.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
-
|
|
3
|
-
exports[`utils > renderAttributes > Should render attributes 1`] = `""`;
|
|
4
|
-
|
|
5
|
-
exports[`utils > renderAttributes > Should render attributes 2`] = `""`;
|
|
6
|
-
|
|
7
|
-
exports[`utils > renderAttributes > Should render attributes 3`] = `""`;
|
|
8
|
-
|
|
9
|
-
exports[`utils > renderAttributes > Should render attributes 4`] = `"name="batman""`;
|
|
10
|
-
|
|
11
|
-
exports[`utils > renderAttributes > Should render attributes 5`] = `"name="<div class='blu'>blu</div>""`;
|
|
12
|
-
|
|
13
|
-
exports[`utils > renderAttributes > Should render attributes 6`] = `"name="batman" user="bruce" active="" id="1""`;
|
|
14
|
-
|
|
15
|
-
exports[`utils > renderAttributes > Should render attributes 7`] = `"empty-string="""`;
|
|
16
|
-
|
|
17
|
-
exports[`utils > renderAttributes > Should render attributes 8`] = `"name="0""`;
|
|
18
|
-
|
|
19
|
-
exports[`utils > renderAttributes > Should render attributes 9`] = `""`;
|
|
20
|
-
|
|
21
|
-
exports[`utils > renderAttributes > Should render attributes 10`] = `"name="""`;
|
|
22
|
-
|
|
23
|
-
exports[`utils > renderAttributes > Should render attributes 11`] = `""`;
|
|
24
|
-
|
|
25
|
-
exports[`utils > renderAttributes > Should render attributes 12`] = `""`;
|
|
26
|
-
|
|
27
|
-
exports[`utils > renderAttributes > Should render attributes 13`] = `""`;
|
|
28
|
-
|
|
29
|
-
exports[`utils > renderProperties > Should not render attributes as properties 1`] = `""`;
|
|
30
|
-
|
|
31
|
-
exports[`utils > renderProperties > Should not render attributes as properties 2`] = `""`;
|
|
32
|
-
|
|
33
|
-
exports[`utils > renderProperties > Should not render attributes as properties 3`] = `""`;
|
|
34
|
-
|
|
35
|
-
exports[`utils > renderProperties > Should not render attributes as properties 4`] = `
|
|
36
|
-
"
|
|
37
|
-
;"
|
|
38
|
-
`;
|
|
39
|
-
|
|
40
|
-
exports[`utils > renderProperties > Should render properties, case id selector 1`] = `
|
|
41
|
-
"
|
|
42
|
-
document.querySelector('div').object={};document.querySelector('div').array=[];"
|
|
43
|
-
`;
|
|
44
|
-
|
|
45
|
-
exports[`utils > renderProperties > Should render properties, case id selector 2`] = `
|
|
46
|
-
"
|
|
47
|
-
document.querySelector('div').object={};document.querySelector('div').array=[];document.querySelector('div').fn=() => {};"
|
|
48
|
-
`;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './utils';
|