@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.
Files changed (146) hide show
  1. package/.turbo/turbo-build.log +52 -0
  2. package/CHANGELOG.md +12 -0
  3. package/LICENSE +29 -0
  4. package/README.md +95 -0
  5. package/dist/angular/index.cjs +27 -0
  6. package/dist/angular/index.cjs.map +1 -0
  7. package/dist/angular/index.d.ts +21 -0
  8. package/dist/angular/index.js +25 -0
  9. package/dist/angular/index.js.map +1 -0
  10. package/dist/angular/index.umd.js +33 -0
  11. package/dist/angular/index.umd.js.map +1 -0
  12. package/dist/locale/index.cjs +164 -0
  13. package/dist/locale/index.cjs.map +1 -0
  14. package/dist/locale/index.d.ts +103 -0
  15. package/dist/locale/index.js +156 -0
  16. package/dist/locale/index.js.map +1 -0
  17. package/dist/locale/index.umd.js +170 -0
  18. package/dist/locale/index.umd.js.map +1 -0
  19. package/dist/playwright/index.cjs +124 -0
  20. package/dist/playwright/index.cjs.map +1 -0
  21. package/dist/playwright/index.d.ts +35 -0
  22. package/dist/playwright/index.js +120 -0
  23. package/dist/playwright/index.js.map +1 -0
  24. package/dist/playwright/index.umd.js +130 -0
  25. package/dist/playwright/index.umd.js.map +1 -0
  26. package/dist/stencil/index.cjs +281 -0
  27. package/dist/stencil/index.cjs.map +1 -0
  28. package/dist/stencil/index.d.ts +111 -0
  29. package/dist/stencil/index.js +277 -0
  30. package/dist/stencil/index.js.map +1 -0
  31. package/dist/stencil/index.umd.js +287 -0
  32. package/dist/stencil/index.umd.js.map +1 -0
  33. package/dist/storybook/index.cjs +2109 -0
  34. package/dist/storybook/index.cjs.map +1 -0
  35. package/dist/storybook/index.d.ts +85 -0
  36. package/dist/storybook/index.js +2103 -0
  37. package/dist/storybook/index.js.map +1 -0
  38. package/dist/storybook/index.umd.js +2115 -0
  39. package/dist/storybook/index.umd.js.map +1 -0
  40. package/dist/tests/index.cjs +166 -0
  41. package/dist/tests/index.cjs.map +1 -0
  42. package/dist/tests/index.d.ts +91 -0
  43. package/dist/tests/index.js +161 -0
  44. package/dist/tests/index.js.map +1 -0
  45. package/dist/tests/index.umd.js +172 -0
  46. package/dist/tests/index.umd.js.map +1 -0
  47. package/dist/utils/index.cjs +433 -0
  48. package/dist/utils/index.cjs.map +1 -0
  49. package/dist/utils/index.d.ts +265 -0
  50. package/dist/utils/index.js +409 -0
  51. package/dist/utils/index.js.map +1 -0
  52. package/dist/utils/index.umd.js +439 -0
  53. package/dist/utils/index.umd.js.map +1 -0
  54. package/dist/vue/index.cjs +1934 -0
  55. package/dist/vue/index.cjs.map +1 -0
  56. package/dist/vue/index.d.ts +35 -0
  57. package/dist/vue/index.js +1932 -0
  58. package/dist/vue/index.js.map +1 -0
  59. package/dist/vue/index.umd.js +1940 -0
  60. package/dist/vue/index.umd.js.map +1 -0
  61. package/json-doc.test.json +253 -0
  62. package/package.json +80 -0
  63. package/rollup.config.mjs +61 -0
  64. package/src/angular/index.spec.ts +8 -0
  65. package/src/angular/index.ts +1 -0
  66. package/src/angular/mg-angular-logger/index.ts +1 -0
  67. package/src/angular/mg-angular-logger/mg-angular-logger.conf.ts +3 -0
  68. package/src/angular/mg-angular-logger/mg-angular-logger.spec.ts +40 -0
  69. package/src/angular/mg-angular-logger/mg-angular-logger.ts +23 -0
  70. package/src/locale/index.spec.ts +14 -0
  71. package/src/locale/index.ts +1 -0
  72. package/src/locale/locale.spec.ts +173 -0
  73. package/src/locale/locale.ts +166 -0
  74. package/src/playwright/config/index.ts +43 -0
  75. package/src/playwright/index.spec.ts +16 -0
  76. package/src/playwright/index.ts +4 -0
  77. package/src/playwright/utils/__snapshots__/utils.spec.ts.snap +48 -0
  78. package/src/playwright/utils/index.ts +1 -0
  79. package/src/playwright/utils/utils.spec.ts +43 -0
  80. package/src/playwright/utils/utils.ts +64 -0
  81. package/src/stencil/ide/__snapshots__/ide.spec.ts.snap +527 -0
  82. package/src/stencil/ide/ide.spec.ts +25 -0
  83. package/src/stencil/ide/ide.ts +214 -0
  84. package/src/stencil/ide/index.ts +1 -0
  85. package/src/stencil/index.spec.ts +12 -0
  86. package/src/stencil/index.ts +1 -0
  87. package/src/storybook/index.spec.ts +15 -0
  88. package/src/storybook/index.ts +1 -0
  89. package/src/storybook/stencil/__snapshots__/stencil.spec.ts.snap +329 -0
  90. package/src/storybook/stencil/index.ts +1 -0
  91. package/src/storybook/stencil/stencil-shim.d.ts +1 -0
  92. package/src/storybook/stencil/stencil.conf.ts +4 -0
  93. package/src/storybook/stencil/stencil.spec.ts +142 -0
  94. package/src/storybook/stencil/stencil.ts +366 -0
  95. package/src/tests/index.spec.ts +13 -0
  96. package/src/tests/index.ts +1 -0
  97. package/src/tests/unit/__snapshots__/unit.spec.ts.snap +52 -0
  98. package/src/tests/unit/index.ts +1 -0
  99. package/src/tests/unit/unit.conf.ts +9 -0
  100. package/src/tests/unit/unit.spec.ts +44 -0
  101. package/src/tests/unit/unit.ts +171 -0
  102. package/src/utils/attributes/class-list/class-list.spec.ts +36 -0
  103. package/src/utils/attributes/class-list/class-list.ts +51 -0
  104. package/src/utils/attributes/class-list/index.ts +1 -0
  105. package/src/utils/attributes/id/id.spec.ts +51 -0
  106. package/src/utils/attributes/id/id.ts +46 -0
  107. package/src/utils/attributes/id/index.ts +1 -0
  108. package/src/utils/attributes/index.ts +3 -0
  109. package/src/utils/attributes/to-kebab-case/index.ts +1 -0
  110. package/src/utils/attributes/to-kebab-case/to-kebab-case.spec.ts +29 -0
  111. package/src/utils/attributes/to-kebab-case/to-kebab-case.ts +23 -0
  112. package/src/utils/components/__snapshots__/components.spec.ts.snap +313 -0
  113. package/src/utils/components/components.conf.ts +11 -0
  114. package/src/utils/components/components.spec.ts +192 -0
  115. package/src/utils/components/components.ts +138 -0
  116. package/src/utils/components/index.ts +2 -0
  117. package/src/utils/date/date.spec.ts +12 -0
  118. package/src/utils/date/date.ts +20 -0
  119. package/src/utils/date/index.ts +1 -0
  120. package/src/utils/elements/elements.spec.ts +17 -0
  121. package/src/utils/elements/elements.ts +16 -0
  122. package/src/utils/elements/index.ts +1 -0
  123. package/src/utils/index.spec.ts +84 -0
  124. package/src/utils/index.ts +8 -0
  125. package/src/utils/number/index.ts +1 -0
  126. package/src/utils/number/number.spec.ts +14 -0
  127. package/src/utils/number/number.ts +6 -0
  128. package/src/utils/object/index.ts +2 -0
  129. package/src/utils/object/object.conf.ts +4 -0
  130. package/src/utils/object/object.spec.ts +98 -0
  131. package/src/utils/object/object.ts +26 -0
  132. package/src/utils/string/index.ts +1 -0
  133. package/src/utils/string/string.spec.ts +47 -0
  134. package/src/utils/string/string.ts +38 -0
  135. package/src/utils/windows/index.ts +1 -0
  136. package/src/utils/windows/windows.spec.ts +65 -0
  137. package/src/utils/windows/windows.ts +50 -0
  138. package/src/vue/index.spec.ts +8 -0
  139. package/src/vue/index.ts +1 -0
  140. package/src/vue/mg-model/index.ts +1 -0
  141. package/src/vue/mg-model/mg-model.conf.ts +6 -0
  142. package/src/vue/mg-model/mg-model.spec.ts +50 -0
  143. package/src/vue/mg-model/mg-model.ts +50 -0
  144. package/tsconfig.json +17 -0
  145. package/typedoc.json +14 -0
  146. 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
