@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 +29 -0
- package/README.md +18 -0
- package/dist/components/index.d.ts +96 -0
- package/dist/components/index.d.ts.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.es.js +565 -0
- package/dist/index.es.js.map +1 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/locale/index.conf.d.ts +5 -0
- package/dist/locale/index.conf.d.ts.map +1 -0
- package/dist/locale/index.d.ts +86 -0
- package/dist/locale/index.d.ts.map +1 -0
- package/dist/storybook/index.conf.d.ts +7 -0
- package/dist/storybook/index.conf.d.ts.map +1 -0
- package/dist/storybook/index.d.ts +48 -0
- package/dist/storybook/index.d.ts.map +1 -0
- package/dist/test/index.d.ts +2 -0
- package/dist/test/index.d.ts.map +1 -0
- package/dist/test/unit.conf.d.ts +16 -0
- package/dist/test/unit.conf.d.ts.map +1 -0
- package/dist/test/unit.d.ts +66 -0
- package/dist/test/unit.d.ts.map +1 -0
- package/package.json +51 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.conf.d.ts","sourceRoot":"","sources":["../../src/locale/index.conf.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import type { ObjectType } from './index.conf';
|
|
2
|
+
/**
|
|
3
|
+
* Gets the date pattern based on the specified locale.
|
|
4
|
+
* @param locale - the locale to refer to
|
|
5
|
+
* @returns date pattern
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* getLocaleDatePattern('fr') // 'dd/mm/yyyy'
|
|
9
|
+
* ```
|
|
10
|
+
*/
|
|
11
|
+
export declare const getLocaleDatePattern: (locale: string) => string;
|
|
12
|
+
/**
|
|
13
|
+
* Formats a date object to a string with the pattern 'YYYY-MM-DD'.
|
|
14
|
+
* @param date - date to parse
|
|
15
|
+
* @returns string date with pattern 'YYYY-MM-DD'
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* dateToString(new Date('2023-12-24')) // '2023-12-24'
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const dateToString: (date: Date) => string | undefined;
|
|
22
|
+
/**
|
|
23
|
+
* Format number to the locale currency
|
|
24
|
+
* @param number - number to format
|
|
25
|
+
* @param locale - locale to apply
|
|
26
|
+
* @param currency - currency to apply
|
|
27
|
+
* @returns formatted currency
|
|
28
|
+
* @example
|
|
29
|
+
* ```ts
|
|
30
|
+
* localeCurrency(1234567890.12, 'fr', 'EUR') // '1 234 567 890,12\xa0€'
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export declare const localeCurrency: (number: number, locale: string, currency: string) => string;
|
|
34
|
+
/**
|
|
35
|
+
* Format number to locale
|
|
36
|
+
* @param number - number to format
|
|
37
|
+
* @param locale - locale to apply
|
|
38
|
+
* @returns formatted number
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* localeNumber(1234567890.12, 'fr') // 1 234 567 890,12
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare const localeNumber: (number: number, locale: string) => string;
|
|
45
|
+
/**
|
|
46
|
+
* Date RegExp, usefull to test if string is a follow the date pattern
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* dateRegExp.test('mystring') // false
|
|
50
|
+
* dateRegExp.test('2020-12-31') // true
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare const dateRegExp: RegExp;
|
|
54
|
+
/**
|
|
55
|
+
* Locale date format
|
|
56
|
+
* @param date - date to format
|
|
57
|
+
* @param locale - locale to apply
|
|
58
|
+
* @returns formatted date
|
|
59
|
+
* @example
|
|
60
|
+
* ```ts
|
|
61
|
+
* localeDate('2022-06-02', 'fr') // '02/06/2022'
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare const localeDate: (date: string | undefined, locale: string) => string;
|
|
65
|
+
/**
|
|
66
|
+
* Get Intl object
|
|
67
|
+
* @param messages - locales to render in object format. `ex: { en: { porp: "test" }, fr: { porp: "test" }}`.
|
|
68
|
+
* @param defaultLocale - fallback locale to render. `ex: 'en'`.
|
|
69
|
+
* @returns from the element passed in return function you will get the matching messages object
|
|
70
|
+
* @example
|
|
71
|
+
* ```ts
|
|
72
|
+
* import en from './en/messages.json';
|
|
73
|
+
* import fr from './fr/messages.json';
|
|
74
|
+
* import { defineLocales } from '@mgdis/stencil-helpers';
|
|
75
|
+
*
|
|
76
|
+
* const defaultLocale = 'en';
|
|
77
|
+
* const messages = { en, fr };
|
|
78
|
+
*
|
|
79
|
+
* export const initLocales = defineLocales(messages, defaultLocale);
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare const defineLocales: (messages: ObjectType, defaultLocale: 'fr' | 'en' | string) => (element: HTMLElement) => {
|
|
83
|
+
locale: string;
|
|
84
|
+
messages: ObjectType;
|
|
85
|
+
};
|
|
86
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/locale/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE/C;;;;;;;;GAQG;AACH,eAAO,MAAM,oBAAoB,WAAY,MAAM,WAKlD,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,SAAU,IAAI,KAAG,MAAM,GAAG,SAA6C,CAAC;AAwBjG;;;;;;;;;;GAUG;AACH,eAAO,MAAM,cAAc,WAAY,MAAM,UAAU,MAAM,YAAY,MAAM,KAAG,MAAuF,CAAC;AAE1K;;;;;;;;;GASG;AACH,eAAO,MAAM,YAAY,WAAY,MAAM,UAAU,MAAM,KAAG,MAAsD,CAAC;AAErH;;;;;;;GAOG;AACH,eAAO,MAAM,UAAU,QAAkD,CAAC;AAE1E;;;;;;;;;GASG;AACH,eAAO,MAAM,UAAU,SAAU,MAAM,GAAG,SAAS,UAAU,MAAM,KAAG,MAKrE,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa,aACb,UAAU,iBAAiB,IAAI,GAAG,IAAI,GAAG,MAAM,eAChD,WAAW;YAAa,MAAM;cAAY,UAAU;CACT,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.conf.d.ts","sourceRoot":"","sources":["../../src/storybook/index.conf.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,QAAQ,GAAG;IAAE,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { VNode } from '@stencil/core';
|
|
2
|
+
import { ArgsType } from './index.conf';
|
|
3
|
+
/**
|
|
4
|
+
* Filter default argument on component argument to prevent them to be rendered
|
|
5
|
+
* @param args - all possible args with custom values
|
|
6
|
+
* @param defaultValues - component default args values
|
|
7
|
+
* @returns filtres args
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* import { filterArgs } from '@mgdis/stencil-helpers';
|
|
11
|
+
* const Template = (args: MgBadgeType): HTMLElement => <mg-badge {...filterArgs(args, { variant: variants[0] })}></mg-badge>;
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export declare const filterArgs: <T>(args: T, defaultValues?: T | undefined) => T;
|
|
15
|
+
/**
|
|
16
|
+
* Storybook stencil wrapper. Used to target element with `storybook-root` id and render virtual DOM inside.
|
|
17
|
+
* @param storyFn - storybook render function
|
|
18
|
+
* @param context - storybook context
|
|
19
|
+
* @returns rendered element
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* // .storybook/preview.ts
|
|
23
|
+
* import { stencilWrapper } from '@mgdis/stencil-helpers';
|
|
24
|
+
* export const decorators: Preview['decorators'] = [stencilWrapper];
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export declare const stencilWrapper: (storyFn: (ctx: any) => void, context: ArgsType) => Element | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Get story HTML from virtual DOM.
|
|
30
|
+
* Mainly used to render, component code exemple in stories.
|
|
31
|
+
* @param vitualNode - story virtual DOM
|
|
32
|
+
* @returns stringified rendered HTML
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* // .storybook/preview.ts
|
|
36
|
+
* import { getStoryHTML } from '@mgdis/stencil-helpers';
|
|
37
|
+
*
|
|
38
|
+
* export const parameters: Preview['parameters'] = {
|
|
39
|
+
* docs: {
|
|
40
|
+
* extractArgTypes,
|
|
41
|
+
* extractComponentDescription,
|
|
42
|
+
* transformSource: (_, ctx) => getStoryHTML(ctx.originalStoryFn(ctx.args)),
|
|
43
|
+
* },
|
|
44
|
+
* };
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare const getStoryHTML: ({ $tag$, $attrs$, $children$, $text$ }: VNode) => string;
|
|
48
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/storybook/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AA6CxC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,UAAU,kDAgBtB,CAAC;AAEF;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,cAAc,kBAAmB,GAAG,KAAK,IAAI,WAAW,QAAQ,KAAG,OAAO,GAAG,SAqBzF,CAAC;AAEF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,YAAY,2CAA4C,KAAK,KAAG,MAM5E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/test/index.ts"],"names":[],"mappings":"AAAA,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Define MutationObserver setup function signature
|
|
3
|
+
*/
|
|
4
|
+
export type SetupMutationObserverMockParams = {
|
|
5
|
+
disconnect: MutationObserver['disconnect'];
|
|
6
|
+
observe: MutationObserver['observe'];
|
|
7
|
+
takeRecords: MutationObserver['takeRecords'];
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Define ResizeObserver setup function signature
|
|
11
|
+
*/
|
|
12
|
+
export type setupResizeObserverMockParams = {
|
|
13
|
+
disconnect: ResizeObserver['disconnect'];
|
|
14
|
+
observe: ResizeObserver['observe'];
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=unit.conf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unit.conf.d.ts","sourceRoot":"","sources":["../../src/test/unit.conf.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAAE,UAAU,EAAE,gBAAgB,CAAC,YAAY,CAAC,CAAC;IAAC,OAAO,EAAE,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAAC,WAAW,EAAE,gBAAgB,CAAC,aAAa,CAAC,CAAA;CAAE,CAAC;AAEjL;;GAEG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAAE,UAAU,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC;IAAC,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { SetupMutationObserverMockParams, setupResizeObserverMockParams } from './unit.conf';
|
|
2
|
+
/**
|
|
3
|
+
* Utility function that mocks the `MutationObserver` API. Recommended to execute inside `beforeEach`.
|
|
4
|
+
* @param mutationObserverMock - Parameter that is sent to the `Object.defineProperty`
|
|
5
|
+
* overwrite method. `jest.fn()` mock functions can be passed here if the goal is to not only
|
|
6
|
+
* mock the mutation observer, but its methods.
|
|
7
|
+
* You can manually fire an intersection entry:
|
|
8
|
+
* @param mutationObserverMock - configuration object
|
|
9
|
+
* @returns Mocked MutationObserver
|
|
10
|
+
* @example
|
|
11
|
+
* ```
|
|
12
|
+
* let fireMo;
|
|
13
|
+
* setupMutationObserverMock({
|
|
14
|
+
* observe: function () {
|
|
15
|
+
* fireMo = this.cb;
|
|
16
|
+
* },
|
|
17
|
+
* });
|
|
18
|
+
* ...
|
|
19
|
+
* fireMo([{ type: 'childList', addedNodes: [AMockElemenet, AnotherMockElemenet], target: yourMockElemenet }]);;
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export declare const setupMutationObserverMock: ({ disconnect, observe, takeRecords }: SetupMutationObserverMockParams) => typeof MutationObserver;
|
|
23
|
+
/**
|
|
24
|
+
* Utility function that mocks the `ResizeObserver` API. Recommended to execute inside `beforeEach`.
|
|
25
|
+
* @param resizeObserverMock - Parameter that is sent to the `Object.defineProperty`
|
|
26
|
+
* overwrite method. `jest.fn()` mock functions can be passed here if the goal is to not only
|
|
27
|
+
* mock the resize observer, but its methods.
|
|
28
|
+
* You can manually fire an intersection entry:
|
|
29
|
+
* @param resizeObserverMock - configuration object
|
|
30
|
+
* @returns Mocked ResizeObserver
|
|
31
|
+
* @example
|
|
32
|
+
* ```
|
|
33
|
+
* let fireRo;
|
|
34
|
+
* setupResizeObserverMock({
|
|
35
|
+
* observe: function () {
|
|
36
|
+
* fireRo = this.cb;
|
|
37
|
+
* },
|
|
38
|
+
* });
|
|
39
|
+
* ...
|
|
40
|
+
* fireRo([{
|
|
41
|
+
* borderBoxSize: ResizeObserverSize[],
|
|
42
|
+
* contentBoxSize: ResizeObserverSize[],
|
|
43
|
+
* contentRect: DOMRectReadOnly,
|
|
44
|
+
* devicePixelContentBoxSize: ResizeObserverSize[],
|
|
45
|
+
* target: yourMockElemenet
|
|
46
|
+
* }]);;
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
49
|
+
export declare const setupResizeObserverMock: ({ disconnect, observe }: setupResizeObserverMockParams) => typeof ResizeObserver;
|
|
50
|
+
declare class MockCustomEvent extends Event {
|
|
51
|
+
/**
|
|
52
|
+
*
|
|
53
|
+
*/
|
|
54
|
+
detail: any;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Utility function that mocks the `SubmitEvent` API. Recommended to execute inside `beforeEach`.
|
|
58
|
+
* @example
|
|
59
|
+
* ```
|
|
60
|
+
* setupSubmitEventMock();
|
|
61
|
+
* ```
|
|
62
|
+
* @returns custom event mock
|
|
63
|
+
*/
|
|
64
|
+
export declare const setupSubmitEventMock: () => typeof MockCustomEvent;
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=unit.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unit.d.ts","sourceRoot":"","sources":["../../src/test/unit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,+BAA+B,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAElG;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,yBAAyB,yCAA0C,+BAA+B,KAAG,uBAgCjH,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,uBAAuB,4BAA6B,6BAA6B,KAAG,qBAgChG,CAAC;AAEF,cAAM,eAAgB,SAAQ,KAAK;IACjC;;OAEG;IAEH,MAAM,EAAE,GAAG,CAAC;CACb;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,QAAO,sBAYvC,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@mgdis/stencil-helpers",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"license": "ISC",
|
|
5
|
+
"author": "Nicolas Jouanno <jouanno-n@mgdis.fr>",
|
|
6
|
+
"maintainers": [
|
|
7
|
+
"Simon Duhem <duhem-s@mgdis.fr>",
|
|
8
|
+
"Nicolas Jouanno <jouanno-n@mgdis.fr>"
|
|
9
|
+
],
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
13
|
+
"main": "./dist/index.umd.js",
|
|
14
|
+
"module": "./dist/index.es.js",
|
|
15
|
+
"types": "dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"import": "./dist/index.es.js",
|
|
20
|
+
"require": "./dist/index.umd.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@stencil/core": "4.11.0"
|
|
25
|
+
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"@types/node": "20.11.6",
|
|
28
|
+
"@vitest/coverage-istanbul": "1.2.1",
|
|
29
|
+
"@vitest/coverage-v8": "1.2.1",
|
|
30
|
+
"typedoc": "0.25.7",
|
|
31
|
+
"typedoc-plugin-markdown": "3.17.1",
|
|
32
|
+
"typescript": "5.3.3",
|
|
33
|
+
"vite": "5.0.12",
|
|
34
|
+
"vite-plugin-dts": "3.7.2",
|
|
35
|
+
"vitest": "1.2.1",
|
|
36
|
+
"eslint-config-custom": "1.0.1",
|
|
37
|
+
"prettier-config": "1.0.1",
|
|
38
|
+
"tsconfig": "1.0.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"build": "tsc --noEmit && vite build && typedoc",
|
|
42
|
+
"test": "vitest",
|
|
43
|
+
"coverage": "vitest run --coverage",
|
|
44
|
+
"lint": "pnpm lint:es && pnpm lint:prettier",
|
|
45
|
+
"lint:fix": "pnpm lint:es:fix && pnpm lint:prettier:fix",
|
|
46
|
+
"lint:es": "eslint '**/*.{ts,tsx}' --ignore-path ../../.gitignore",
|
|
47
|
+
"lint:es:fix": "eslint '**/*.{ts,tsx}' --fix --ignore-path ../../.gitignore",
|
|
48
|
+
"lint:prettier": "prettier --check '**/*.{js,ts,json}' --ignore-path ../../.gitignore",
|
|
49
|
+
"lint:prettier:fix": "prettier --write '**/*.{js,ts,json}' --ignore-path ../../.gitignore"
|
|
50
|
+
}
|
|
51
|
+
}
|