@mgdis/core-ui-helpers 1.0.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/.turbo/turbo-build.log +52 -0
- package/CHANGELOG.md +12 -0
- package/LICENSE +29 -0
- package/README.md +95 -0
- 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 +164 -0
- package/dist/locale/index.cjs.map +1 -0
- package/dist/locale/index.d.ts +103 -0
- package/dist/locale/index.js +156 -0
- package/dist/locale/index.js.map +1 -0
- package/dist/locale/index.umd.js +170 -0
- package/dist/locale/index.umd.js.map +1 -0
- package/dist/playwright/index.cjs +124 -0
- package/dist/playwright/index.cjs.map +1 -0
- package/dist/playwright/index.d.ts +35 -0
- package/dist/playwright/index.js +120 -0
- package/dist/playwright/index.js.map +1 -0
- package/dist/playwright/index.umd.js +130 -0
- package/dist/playwright/index.umd.js.map +1 -0
- package/dist/stencil/index.cjs +281 -0
- package/dist/stencil/index.cjs.map +1 -0
- package/dist/stencil/index.d.ts +111 -0
- package/dist/stencil/index.js +277 -0
- package/dist/stencil/index.js.map +1 -0
- package/dist/stencil/index.umd.js +287 -0
- package/dist/stencil/index.umd.js.map +1 -0
- package/dist/storybook/index.cjs +2109 -0
- package/dist/storybook/index.cjs.map +1 -0
- package/dist/storybook/index.d.ts +85 -0
- package/dist/storybook/index.js +2103 -0
- package/dist/storybook/index.js.map +1 -0
- package/dist/storybook/index.umd.js +2115 -0
- package/dist/storybook/index.umd.js.map +1 -0
- package/dist/tests/index.cjs +166 -0
- package/dist/tests/index.cjs.map +1 -0
- package/dist/tests/index.d.ts +91 -0
- package/dist/tests/index.js +161 -0
- package/dist/tests/index.js.map +1 -0
- package/dist/tests/index.umd.js +172 -0
- package/dist/tests/index.umd.js.map +1 -0
- package/dist/utils/index.cjs +433 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.ts +265 -0
- package/dist/utils/index.js +409 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/index.umd.js +439 -0
- package/dist/utils/index.umd.js.map +1 -0
- package/dist/vue/index.cjs +1934 -0
- package/dist/vue/index.cjs.map +1 -0
- package/dist/vue/index.d.ts +35 -0
- package/dist/vue/index.js +1932 -0
- package/dist/vue/index.js.map +1 -0
- package/dist/vue/index.umd.js +1940 -0
- package/dist/vue/index.umd.js.map +1 -0
- package/json-doc.test.json +253 -0
- package/package.json +80 -0
- package/rollup.config.mjs +61 -0
- package/src/angular/index.spec.ts +8 -0
- package/src/angular/index.ts +1 -0
- package/src/angular/mg-angular-logger/index.ts +1 -0
- package/src/angular/mg-angular-logger/mg-angular-logger.conf.ts +3 -0
- package/src/angular/mg-angular-logger/mg-angular-logger.spec.ts +40 -0
- package/src/angular/mg-angular-logger/mg-angular-logger.ts +23 -0
- package/src/locale/index.spec.ts +14 -0
- package/src/locale/index.ts +1 -0
- package/src/locale/locale.spec.ts +173 -0
- package/src/locale/locale.ts +166 -0
- package/src/playwright/config/index.ts +43 -0
- package/src/playwright/index.spec.ts +16 -0
- package/src/playwright/index.ts +4 -0
- package/src/playwright/utils/__snapshots__/utils.spec.ts.snap +48 -0
- package/src/playwright/utils/index.ts +1 -0
- package/src/playwright/utils/utils.spec.ts +43 -0
- package/src/playwright/utils/utils.ts +64 -0
- package/src/stencil/ide/__snapshots__/ide.spec.ts.snap +527 -0
- package/src/stencil/ide/ide.spec.ts +25 -0
- package/src/stencil/ide/ide.ts +214 -0
- package/src/stencil/ide/index.ts +1 -0
- package/src/stencil/index.spec.ts +12 -0
- package/src/stencil/index.ts +1 -0
- package/src/storybook/index.spec.ts +15 -0
- package/src/storybook/index.ts +1 -0
- package/src/storybook/stencil/__snapshots__/stencil.spec.ts.snap +329 -0
- package/src/storybook/stencil/index.ts +1 -0
- package/src/storybook/stencil/stencil-shim.d.ts +1 -0
- package/src/storybook/stencil/stencil.conf.ts +4 -0
- package/src/storybook/stencil/stencil.spec.ts +142 -0
- package/src/storybook/stencil/stencil.ts +366 -0
- package/src/tests/index.spec.ts +13 -0
- package/src/tests/index.ts +1 -0
- package/src/tests/unit/__snapshots__/unit.spec.ts.snap +52 -0
- package/src/tests/unit/index.ts +1 -0
- package/src/tests/unit/unit.conf.ts +9 -0
- package/src/tests/unit/unit.spec.ts +44 -0
- package/src/tests/unit/unit.ts +171 -0
- package/src/utils/attributes/class-list/class-list.spec.ts +36 -0
- package/src/utils/attributes/class-list/class-list.ts +51 -0
- package/src/utils/attributes/class-list/index.ts +1 -0
- package/src/utils/attributes/id/id.spec.ts +51 -0
- package/src/utils/attributes/id/id.ts +46 -0
- package/src/utils/attributes/id/index.ts +1 -0
- package/src/utils/attributes/index.ts +3 -0
- package/src/utils/attributes/to-kebab-case/index.ts +1 -0
- package/src/utils/attributes/to-kebab-case/to-kebab-case.spec.ts +29 -0
- package/src/utils/attributes/to-kebab-case/to-kebab-case.ts +23 -0
- package/src/utils/components/__snapshots__/components.spec.ts.snap +313 -0
- package/src/utils/components/components.conf.ts +11 -0
- package/src/utils/components/components.spec.ts +192 -0
- package/src/utils/components/components.ts +138 -0
- package/src/utils/components/index.ts +2 -0
- package/src/utils/date/date.spec.ts +12 -0
- package/src/utils/date/date.ts +20 -0
- package/src/utils/date/index.ts +1 -0
- package/src/utils/elements/elements.spec.ts +17 -0
- package/src/utils/elements/elements.ts +16 -0
- package/src/utils/elements/index.ts +1 -0
- package/src/utils/index.spec.ts +84 -0
- package/src/utils/index.ts +8 -0
- package/src/utils/number/index.ts +1 -0
- package/src/utils/number/number.spec.ts +14 -0
- package/src/utils/number/number.ts +6 -0
- package/src/utils/object/index.ts +2 -0
- package/src/utils/object/object.conf.ts +4 -0
- package/src/utils/object/object.spec.ts +98 -0
- package/src/utils/object/object.ts +26 -0
- package/src/utils/string/index.ts +1 -0
- package/src/utils/string/string.spec.ts +47 -0
- package/src/utils/string/string.ts +38 -0
- package/src/utils/windows/index.ts +1 -0
- package/src/utils/windows/windows.spec.ts +65 -0
- package/src/utils/windows/windows.ts +50 -0
- package/src/vue/index.spec.ts +8 -0
- package/src/vue/index.ts +1 -0
- package/src/vue/mg-model/index.ts +1 -0
- package/src/vue/mg-model/mg-model.conf.ts +6 -0
- package/src/vue/mg-model/mg-model.spec.ts +50 -0
- package/src/vue/mg-model/mg-model.ts +50 -0
- package/tsconfig.json +17 -0
- package/typedoc.json +14 -0
- package/vitest.config.mts +13 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
|
|
2
|
+
> @mgdis/core-ui-helpers@1.0.0 build /builds/core/core-ui/core-ui/packages/helpers
|
|
3
|
+
> rollup -c ./rollup.config.mjs
|
|
4
|
+
|
|
5
|
+
[36m
|
|
6
|
+
[1msrc/angular/index.ts[22m → [1mdist/angular/index.js, dist/angular/index.cjs, dist/angular/index.umd.js[22m...[39m
|
|
7
|
+
[32mcreated [1mdist/angular/index.js, dist/angular/index.cjs, dist/angular/index.umd.js[22m in [1m5s[22m[39m
|
|
8
|
+
[36m
|
|
9
|
+
[1msrc/angular/index.ts[22m → [1mdist/angular/index.d.ts[22m...[39m
|
|
10
|
+
[32mcreated [1mdist/angular/index.d.ts[22m in [1m2s[22m[39m
|
|
11
|
+
[36m
|
|
12
|
+
[1msrc/locale/index.ts[22m → [1mdist/locale/index.js, dist/locale/index.cjs, dist/locale/index.umd.js[22m...[39m
|
|
13
|
+
[32mcreated [1mdist/locale/index.js, dist/locale/index.cjs, dist/locale/index.umd.js[22m in [1m2.9s[22m[39m
|
|
14
|
+
[36m
|
|
15
|
+
[1msrc/locale/index.ts[22m → [1mdist/locale/index.d.ts[22m...[39m
|
|
16
|
+
[32mcreated [1mdist/locale/index.d.ts[22m in [1m1.1s[22m[39m
|
|
17
|
+
[36m
|
|
18
|
+
[1msrc/playwright/index.ts[22m → [1mdist/playwright/index.js, dist/playwright/index.cjs, dist/playwright/index.umd.js[22m...[39m
|
|
19
|
+
[32mcreated [1mdist/playwright/index.js, dist/playwright/index.cjs, dist/playwright/index.umd.js[22m in [1m3.3s[22m[39m
|
|
20
|
+
[36m
|
|
21
|
+
[1msrc/playwright/index.ts[22m → [1mdist/playwright/index.d.ts[22m...[39m
|
|
22
|
+
[32mcreated [1mdist/playwright/index.d.ts[22m in [1m1.1s[22m[39m
|
|
23
|
+
[36m
|
|
24
|
+
[1msrc/stencil/index.ts[22m → [1mdist/stencil/index.js, dist/stencil/index.cjs, dist/stencil/index.umd.js[22m...[39m
|
|
25
|
+
[32mcreated [1mdist/stencil/index.js, dist/stencil/index.cjs, dist/stencil/index.umd.js[22m in [1m3s[22m[39m
|
|
26
|
+
[36m
|
|
27
|
+
[1msrc/stencil/index.ts[22m → [1mdist/stencil/index.d.ts[22m...[39m
|
|
28
|
+
[32mcreated [1mdist/stencil/index.d.ts[22m in [1m1s[22m[39m
|
|
29
|
+
[36m
|
|
30
|
+
[1msrc/storybook/index.ts[22m → [1mdist/storybook/index.js, dist/storybook/index.cjs, dist/storybook/index.umd.js[22m...[39m
|
|
31
|
+
[32mcreated [1mdist/storybook/index.js, dist/storybook/index.cjs, dist/storybook/index.umd.js[22m in [1m2.5s[22m[39m
|
|
32
|
+
[36m
|
|
33
|
+
[1msrc/storybook/index.ts[22m → [1mdist/storybook/index.d.ts[22m...[39m
|
|
34
|
+
[32mcreated [1mdist/storybook/index.d.ts[22m in [1m1.2s[22m[39m
|
|
35
|
+
[36m
|
|
36
|
+
[1msrc/tests/index.ts[22m → [1mdist/tests/index.js, dist/tests/index.cjs, dist/tests/index.umd.js[22m...[39m
|
|
37
|
+
[32mcreated [1mdist/tests/index.js, dist/tests/index.cjs, dist/tests/index.umd.js[22m in [1m2.8s[22m[39m
|
|
38
|
+
[36m
|
|
39
|
+
[1msrc/tests/index.ts[22m → [1mdist/tests/index.d.ts[22m...[39m
|
|
40
|
+
[32mcreated [1mdist/tests/index.d.ts[22m in [1m1s[22m[39m
|
|
41
|
+
[36m
|
|
42
|
+
[1msrc/utils/index.ts[22m → [1mdist/utils/index.js, dist/utils/index.cjs, dist/utils/index.umd.js[22m...[39m
|
|
43
|
+
[32mcreated [1mdist/utils/index.js, dist/utils/index.cjs, dist/utils/index.umd.js[22m in [1m2.9s[22m[39m
|
|
44
|
+
[36m
|
|
45
|
+
[1msrc/utils/index.ts[22m → [1mdist/utils/index.d.ts[22m...[39m
|
|
46
|
+
[32mcreated [1mdist/utils/index.d.ts[22m in [1m1.3s[22m[39m
|
|
47
|
+
[36m
|
|
48
|
+
[1msrc/vue/index.ts[22m → [1mdist/vue/index.js, dist/vue/index.cjs, dist/vue/index.umd.js[22m...[39m
|
|
49
|
+
[32mcreated [1mdist/vue/index.js, dist/vue/index.cjs, dist/vue/index.umd.js[22m in [1m2.7s[22m[39m
|
|
50
|
+
[36m
|
|
51
|
+
[1msrc/vue/index.ts[22m → [1mdist/vue/index.d.ts[22m...[39m
|
|
52
|
+
[32mcreated [1mdist/vue/index.d.ts[22m in [1m1.1s[22m[39m
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# @mgdis/core-ui-helpers
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- 10c6605: Helper package release.
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 3c89e9d: replace @mgdis/mg-components-helpers @mgdis/playwright-helpers and @mgdis/stencil-helpers dependences by @mgdis/core-ui-helpers
|
|
12
|
+
- b816cca: Update dependencies
|
package/LICENSE
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022, MGDIS
|
|
4
|
+
All rights reserved.
|
|
5
|
+
|
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
|
8
|
+
|
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
10
|
+
list of conditions and the following disclaimer.
|
|
11
|
+
|
|
12
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
|
14
|
+
and/or other materials provided with the distribution.
|
|
15
|
+
|
|
16
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
17
|
+
contributors may be used to endorse or promote products derived from
|
|
18
|
+
this software without specific prior written permission.
|
|
19
|
+
|
|
20
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
21
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
22
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
23
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
24
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
25
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
26
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
27
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
28
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
29
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# @mgdis/core-ui-helpers
|
|
2
|
+
|
|
3
|
+
This package centralizes helper functions to solve the commons needs to build, test and use MGDIS design system components.
|
|
4
|
+
|
|
5
|
+
It can be used in [Stencil](https://stenciljs.com/), [vueJS@2|3](https://vuejs.org/) and [angularJS](https://angularjs.org/) projects with javascript/NodeJS standards (CJS,UMD,MJS) moderne bundlers: [ViteJS](https://vitejs.fr/), [Webpack](https://webpack.js.org/).
|
|
6
|
+
|
|
7
|
+
It is divided into six thematic sections:
|
|
8
|
+
|
|
9
|
+
- **Angular**: Centralizes all angular utilities.
|
|
10
|
+
- **Playwright**: Centralizes all playwright utilities to simplify e2e testing.
|
|
11
|
+
- **Stencil**: Centralizes all stencil utilities to simplify components creation.
|
|
12
|
+
- **Storybook**: Centralizes all Storybook helpers useful for building your own Storybook.
|
|
13
|
+
- **Utils**: Centralizes all utilities.
|
|
14
|
+
- **Vue**: Centralizes all vue utilities to simplify components creation.
|
|
15
|
+
|
|
16
|
+
## Requirements
|
|
17
|
+
|
|
18
|
+
**NodeJS v14.x or higher.**
|
|
19
|
+
**Webpack@5 or higher or viteJS bundler or UMD support.**
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
1. Package Manager
|
|
24
|
+
|
|
25
|
+
```shell
|
|
26
|
+
pnpm add @mgdis/core-ui-helpers
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
2. Select JS format
|
|
30
|
+
|
|
31
|
+
**Recommendation**
|
|
32
|
+
|
|
33
|
+
For ESM and CJS imports, it is highly recommended to target the import from the desired helper documentation to benefit from the bundler's tree-shaking optimization.
|
|
34
|
+
|
|
35
|
+
**ES Module**
|
|
36
|
+
|
|
37
|
+
Mostly used with ViteJS and Webpack Bundler.
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
// Use in angular project
|
|
41
|
+
import CoreUiHelpers from '@mgdis/core-ui-helpers/dist/angular';
|
|
42
|
+
// Use of locales in project
|
|
43
|
+
import CoreUiHelpers from '@mgdis/core-ui-helpers/dist/locales';
|
|
44
|
+
// Use in playwright project
|
|
45
|
+
import CoreUiHelpers from '@mgdis/core-ui-helpers/dist/playwright';
|
|
46
|
+
// Use in Stencil project
|
|
47
|
+
import CoreUiHelpers from '@mgdis/core-ui-helpers/dist/stencil';
|
|
48
|
+
// Use in storybook project
|
|
49
|
+
import CoreUiHelpers from '@mgdis/core-ui-helpers/dist/storybook';
|
|
50
|
+
// Use of tests in project
|
|
51
|
+
import CoreUiHelpers from '@mgdis/core-ui-helpers/dist/tests';
|
|
52
|
+
// Use of utils in project
|
|
53
|
+
import CoreUiHelpers from '@mgdis/core-ui-helpers/dist/utils';
|
|
54
|
+
// Use in VUE project
|
|
55
|
+
import CoreUiHelpers from '@mgdis/core-ui-helpers/dist/vue';
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
**CommonJS**
|
|
59
|
+
|
|
60
|
+
Mostly used with bundler wich doesn't support ES Module.
|
|
61
|
+
|
|
62
|
+
```js
|
|
63
|
+
// Use in angular project
|
|
64
|
+
const CoreUiHelpers = require('@mgdis/core-ui-helpers/dist/angular');
|
|
65
|
+
// Use of locales in project
|
|
66
|
+
const CoreUiHelpers = require('@mgdis/core-ui-helpers/dist/locales');
|
|
67
|
+
// Use in playwright project
|
|
68
|
+
const CoreUiHelpers = require('@mgdis/core-ui-helpers/dist/playwright');
|
|
69
|
+
// Use in Stencil project
|
|
70
|
+
const CoreUiHelpers = require('@mgdis/core-ui-helpers/dist/stencil');
|
|
71
|
+
// Use in storybook project
|
|
72
|
+
const CoreUiHelpers = require('@mgdis/core-ui-helpers/dist/storybook');
|
|
73
|
+
// Use of tests in project
|
|
74
|
+
const CoreUiHelpers = require('@mgdis/core-ui-helpers/dist/tests');
|
|
75
|
+
// Use of utils in project
|
|
76
|
+
const CoreUiHelpers = require('@mgdis/core-ui-helpers/dist/utils');
|
|
77
|
+
// Use in VUE project
|
|
78
|
+
const CoreUiHelpers = require('@mgdis/core-ui-helpers/dist/vue');
|
|
79
|
+
...
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
**UMD**
|
|
83
|
+
|
|
84
|
+
Mostly used when your project doesn't have a bundler but uses scripts to compile project sources (e.g., gulp).
|
|
85
|
+
|
|
86
|
+
```html
|
|
87
|
+
<!-- Use in angular project -->
|
|
88
|
+
<script src="/node_modules/@mgdis/core-ui-helpers/dist/angular/index.umd.js"></script>
|
|
89
|
+
<script>
|
|
90
|
+
// Disable some console error
|
|
91
|
+
CoreUiHelpers.angular.setMgAngularLogger({ level: 'log' });
|
|
92
|
+
</script>
|
|
93
|
+
<!-- Use in VUE project -->
|
|
94
|
+
<script src="/node_modules/@mgdis/core-ui-helpers/dist/vue/index.umd.js"></script>
|
|
95
|
+
```
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
'use strict';
|
|
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
|
+
const setMgAngularLogger = (config = { level: 'log' }) => {
|
|
18
|
+
const error = console.error;
|
|
19
|
+
console.error = (...args) => {
|
|
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
|
+
};
|
|
25
|
+
|
|
26
|
+
exports.setMgAngularLogger = setMgAngularLogger;
|
|
27
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/angular/mg-angular-logger/mg-angular-logger.ts"],"sourcesContent":[null],"names":[],"mappings":";;AAEA;;;;;;;;;;;;;AAaG;AACI,MAAM,kBAAkB,GAAG,CAAC,MAAA,GAAqB,EAAE,KAAK,EAAE,KAAK,EAAE,KAAU;AAChF,IAAA,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK;AAC3B,IAAA,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,IAAe,KAAI;;QAErC,IAAI,MAAM,CAAC,KAAK,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;AACzI,KAAC;AACH;;;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
type ConfigType = {
|
|
2
|
+
level: 'log' | 'error';
|
|
3
|
+
};
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Set window logger custom rules for angular and mg-components
|
|
7
|
+
* @param config - logger configuration object
|
|
8
|
+
* @example
|
|
9
|
+
* ```js
|
|
10
|
+
* // main.js
|
|
11
|
+
* import { defineCustomElements } from '@mgdis/mg-components/loader';
|
|
12
|
+
* import { setMgAngularLogger } from '@mgdis/core-ui-helpers/dist/angular';
|
|
13
|
+
*
|
|
14
|
+
* // need to be set before `defineCustomElements` call
|
|
15
|
+
* setMgAngularLogger({level: 'error'});
|
|
16
|
+
* defineCustomElements();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
declare const setMgAngularLogger: (config?: ConfigType) => void;
|
|
20
|
+
|
|
21
|
+
export { setMgAngularLogger };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Set window logger custom rules for angular and mg-components
|
|
3
|
+
* @param config - logger configuration object
|
|
4
|
+
* @example
|
|
5
|
+
* ```js
|
|
6
|
+
* // main.js
|
|
7
|
+
* import { defineCustomElements } from '@mgdis/mg-components/loader';
|
|
8
|
+
* import { setMgAngularLogger } from '@mgdis/core-ui-helpers/dist/angular';
|
|
9
|
+
*
|
|
10
|
+
* // need to be set before `defineCustomElements` call
|
|
11
|
+
* setMgAngularLogger({level: 'error'});
|
|
12
|
+
* defineCustomElements();
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
const setMgAngularLogger = (config = { level: 'log' }) => {
|
|
16
|
+
const error = console.error;
|
|
17
|
+
console.error = (...args) => {
|
|
18
|
+
// filter error when it come from a mg-components component error
|
|
19
|
+
if (config.level === 'error' || !args.some(arg => arg instanceof Error && arg.message.startsWith('<mg-')))
|
|
20
|
+
error.call(console, ...args);
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { setMgAngularLogger };
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/angular/mg-angular-logger/mg-angular-logger.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEA;;;;;;;;;;;;;AAaG;AACI,MAAM,kBAAkB,GAAG,CAAC,MAAA,GAAqB,EAAE,KAAK,EAAE,KAAK,EAAE,KAAU;AAChF,IAAA,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK;AAC3B,IAAA,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,IAAe,KAAI;;QAErC,IAAI,MAAM,CAAC,KAAK,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YAAE,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;AACzI,KAAC;AACH;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CoreUiHelpers = global.CoreUiHelpers || {}, global.CoreUiHelpers.angular = {})));
|
|
5
|
+
})(this, (function (exports) { 'use strict';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Set window logger custom rules for angular and mg-components
|
|
9
|
+
* @param config - logger configuration object
|
|
10
|
+
* @example
|
|
11
|
+
* ```js
|
|
12
|
+
* // main.js
|
|
13
|
+
* import { defineCustomElements } from '@mgdis/mg-components/loader';
|
|
14
|
+
* import { setMgAngularLogger } from '@mgdis/core-ui-helpers/dist/angular';
|
|
15
|
+
*
|
|
16
|
+
* // need to be set before `defineCustomElements` call
|
|
17
|
+
* setMgAngularLogger({level: 'error'});
|
|
18
|
+
* defineCustomElements();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const setMgAngularLogger = (config = { level: 'log' }) => {
|
|
22
|
+
const error = console.error;
|
|
23
|
+
console.error = (...args) => {
|
|
24
|
+
// filter error when it come from a mg-components component error
|
|
25
|
+
if (config.level === 'error' || !args.some(arg => arg instanceof Error && arg.message.startsWith('<mg-')))
|
|
26
|
+
error.call(console, ...args);
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.setMgAngularLogger = setMgAngularLogger;
|
|
31
|
+
|
|
32
|
+
}));
|
|
33
|
+
//# sourceMappingURL=index.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../../src/angular/mg-angular-logger/mg-angular-logger.ts"],"sourcesContent":[null],"names":[],"mappings":";;;;;;IAEA;;;;;;;;;;;;;IAaG;AACI,UAAM,kBAAkB,GAAG,CAAC,MAAA,GAAqB,EAAE,KAAK,EAAE,KAAK,EAAE,KAAU;IAChF,IAAA,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK;IAC3B,IAAA,OAAO,CAAC,KAAK,GAAG,CAAC,GAAG,IAAe,KAAI;;YAErC,IAAI,MAAM,CAAC,KAAK,KAAK,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,YAAY,KAAK,IAAI,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;gBAAE,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,IAAI,CAAC;IACzI,KAAC;IACH;;;;;;;;"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Date RegExp, usefull to test if string is a follow the date pattern
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* dateRegExp.test('mystring') // false
|
|
8
|
+
* dateRegExp.test('2020-12-31') // true
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
const dateRegExp = /^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$/;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Gets the date pattern based on the specified locale.
|
|
15
|
+
* @param locale - the locale to refer to
|
|
16
|
+
* @returns date pattern
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* localeDatePattern('fr') // 'dd/mm/yyyy'
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
const localeDatePattern = (locale) => {
|
|
23
|
+
const year = { value: '2023', pattern: 'yyyy' };
|
|
24
|
+
const month = { value: '12', pattern: 'mm' };
|
|
25
|
+
const day = { value: '24', pattern: 'dd' };
|
|
26
|
+
return localeDate([year.value, month.value, day.value].join('-'), locale, { timeZone: 'UTC' })
|
|
27
|
+
.replace(year.value, year.pattern)
|
|
28
|
+
.replace(month.value, month.pattern)
|
|
29
|
+
.replace(day.value, day.pattern);
|
|
30
|
+
};
|
|
31
|
+
/**
|
|
32
|
+
* Get locale and messages
|
|
33
|
+
* We load the defined locale but for now we only support the first subtag for messages
|
|
34
|
+
* @param element - element we need to get the language
|
|
35
|
+
* @param messages - messages to use
|
|
36
|
+
* @param defaultLocale - default messages locale
|
|
37
|
+
* @returns messages object
|
|
38
|
+
*/
|
|
39
|
+
const localeMessages = (element, messages, defaultLocale) => {
|
|
40
|
+
// Get local
|
|
41
|
+
const closestLangAttribute = element.closest('[lang]');
|
|
42
|
+
const closestLang = Intl.NumberFormat.supportedLocalesOf(closestLangAttribute?.lang);
|
|
43
|
+
const locale = closestLang.length > 0 && typeof closestLang[0] === 'string' ? closestLang[0] : navigator.language || defaultLocale;
|
|
44
|
+
// Only keep first subtag
|
|
45
|
+
const localeSubtag = locale.split('-').shift();
|
|
46
|
+
// If messages is empty, return a default object
|
|
47
|
+
if (Object.keys(messages).length === 0) {
|
|
48
|
+
return {
|
|
49
|
+
locale,
|
|
50
|
+
messages: { lang: defaultLocale },
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
// Return
|
|
54
|
+
return {
|
|
55
|
+
locale,
|
|
56
|
+
messages: (messages[localeSubtag] || messages[defaultLocale] || { lang: defaultLocale }),
|
|
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
|
+
const localeCurrency = (number, locale, currency) => new Intl.NumberFormat(locale, { style: 'currency', currency }).format(number);
|
|
71
|
+
/**
|
|
72
|
+
* Format number to locale
|
|
73
|
+
* @param number - number to format
|
|
74
|
+
* @param locale - locale to apply
|
|
75
|
+
* @param decimalLength - decimal length to apply
|
|
76
|
+
* @returns formatted number
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* localeNumber(1234567890.12, 'fr') // 1 234 567 890,12
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
const localeNumber = (number, locale, decimalLength = 0) => new Intl.NumberFormat(locale, { minimumFractionDigits: decimalLength }).format(Number(number));
|
|
83
|
+
/**
|
|
84
|
+
* Format number as percentage based on locale
|
|
85
|
+
* @param number - number to format
|
|
86
|
+
* @param locale - locale to apply
|
|
87
|
+
* @param decimalLength - decimal length to apply
|
|
88
|
+
* @returns formatted percentage
|
|
89
|
+
* @example
|
|
90
|
+
* ```ts
|
|
91
|
+
* localePercent(0.42, 'fr', 2) // '42,00 %'
|
|
92
|
+
* localePercent(0.42, 'en', 2) // '42.00%'
|
|
93
|
+
* ```
|
|
94
|
+
*/
|
|
95
|
+
const localePercent = (number, locale, decimalLength = 0) => {
|
|
96
|
+
return new Intl.NumberFormat(locale, {
|
|
97
|
+
style: 'percent',
|
|
98
|
+
minimumFractionDigits: decimalLength,
|
|
99
|
+
maximumFractionDigits: decimalLength,
|
|
100
|
+
}).format(number);
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Format number with standardized unit based on locale using Intl unit formatting
|
|
104
|
+
* @param number - number to format
|
|
105
|
+
* @param locale - locale to apply
|
|
106
|
+
* @param unit - standardized unit (e.g., 'kilometer', 'kilogram', 'celsius')
|
|
107
|
+
* @param unitDisplay - how to display the unit ('short', 'long', 'narrow')
|
|
108
|
+
* @param decimalLength - decimal length to apply
|
|
109
|
+
* @returns formatted number with localized unit
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* localeUnit(1234567890.12, 'fr', 'kilometer') // '1 234 567 890,12 km'
|
|
113
|
+
* localeUnit(23, 'fr', 'celsius') // '23 °C'
|
|
114
|
+
* localeUnit(10, 'fr', 'kilometer', 0, 'long') // '10 kilomètres'
|
|
115
|
+
* ```
|
|
116
|
+
*/
|
|
117
|
+
const localeUnit = (number, locale, unit, unitDisplay = 'short', decimalLength = 0) => {
|
|
118
|
+
return new Intl.NumberFormat(locale, {
|
|
119
|
+
style: 'unit',
|
|
120
|
+
unit,
|
|
121
|
+
unitDisplay,
|
|
122
|
+
minimumFractionDigits: decimalLength,
|
|
123
|
+
maximumFractionDigits: decimalLength,
|
|
124
|
+
}).format(number);
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Locale date format
|
|
128
|
+
* @param date - date to format
|
|
129
|
+
* @param locale - locale to apply
|
|
130
|
+
* @param config - DateTimeFormatOptions object to apply
|
|
131
|
+
* @returns formatted date
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* localeDate('2022-06-02', 'fr') // '02/06/2022'
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
const localeDate = (date, locale, config) => typeof date !== 'string' || date === '' || !dateRegExp.test(date) ? '' : new Intl.DateTimeFormat(locale, config).format(new Date(date));
|
|
138
|
+
/**
|
|
139
|
+
* Get Intl object
|
|
140
|
+
* @param messages - locales to render in object format. `ex: { en: { porp: "test" }, fr: { porp: "test" }}`.
|
|
141
|
+
* @param defaultLocale - fallback locale to render. `ex: 'en'`.
|
|
142
|
+
* @returns from the element passed in return function you will get the matching messages object
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* import en from './en/messages.json';
|
|
146
|
+
* import fr from './fr/messages.json';
|
|
147
|
+
* import { defineLocales } from '@mgdis/core-ui-helpers/dist/utils';
|
|
148
|
+
*
|
|
149
|
+
* const defaultLocale = 'en';
|
|
150
|
+
* const messages = { en, fr };
|
|
151
|
+
*
|
|
152
|
+
* export const initLocales = defineLocales(messages, defaultLocale);
|
|
153
|
+
* ```
|
|
154
|
+
*/
|
|
155
|
+
const defineLocales = (messages, defaultLocale) => (element) => localeMessages(element, messages, defaultLocale);
|
|
156
|
+
|
|
157
|
+
exports.defineLocales = defineLocales;
|
|
158
|
+
exports.localeCurrency = localeCurrency;
|
|
159
|
+
exports.localeDate = localeDate;
|
|
160
|
+
exports.localeDatePattern = localeDatePattern;
|
|
161
|
+
exports.localeNumber = localeNumber;
|
|
162
|
+
exports.localePercent = localePercent;
|
|
163
|
+
exports.localeUnit = localeUnit;
|
|
164
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../../src/utils/date/date.ts","../../src/locale/locale.ts"],"sourcesContent":[null,null],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define json object type
|
|
3
|
+
*/
|
|
4
|
+
type ObjectType = Record<string, unknown>;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Gets the date pattern based on the specified locale.
|
|
8
|
+
* @param locale - the locale to refer to
|
|
9
|
+
* @returns date pattern
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* localeDatePattern('fr') // 'dd/mm/yyyy'
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
declare const localeDatePattern: (locale: string) => string;
|
|
16
|
+
/**
|
|
17
|
+
* Format number to the locale currency
|
|
18
|
+
* @param number - number to format
|
|
19
|
+
* @param locale - locale to apply
|
|
20
|
+
* @param currency - currency to apply
|
|
21
|
+
* @returns formatted currency
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* localeCurrency(1234567890.12, 'fr', 'EUR') // '1 234 567 890,12\xa0€'
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
declare const localeCurrency: (number: number, locale: string, currency: string) => string;
|
|
28
|
+
/**
|
|
29
|
+
* Format number to locale
|
|
30
|
+
* @param number - number to format
|
|
31
|
+
* @param locale - locale to apply
|
|
32
|
+
* @param decimalLength - decimal length to apply
|
|
33
|
+
* @returns formatted number
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* localeNumber(1234567890.12, 'fr') // 1 234 567 890,12
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare const localeNumber: (number: number, locale: string, decimalLength?: number) => string;
|
|
40
|
+
/**
|
|
41
|
+
* Format number as percentage based on locale
|
|
42
|
+
* @param number - number to format
|
|
43
|
+
* @param locale - locale to apply
|
|
44
|
+
* @param decimalLength - decimal length to apply
|
|
45
|
+
* @returns formatted percentage
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* localePercent(0.42, 'fr', 2) // '42,00 %'
|
|
49
|
+
* localePercent(0.42, 'en', 2) // '42.00%'
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
declare const localePercent: (number: number, locale: string, decimalLength?: number) => string;
|
|
53
|
+
/**
|
|
54
|
+
* Format number with standardized unit based on locale using Intl unit formatting
|
|
55
|
+
* @param number - number to format
|
|
56
|
+
* @param locale - locale to apply
|
|
57
|
+
* @param unit - standardized unit (e.g., 'kilometer', 'kilogram', 'celsius')
|
|
58
|
+
* @param unitDisplay - how to display the unit ('short', 'long', 'narrow')
|
|
59
|
+
* @param decimalLength - decimal length to apply
|
|
60
|
+
* @returns formatted number with localized unit
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* localeUnit(1234567890.12, 'fr', 'kilometer') // '1 234 567 890,12 km'
|
|
64
|
+
* localeUnit(23, 'fr', 'celsius') // '23 °C'
|
|
65
|
+
* localeUnit(10, 'fr', 'kilometer', 0, 'long') // '10 kilomètres'
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
declare const localeUnit: (number: number, locale: string, unit: Intl.NumberFormatOptions["unit"], unitDisplay?: Intl.NumberFormatOptions["unitDisplay"], decimalLength?: number) => string;
|
|
69
|
+
/**
|
|
70
|
+
* Locale date format
|
|
71
|
+
* @param date - date to format
|
|
72
|
+
* @param locale - locale to apply
|
|
73
|
+
* @param config - DateTimeFormatOptions object to apply
|
|
74
|
+
* @returns formatted date
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* localeDate('2022-06-02', 'fr') // '02/06/2022'
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
declare const localeDate: (date: string | undefined, locale: string, config?: Intl.DateTimeFormatOptions) => string;
|
|
81
|
+
/**
|
|
82
|
+
* Get Intl object
|
|
83
|
+
* @param messages - locales to render in object format. `ex: { en: { porp: "test" }, fr: { porp: "test" }}`.
|
|
84
|
+
* @param defaultLocale - fallback locale to render. `ex: 'en'`.
|
|
85
|
+
* @returns from the element passed in return function you will get the matching messages object
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import en from './en/messages.json';
|
|
89
|
+
* import fr from './fr/messages.json';
|
|
90
|
+
* import { defineLocales } from '@mgdis/core-ui-helpers/dist/utils';
|
|
91
|
+
*
|
|
92
|
+
* const defaultLocale = 'en';
|
|
93
|
+
* const messages = { en, fr };
|
|
94
|
+
*
|
|
95
|
+
* export const initLocales = defineLocales(messages, defaultLocale);
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
98
|
+
declare const defineLocales: (messages: ObjectType, defaultLocale: "fr" | "en") => (element: HTMLElement) => {
|
|
99
|
+
locale: string;
|
|
100
|
+
messages: ObjectType;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export { defineLocales, localeCurrency, localeDate, localeDatePattern, localeNumber, localePercent, localeUnit };
|