+ 
6
+ src/angular/index.ts → dist/angular/index.js, dist/angular/index.cjs, dist/angular/index.umd.js...
7
+ created dist/angular/index.js, dist/angular/index.cjs, dist/angular/index.umd.js in 5s
8
+ 
9
+ src/angular/index.ts → dist/angular/index.d.ts...
10
+ created dist/angular/index.d.ts in 2s
11
+ 
12
+ src/locale/index.ts → dist/locale/index.js, dist/locale/index.cjs, dist/locale/index.umd.js...
13
+ created dist/locale/index.js, dist/locale/index.cjs, dist/locale/index.umd.js in 2.9s
14
+ 
15
+ src/locale/index.ts → dist/locale/index.d.ts...
16
+ created dist/locale/index.d.ts in 1.1s
17
+ 
18
+ src/playwright/index.ts → dist/playwright/index.js, dist/playwright/index.cjs, dist/playwright/index.umd.js...
19
+ created dist/playwright/index.js, dist/playwright/index.cjs, dist/playwright/index.umd.js in 3.3s
20
+ 
21
+ src/playwright/index.ts → dist/playwright/index.d.ts...
22
+ created dist/playwright/index.d.ts in 1.1s
23
+ 
24
+ src/stencil/index.ts → dist/stencil/index.js, dist/stencil/index.cjs, dist/stencil/index.umd.js...
25
+ created dist/stencil/index.js, dist/stencil/index.cjs, dist/stencil/index.umd.js in 3s
26
+ 
27
+ src/stencil/index.ts → dist/stencil/index.d.ts...
28
+ created dist/stencil/index.d.ts in 1s
29
+ 
30
+ src/storybook/index.ts → dist/storybook/index.js, dist/storybook/index.cjs, dist/storybook/index.umd.js...
31
+ created dist/storybook/index.js, dist/storybook/index.cjs, dist/storybook/index.umd.js in 2.5s
32
+ 
33
+ src/storybook/index.ts → dist/storybook/index.d.ts...
34
+ created dist/storybook/index.d.ts in 1.2s
35
+ 
36
+ src/tests/index.ts → dist/tests/index.js, dist/tests/index.cjs, dist/tests/index.umd.js...
37
+ created dist/tests/index.js, dist/tests/index.cjs, dist/tests/index.umd.js in 2.8s
38
+ 
39
+ src/tests/index.ts → dist/tests/index.d.ts...
40
+ created dist/tests/index.d.ts in 1s
41
+ 
42
+ src/utils/index.ts → dist/utils/index.js, dist/utils/index.cjs, dist/utils/index.umd.js...
43
+ created dist/utils/index.js, dist/utils/index.cjs, dist/utils/index.umd.js in 2.9s
44
+ 
45
+ src/utils/index.ts → dist/utils/index.d.ts...
46
+ created dist/utils/index.d.ts in 1.3s
47
+ 
48
+ src/vue/index.ts → dist/vue/index.js, dist/vue/index.cjs, dist/vue/index.umd.js...
49
+ created dist/vue/index.js, dist/vue/index.cjs, dist/vue/index.umd.js in 2.7s
50
+ 
51
+ src/vue/index.ts → dist/vue/index.d.ts...
52
+ created dist/vue/index.d.ts in 1.1s
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 };