@mgdis/stencil-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/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,18 @@
1
+ # @mgdis/stencil-helpers
2
+
3
+ This package centralizes helper functions for your [Stencil](https://stenciljs.com/) projects. It is divided into four thematic sections:
4
+
5
+ - **Components**: Centralizes all component utilities.
6
+ - **Locale**: Centralizes all necessary locale utilities for managing content translation.
7
+ - **Storybook**: Centralizes all Storybook helpers useful for building your own Storybook.
8
+ - **Test**: Centralizes all test utilities to simplify testing your components.
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ pnpm i @mgdis/stencil-helpers
14
+ ```
15
+
16
+ ## Documentation
17
+
18
+ Read the full [documentation](./doc/README.md)
@@ -0,0 +1,96 @@
1
+ /**
2
+ * Create random ID
3
+ * @param prefix - add prefix to created ID
4
+ * @param length - ID length
5
+ * @returns ID
6
+ */
7
+ export declare const createID: (prefix?: string, length?: number) => string;
8
+ /**
9
+ * Class to manage component classlist
10
+ */
11
+ export declare class ClassList {
12
+ /**
13
+ * Available classes
14
+ */
15
+ classes: string[];
16
+ constructor(classlist?: string[]);
17
+ /**
18
+ * Add class
19
+ * @param className - class name to add
20
+ */
21
+ add: (className: string) => void;
22
+ /**
23
+ * Delete class
24
+ * @param className - class name to delete
25
+ */
26
+ delete: (className: string) => void;
27
+ /**
28
+ * Check if class exist in list
29
+ * @param className - class name to check
30
+ * @returns class name is in the list
31
+ */
32
+ has: (className: string) => boolean;
33
+ /**
34
+ * Join classes seperated by spaces
35
+ * @returns joined values
36
+ */
37
+ join: () => string;
38
+ }
39
+ /**
40
+ * Typeguard function to check if all array items are strings.
41
+ * @param items - items to check
42
+ * @returns `true` if all items are strings
43
+ */
44
+ export declare const allItemsAreString: (items: unknown) => items is string[];
45
+ /**
46
+ * Check if element belongs to the given tagNames list
47
+ * @param element - element to check
48
+ * @param tagNames - allowed tag names list
49
+ * @returns `true` if element tagName is in the tagNames list
50
+ */
51
+ export declare const isTagName: (element: Element, tagNames: string[]) => boolean;
52
+ /**
53
+ * CSS selector to select focusable elements.
54
+ * @example
55
+ * ```ts
56
+ * const allFocusableElements: HTMLElement[] = Array.from(this.element.querySelectorAll(focusableElements));
57
+ * ```
58
+ */
59
+ export declare const focusableElements = "a[href], button, input, textarea, select, details, [tabindex]:not([tabindex=\"-1\"]), [identifier], mg-button";
60
+ /**
61
+ * Get windows
62
+ * @param localWindow - the window we are lookink for other windows
63
+ * @returns The list of windows found
64
+ */
65
+ export declare const getWindows: (localWindow: Window) => Window[];
66
+ /**
67
+ * Get parent windows
68
+ * @param localWindow - the window we are lookink for parents
69
+ * @param windows - The list of allready found windows
70
+ * @returns The list of windows found
71
+ */
72
+ export declare const getParentWindows: (localWindow: Window, windows?: Window[]) => Window[];
73
+ /**
74
+ * Validate string
75
+ * @param value - value to check
76
+ * @returns `true` if string is valid
77
+ */
78
+ export declare const isValidString: (value: unknown) => boolean;
79
+ /**
80
+ * Cleans string characters by removing special characters and converting to lowercase.
81
+ * @param text - text to clean
82
+ * @returns cleaned string
83
+ * @example
84
+ * ```ts
85
+ * cleanString('âäàçéèêñù') // 'aaaceeenu'
86
+ * cleanString('BATMAN') // 'batman'
87
+ * ```
88
+ */
89
+ export declare const cleanString: (text: string) => string;
90
+ /**
91
+ * Use to process code next tick in the event loop
92
+ * @param callback - code to excute on next tick
93
+ * @returns differed code excution
94
+ */
95
+ export declare const nextTick: (callback: () => void) => Promise<void>;
96
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,wCAA+B,MAWnD,CAAC;AAEF;;GAEG;AACH,qBAAa,SAAS;IACpB;;OAEG;IACH,OAAO,EAAE,MAAM,EAAE,CAAC;gBAEN,SAAS,GAAE,MAAM,EAAO;IAIpC;;;OAGG;IACH,GAAG,cAAe,MAAM,KAAG,IAAI,CAI7B;IAEF;;;OAGG;IACH,MAAM,cAAe,MAAM,KAAG,IAAI,CAKhC;IAEF;;;;OAIG;IACH,GAAG,cAAe,MAAM,KAAG,OAAO,CAEhC;IAEF;;;OAGG;IACH,IAAI,QAAO,MAAM,CAEf;CACH;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,UAAW,OAAO,sBAA6F,CAAC;AAE9I;;;;;GAKG;AACH,eAAO,MAAM,SAAS,YAAa,OAAO,YAAY,MAAM,EAAE,KAAG,OAEhE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,kHAAgH,CAAC;AAE/I;;;;GAIG;AACH,eAAO,MAAM,UAAU,gBAAiB,MAAM,KAAG,MAAM,EAItD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,gBAAiB,MAAM,YAAW,MAAM,EAAE,KAAQ,MAAM,EAgBpF,CAAC;AAkBF;;;;GAIG;AACH,eAAO,MAAM,aAAa,UAAW,OAAO,KAAG,OAA2D,CAAC;AAE3G;;;;;;;;;GASG;AACH,eAAO,MAAM,WAAW,SAAU,MAAM,KAAG,MAMjC,CAAC;AAEX;;;;GAIG;AACH,eAAO,MAAM,QAAQ,aAAoB,MAAM,IAAI,KAAG,QAAQ,IAAI,CAAe,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './storybook';
2
+ export * from './locale';
3
+ export * from './components';
4
+ export * from './test';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}