@ponchopay/pp-browser 1.0.2
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 +21 -0
- package/README.md +106 -0
- package/dist/src/PpPayment.d.ts +19 -0
- package/dist/src/PpPayment.js +88 -0
- package/dist/src/PpPayment.js.map +1 -0
- package/dist/src/index.d.ts +1 -0
- package/dist/src/index.js +3 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/utils.d.ts +5 -0
- package/dist/src/utils.js +27 -0
- package/dist/src/utils.js.map +1 -0
- package/package.json +99 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 pp-payment
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# pp-browser
|
|
2
|
+
|
|
3
|
+
Tools to integrate PonchoPay on the browser
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
There are 2 ways to use this package:
|
|
8
|
+
|
|
9
|
+
### HTML import
|
|
10
|
+
|
|
11
|
+
You can import the compiled file directly from our servers:
|
|
12
|
+
|
|
13
|
+
```html
|
|
14
|
+
<script
|
|
15
|
+
type="module"
|
|
16
|
+
src="https://pay.ponchopay.com/api/integration/generic/asset/pp-browser.min.js"
|
|
17
|
+
></script>
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
After this HTML declaration, you will be able to use the web component.
|
|
21
|
+
|
|
22
|
+
### NPM installation
|
|
23
|
+
|
|
24
|
+
You can install the module from `npm`:
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npm i @ponchopay/pp-browser
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
After this command, you can import the web componet like this:
|
|
31
|
+
|
|
32
|
+
```js
|
|
33
|
+
import '@ponchopay/pp-browser';
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Using the web component
|
|
37
|
+
|
|
38
|
+
The web component can be used by declaring it in HTML like this:
|
|
39
|
+
|
|
40
|
+
```html
|
|
41
|
+
<pp-payment {properties}>{text}</pp-payment>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
The following the list of accepted properties (please, refer to the [official documentation](https://ponchocare.notion.site/PonchoPay-API-integration-04bc3f5220ff4028b0078793bfc03abc) for their meaning):
|
|
45
|
+
|
|
46
|
+
| Name | Mandatory |
|
|
47
|
+
| -------- | --------- |
|
|
48
|
+
| token | Yes |
|
|
49
|
+
| metadata | Yes |
|
|
50
|
+
| urn | Yes |
|
|
51
|
+
| amount | Yes |
|
|
52
|
+
| email | Yes |
|
|
53
|
+
| note | No |
|
|
54
|
+
|
|
55
|
+
The component's text is optional being "Pay with PonchoPay" the default text. Feel free to change it as you see fit.
|
|
56
|
+
|
|
57
|
+
## Considerations
|
|
58
|
+
|
|
59
|
+
Unfortunately, this web component required `HTMLElement` class to exist which means that it is not suitable for Server Side Rendering applications.
|
|
60
|
+
There are, however, some techniques that can be used to mitigate this.
|
|
61
|
+
|
|
62
|
+
### SvelteKit
|
|
63
|
+
|
|
64
|
+
When using SvelteKit, the component import can be pushed to the `onMount` event:
|
|
65
|
+
|
|
66
|
+
```svelte
|
|
67
|
+
<script>
|
|
68
|
+
import { onMount } from 'svelte';
|
|
69
|
+
|
|
70
|
+
onMount(async () => {
|
|
71
|
+
await import('@ponchopay/pp-browser');
|
|
72
|
+
});
|
|
73
|
+
</script>
|
|
74
|
+
|
|
75
|
+
<pp-payment>It worked!</pp-payment>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Alternatively, the route can be made non-ssr by exporting [`export const ssr = false;`](https://kit.svelte.dev/docs/page-options#ssr) in the loader file.
|
|
79
|
+
|
|
80
|
+
## Development
|
|
81
|
+
|
|
82
|
+
### Linting and formatting
|
|
83
|
+
|
|
84
|
+
To scan the project for linting and formatting errors, run
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npm run lint
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
To automatically fix linting and formatting errors, run
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
npm run format
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Tooling configs
|
|
97
|
+
|
|
98
|
+
For most of the tools, the configuration is in the `package.json` to reduce the amount of files in the project.
|
|
99
|
+
|
|
100
|
+
## Local Demo with `web-dev-server`
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
npm start
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
To run a local development server that serves the basic demo located in `demo/index.html`
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export declare class PpPayment extends HTMLElement {
|
|
2
|
+
private sr;
|
|
3
|
+
constructor();
|
|
4
|
+
private redrawContents;
|
|
5
|
+
set token(value: string);
|
|
6
|
+
get token(): string;
|
|
7
|
+
set metadata(value: string);
|
|
8
|
+
get metadata(): string;
|
|
9
|
+
set urn(value: string);
|
|
10
|
+
get urn(): string;
|
|
11
|
+
set amount(value: string | number);
|
|
12
|
+
get amount(): string;
|
|
13
|
+
set email(value: string);
|
|
14
|
+
get email(): string;
|
|
15
|
+
set note(value: string);
|
|
16
|
+
get note(): string;
|
|
17
|
+
attributeChangedCallback(): void;
|
|
18
|
+
static get observedAttributes(): string[];
|
|
19
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { buildButton, buildForm, buildHiddenInput, buildSlot, buildStyle, } from './utils';
|
|
2
|
+
const PONCHO_PAY = 'https://pay.ponchopay.com/api/integration/generic/initiate';
|
|
3
|
+
const ATTRIBUTES = ['token', 'metadata', 'urn', 'amount', 'email', 'note'];
|
|
4
|
+
const STYLES = [
|
|
5
|
+
'width: 100%',
|
|
6
|
+
'background-color: #02C2A0',
|
|
7
|
+
'white-space: nowrap',
|
|
8
|
+
'text-decoration-line: none',
|
|
9
|
+
'border-radius: .25rem',
|
|
10
|
+
'box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05)',
|
|
11
|
+
'text-align: center',
|
|
12
|
+
'font-size: 1.25rem',
|
|
13
|
+
'line-height: 1.75rem',
|
|
14
|
+
'color: white',
|
|
15
|
+
'margin-top: .5rem',
|
|
16
|
+
'margin-bottom: .75rem',
|
|
17
|
+
'padding: .75rem 1rem',
|
|
18
|
+
'display: flex',
|
|
19
|
+
'flex-wrap: nowrap',
|
|
20
|
+
'align-items: center',
|
|
21
|
+
'justify-content: space-evenly',
|
|
22
|
+
'cursor: pointer',
|
|
23
|
+
'text-transform: none',
|
|
24
|
+
'box-sizing: border-box',
|
|
25
|
+
'border-width: 0',
|
|
26
|
+
'border-style: solid',
|
|
27
|
+
'border-color: currentColor',
|
|
28
|
+
];
|
|
29
|
+
export class PpPayment extends HTMLElement {
|
|
30
|
+
constructor() {
|
|
31
|
+
super();
|
|
32
|
+
this.sr = this.attachShadow({ mode: 'open' });
|
|
33
|
+
this.redrawContents();
|
|
34
|
+
}
|
|
35
|
+
redrawContents() {
|
|
36
|
+
this.sr.replaceChildren();
|
|
37
|
+
this.sr.appendChild(buildForm(PONCHO_PAY, ...ATTRIBUTES.filter(name => { var _a; return ((_a = this.getAttribute(name)) !== null && _a !== void 0 ? _a : '') !== ''; }).map(name => buildHiddenInput(name, this.getAttribute(name))), buildStyle(`button { ${STYLES.join(';')} ${this.getAttribute('style')} } button:active { transform: translate(1px,1px); }`), buildButton(buildSlot('Pay with PonchoPay'))));
|
|
38
|
+
}
|
|
39
|
+
set token(value) {
|
|
40
|
+
this.setAttribute('token', value);
|
|
41
|
+
}
|
|
42
|
+
get token() {
|
|
43
|
+
var _a;
|
|
44
|
+
return (_a = this.getAttribute('token')) !== null && _a !== void 0 ? _a : '';
|
|
45
|
+
}
|
|
46
|
+
set metadata(value) {
|
|
47
|
+
this.setAttribute('metadata', value);
|
|
48
|
+
}
|
|
49
|
+
get metadata() {
|
|
50
|
+
var _a;
|
|
51
|
+
return (_a = this.getAttribute('metadata')) !== null && _a !== void 0 ? _a : '';
|
|
52
|
+
}
|
|
53
|
+
set urn(value) {
|
|
54
|
+
this.setAttribute('urn', value);
|
|
55
|
+
}
|
|
56
|
+
get urn() {
|
|
57
|
+
var _a;
|
|
58
|
+
return (_a = this.getAttribute('urn')) !== null && _a !== void 0 ? _a : '';
|
|
59
|
+
}
|
|
60
|
+
set amount(value) {
|
|
61
|
+
this.setAttribute('amount', String(value));
|
|
62
|
+
}
|
|
63
|
+
get amount() {
|
|
64
|
+
var _a;
|
|
65
|
+
return (_a = this.getAttribute('amount')) !== null && _a !== void 0 ? _a : '';
|
|
66
|
+
}
|
|
67
|
+
set email(value) {
|
|
68
|
+
this.setAttribute('email', value);
|
|
69
|
+
}
|
|
70
|
+
get email() {
|
|
71
|
+
var _a;
|
|
72
|
+
return (_a = this.getAttribute('email')) !== null && _a !== void 0 ? _a : '';
|
|
73
|
+
}
|
|
74
|
+
set note(value) {
|
|
75
|
+
this.setAttribute('note', value);
|
|
76
|
+
}
|
|
77
|
+
get note() {
|
|
78
|
+
var _a;
|
|
79
|
+
return (_a = this.getAttribute('note')) !== null && _a !== void 0 ? _a : '';
|
|
80
|
+
}
|
|
81
|
+
attributeChangedCallback() {
|
|
82
|
+
this.redrawContents();
|
|
83
|
+
}
|
|
84
|
+
static get observedAttributes() {
|
|
85
|
+
return ATTRIBUTES;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=PpPayment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PpPayment.js","sourceRoot":"","sources":["../../src/PpPayment.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n buildButton,\n buildForm,\n buildHiddenInput,\n buildSlot,\n buildStyle,\n} from './utils';\n\nconst PONCHO_PAY = 'https://pay.ponchopay.com/api/integration/generic/initiate';\nconst ATTRIBUTES = ['token', 'metadata', 'urn', 'amount', 'email', 'note'];\nconst STYLES = [\n 'width: 100%',\n 'background-color: #02C2A0',\n 'white-space: nowrap',\n 'text-decoration-line: none',\n 'border-radius: .25rem',\n 'box-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05)',\n 'text-align: center',\n 'font-size: 1.25rem',\n 'line-height: 1.75rem',\n 'color: white',\n 'margin-top: .5rem',\n 'margin-bottom: .75rem',\n 'padding: .75rem 1rem',\n 'display: flex',\n 'flex-wrap: nowrap',\n 'align-items: center',\n 'justify-content: space-evenly',\n 'cursor: pointer',\n 'text-transform: none',\n 'box-sizing: border-box',\n 'border-width: 0',\n 'border-style: solid',\n 'border-color: currentColor',\n];\n\nexport class PpPayment extends HTMLElement {\n private sr: ShadowRoot;\n\n public constructor() {\n super();\n\n this.sr = this.attachShadow({ mode: 'open' });\n this.redrawContents();\n }\n\n private redrawContents(): void {\n this.sr.replaceChildren();\n this.sr.appendChild(\n buildForm(\n PONCHO_PAY,\n ...ATTRIBUTES.filter(\n name => (this.getAttribute(name) ?? '') !== ''\n ).map(name => buildHiddenInput(name, this.getAttribute(name)!)),\n buildStyle(\n `button { ${STYLES.join(';')} ${this.getAttribute(\n 'style'\n )} } button:active { transform: translate(1px,1px); }`\n ),\n buildButton(buildSlot('Pay with PonchoPay'))\n )\n );\n }\n\n public set token(value: string) {\n this.setAttribute('token', value);\n }\n\n public get token(): string {\n return this.getAttribute('token') ?? '';\n }\n\n public set metadata(value: string) {\n this.setAttribute('metadata', value);\n }\n\n public get metadata(): string {\n return this.getAttribute('metadata') ?? '';\n }\n\n public set urn(value: string) {\n this.setAttribute('urn', value);\n }\n\n public get urn(): string {\n return this.getAttribute('urn') ?? '';\n }\n\n public set amount(value: string | number) {\n this.setAttribute('amount', String(value));\n }\n\n public get amount(): string {\n return this.getAttribute('amount') ?? '';\n }\n\n public set email(value: string) {\n this.setAttribute('email', value);\n }\n\n public get email(): string {\n return this.getAttribute('email') ?? '';\n }\n\n public set note(value: string) {\n this.setAttribute('note', value);\n }\n\n public get note(): string {\n return this.getAttribute('note') ?? '';\n }\n\n public attributeChangedCallback(): void {\n this.redrawContents();\n }\n\n public static get observedAttributes() {\n return ATTRIBUTES;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,YAAY,EAAE,SAAS,CAAC,CAAC","sourcesContent":["import { PpPayment } from './PpPayment.js';\n\nwindow.customElements.define('pp-payment', PpPayment);\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare function buildHiddenInput(name: string, value: string): HTMLInputElement;
|
|
2
|
+
export declare function buildForm(action: string, ...elements: HTMLElement[]): HTMLFormElement;
|
|
3
|
+
export declare function buildSlot(fallback: HTMLElement[] | string): HTMLSlotElement;
|
|
4
|
+
export declare function buildButton(children: HTMLElement): HTMLButtonElement;
|
|
5
|
+
export declare function buildStyle(styles: string): HTMLStyleElement;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function buildElement(tag, props, children) {
|
|
2
|
+
const element = document.createElement(tag);
|
|
3
|
+
Object.entries(props !== null && props !== void 0 ? props : {}).forEach(([key, value]) => element.setAttribute(key, value));
|
|
4
|
+
if (typeof children === 'string') {
|
|
5
|
+
element.innerText = children;
|
|
6
|
+
}
|
|
7
|
+
else if (Array.isArray(children)) {
|
|
8
|
+
children.forEach(element.appendChild.bind(element));
|
|
9
|
+
}
|
|
10
|
+
return element;
|
|
11
|
+
}
|
|
12
|
+
export function buildHiddenInput(name, value) {
|
|
13
|
+
return buildElement('input', { type: 'hidden', name, value });
|
|
14
|
+
}
|
|
15
|
+
export function buildForm(action, ...elements) {
|
|
16
|
+
return buildElement('form', { action, method: 'post' }, elements);
|
|
17
|
+
}
|
|
18
|
+
export function buildSlot(fallback) {
|
|
19
|
+
return buildElement('slot', {}, fallback);
|
|
20
|
+
}
|
|
21
|
+
export function buildButton(children) {
|
|
22
|
+
return buildElement('button', { type: 'submit' }, [children]);
|
|
23
|
+
}
|
|
24
|
+
export function buildStyle(styles) {
|
|
25
|
+
return buildElement('style', {}, styles);
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,SAAS,YAAY,CACnB,GAAS,EACT,KAA4C,EAC5C,QAAiC;IAEjC,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,CAAC,OAAO,CAAC,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CACnD,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,KAAK,CAAC,CACjC,CAAC;IACF,IAAI,OAAO,QAAQ,KAAK,QAAQ,EAAE;QAChC,OAAO,CAAC,SAAS,GAAG,QAAQ,CAAC;KAC9B;SAAM,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE;QAClC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;KACrD;IACD,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,IAAY,EACZ,KAAa;IAEb,OAAO,YAAY,CAAC,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,SAAS,CACvB,MAAc,EACd,GAAG,QAAuB;IAE1B,OAAO,YAAY,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,QAAQ,CAAC,CAAC;AACpE,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,QAAgC;IACxD,OAAO,YAAY,CAAC,MAAM,EAAE,EAAE,EAAE,QAAQ,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,QAAqB;IAC/C,OAAO,YAAY,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,MAAc;IACvC,OAAO,YAAY,CAAC,OAAO,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["function buildElement<TTag extends keyof HTMLElementTagNameMap>(\n tag: TTag,\n props?: Partial<HTMLElementTagNameMap[TTag]>,\n children?: HTMLElement[] | string\n): HTMLElementTagNameMap[TTag] {\n const element = document.createElement(tag);\n Object.entries(props ?? {}).forEach(([key, value]) =>\n element.setAttribute(key, value)\n );\n if (typeof children === 'string') {\n element.innerText = children;\n } else if (Array.isArray(children)) {\n children.forEach(element.appendChild.bind(element));\n }\n return element;\n}\n\nexport function buildHiddenInput(\n name: string,\n value: string\n): HTMLInputElement {\n return buildElement('input', { type: 'hidden', name, value });\n}\n\nexport function buildForm(\n action: string,\n ...elements: HTMLElement[]\n): HTMLFormElement {\n return buildElement('form', { action, method: 'post' }, elements);\n}\n\nexport function buildSlot(fallback: HTMLElement[] | string): HTMLSlotElement {\n return buildElement('slot', {}, fallback);\n}\n\nexport function buildButton(children: HTMLElement): HTMLButtonElement {\n return buildElement('button', { type: 'submit' }, [children]);\n}\n\nexport function buildStyle(styles: string): HTMLStyleElement {\n return buildElement('style', {}, styles);\n}\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ponchopay/pp-browser",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "Tools to integrate PonchoPay on the browser",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/src/index.js",
|
|
7
|
+
"module": "dist/src/index.js",
|
|
8
|
+
"types": "dist/src/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "dist/src/index.d.ts",
|
|
12
|
+
"import": "dist/src/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./pp-payment": {
|
|
15
|
+
"types": "dist/src/PpPayment.d.ts",
|
|
16
|
+
"import": "dist/src/PpPayment.js"
|
|
17
|
+
},
|
|
18
|
+
"./package.json": "./package.json"
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist/src"
|
|
22
|
+
],
|
|
23
|
+
"scripts": {
|
|
24
|
+
"clean": "rimraf build dist",
|
|
25
|
+
"start": "npm run clean && tsc && concurrently -k -r \"tsc --watch --preserveWatchOutput\" \"wds\"",
|
|
26
|
+
"build": "npm run clean && tsc && rollup -c",
|
|
27
|
+
"prepublish": "npm run clean && tsc",
|
|
28
|
+
"lint": "eslint --ext .ts,.html . --ignore-path .gitignore && prettier \"**/*.ts\" --check --ignore-path .gitignore",
|
|
29
|
+
"format": "eslint --ext .ts,.html . --fix --ignore-path .gitignore && prettier \"**/*.ts\" --write --ignore-path .gitignore"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@open-wc/eslint-config": "^9.2.1",
|
|
34
|
+
"@rollup/plugin-terser": "^0.4.3",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^5.48.0",
|
|
36
|
+
"@typescript-eslint/parser": "^5.48.0",
|
|
37
|
+
"@web/dev-server": "^0.1.34",
|
|
38
|
+
"concurrently": "^5.3.0",
|
|
39
|
+
"eslint": "^8.31.0",
|
|
40
|
+
"eslint-config-prettier": "^8.3.0",
|
|
41
|
+
"husky": "^4.3.8",
|
|
42
|
+
"lint-staged": "^10.5.4",
|
|
43
|
+
"prettier": "^2.4.1",
|
|
44
|
+
"rimraf": "^5.0.1",
|
|
45
|
+
"rollup": "^3.29.0",
|
|
46
|
+
"tslib": "^2.3.1",
|
|
47
|
+
"typescript": "^4.5.2"
|
|
48
|
+
},
|
|
49
|
+
"repository": {
|
|
50
|
+
"type": "git",
|
|
51
|
+
"url": "git+https://github.com/ponchocare/pp-browser.git"
|
|
52
|
+
},
|
|
53
|
+
"keywords": [
|
|
54
|
+
"ponchopay",
|
|
55
|
+
"web",
|
|
56
|
+
"component",
|
|
57
|
+
"tools"
|
|
58
|
+
],
|
|
59
|
+
"author": "info@ponchopay.com",
|
|
60
|
+
"license": "MIT",
|
|
61
|
+
"bugs": {
|
|
62
|
+
"url": "https://github.com/ponchocare/pp-browser/issues"
|
|
63
|
+
},
|
|
64
|
+
"homepage": "https://github.com/ponchocare/pp-browser#readme",
|
|
65
|
+
"eslintConfig": {
|
|
66
|
+
"parser": "@typescript-eslint/parser",
|
|
67
|
+
"extends": [
|
|
68
|
+
"@open-wc",
|
|
69
|
+
"prettier"
|
|
70
|
+
],
|
|
71
|
+
"plugins": [
|
|
72
|
+
"@typescript-eslint"
|
|
73
|
+
],
|
|
74
|
+
"rules": {
|
|
75
|
+
"no-undef": "off",
|
|
76
|
+
"no-unused-vars": "off",
|
|
77
|
+
"@typescript-eslint/no-unused-vars": [
|
|
78
|
+
"error"
|
|
79
|
+
],
|
|
80
|
+
"import/no-unresolved": "off",
|
|
81
|
+
"import/extensions": "off"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
"prettier": {
|
|
85
|
+
"singleQuote": true,
|
|
86
|
+
"arrowParens": "avoid"
|
|
87
|
+
},
|
|
88
|
+
"husky": {
|
|
89
|
+
"hooks": {
|
|
90
|
+
"pre-commit": "lint-staged"
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
"lint-staged": {
|
|
94
|
+
"*.ts": [
|
|
95
|
+
"eslint --fix",
|
|
96
|
+
"prettier --write"
|
|
97
|
+
]
|
|
98
|
+
}
|
|
99
|
+
}
|