bysquare 2.12.1 → 2.12.3

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/README.md CHANGED
@@ -26,7 +26,7 @@ individuals and businesses to create QR codes for their invoices.
26
26
  [mozzila-esm]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
27
27
  [mozzila-import]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import
28
28
 
29
- ### npm
29
+ ### [npm](https://npmjs.com/bysquare)
30
30
 
31
31
  ```sh
32
32
  $ npm install bysquare
@@ -40,27 +40,94 @@ $ npm install bysquare
40
40
  </script>
41
41
  ```
42
42
 
43
- ## Usage
43
+ ## Quick start
44
44
 
45
- ### Basic Usage
45
+ There are helper functions for the most common use cases, such as simple payment,
46
+ direct debit, and standing order. Also you can use `encode` and `decode` functions
47
+ to work with the data model directly.
46
48
 
47
- Simple helper functions to wrap encoding for most common use cases.
49
+ ### Simple Payment
48
50
 
49
- - `simplePayment` - Encode simple payment data.
50
- - `directDebit` - Encode direct debit data.
51
- - `standingOrder` - Encode standing order data.
52
-
53
- ```typescript
54
- import { simplePayment } from "bysquare";
51
+ ```js
52
+ import {
53
+ CurrencyCode,
54
+ simplePayment,
55
+ } from "bysquare";
55
56
 
56
57
  const qrstring = simplePayment({
57
- amount: 100,
58
+ amount: 50.75,
59
+ iban: "SK9611000000002918599669",
58
60
  variableSymbol: "123456",
59
61
  currencyCode: CurrencyCode.EUR,
62
+ });
63
+ ```
64
+
65
+ ### Direct Debit
66
+
67
+ ```js
68
+ import {
69
+ CurrencyCode,
70
+ directDebit,
71
+ } from "bysquare";
72
+
73
+ const qrstring = directDebit({
74
+ amount: 25.00,
60
75
  iban: "SK9611000000002918599669",
76
+ variableSymbol: "789012",
77
+ currencyCode: CurrencyCode.EUR,
61
78
  });
62
79
  ```
63
80
 
81
+ ### Standing Order
82
+
83
+ ```js
84
+ import {
85
+ CurrencyCode,
86
+ Periodicity,
87
+ standingOrder,
88
+ } from "bysquare";
89
+
90
+ const qrstring = standingOrder({
91
+ amount: 100.00,
92
+ iban: "SK9611000000002918599669",
93
+ variableSymbol: "654321",
94
+ day: 15,
95
+ periodicity: Periodicity.Monthly,
96
+ });
97
+ ```
98
+
99
+ ### HTML example
100
+
101
+ This example shows how to generate a payment QR code and display it in a web
102
+ page:
103
+
104
+ ```html
105
+ <!DOCTYPE html>
106
+ <html lang="en">
107
+ <head>
108
+ <meta charset="UTF-8">
109
+ <title>Payment QR Code</title>
110
+ </head>
111
+ <body>
112
+ <div id="qrcode" style="width: 200px"></div>
113
+
114
+ <script type="module">
115
+ import { QRCode } from "https://esm.sh/@lostinbrittany/qr-esm@latest";
116
+ import { simplePayment } from "https://esm.sh/bysquare@latest";
117
+
118
+ const qrstring = simplePayment({
119
+ amount: 123.45,
120
+ iban: "SK9611000000002918599669",
121
+ variableSymbol: "987654",
122
+ });
123
+
124
+ const qrElement = document.getElementById('qrcode');
125
+ qrElement.appendChild(QRCode.generateSVG(qrstring));
126
+ </script>
127
+ </body>
128
+ </html>
129
+ ```
130
+
64
131
  ### Adavanced usage
65
132
 
66
133
  For more complex data use `encode` and `decode` functions:
@@ -91,9 +158,13 @@ const data = {
91
158
  amount: 100.0,
92
159
  variableSymbol: "123",
93
160
  paymentNote: "hello world",
94
- bankAccounts: [{ iban: "SK9611000000002918599669" }],
161
+ bankAccounts: [
162
+ { iban: "SK9611000000002918599669" },
163
+ // ...more bank accounts
164
+ ],
95
165
  // ...more fields
96
166
  },
167
+ // ...more payments
97
168
  ],
98
169
  } satisfies DataModel;
99
170
 
@@ -130,7 +201,9 @@ $ bysquare --decode <qrstring>
130
201
 
131
202
  ## How it works
132
203
 
133
- ### Encoding sequence
204
+ ### Data Flow
205
+
206
+ ### Encoding/Decoding Architecture
134
207
 
135
208
  <image src="./docs/logic.svg" alt="encode" width="500px">
136
209
 
package/dist/decode.d.ts CHANGED
@@ -1,22 +1,21 @@
1
1
  import { DataModel } from "./index.js";
2
- export declare enum DecodeErrorMessage {
3
- MissingIBAN = "IBAN is missing",
2
+ export declare const DecodeErrorMessage: {
3
+ readonly MissingIBAN: "IBAN is missing";
4
4
  /**
5
5
  * @description - find original LZMA error in extensions
6
6
  */
7
- LZMADecompressionFailed = "LZMA decompression failed",
7
+ readonly LZMADecompressionFailed: "LZMA decompression failed";
8
8
  /**
9
9
  * @description - find found version in extensions
10
10
  * @see {@link ./types#Version} for valid ranges
11
11
  */
12
- UnsupportedVersion = "Unsupported version"
13
- }
12
+ readonly UnsupportedVersion: "Unsupported version";
13
+ };
14
14
  export declare class DecodeError extends Error {
15
- name: string;
16
15
  extensions?: {
17
16
  [name: string]: any;
18
17
  };
19
- constructor(message: DecodeErrorMessage, extensions?: {
18
+ constructor(message: string, extensions?: {
20
19
  [name: string]: any;
21
20
  });
22
21
  }
package/dist/decode.js CHANGED
@@ -1,24 +1,23 @@
1
1
  import { decompress } from "lzma1";
2
2
  import * as base32hex from "./base32hex.js";
3
3
  import { CurrencyCode, PaymentOptions, Version, } from "./index.js";
4
- export var DecodeErrorMessage;
5
- (function (DecodeErrorMessage) {
6
- DecodeErrorMessage["MissingIBAN"] = "IBAN is missing";
4
+ export const DecodeErrorMessage = {
5
+ MissingIBAN: "IBAN is missing",
7
6
  /**
8
7
  * @description - find original LZMA error in extensions
9
8
  */
10
- DecodeErrorMessage["LZMADecompressionFailed"] = "LZMA decompression failed";
9
+ LZMADecompressionFailed: "LZMA decompression failed",
11
10
  /**
12
11
  * @description - find found version in extensions
13
12
  * @see {@link ./types#Version} for valid ranges
14
13
  */
15
- DecodeErrorMessage["UnsupportedVersion"] = "Unsupported version";
16
- })(DecodeErrorMessage || (DecodeErrorMessage = {}));
14
+ UnsupportedVersion: "Unsupported version",
15
+ };
17
16
  export class DecodeError extends Error {
18
- name = "DecodeError";
19
17
  extensions;
20
18
  constructor(message, extensions) {
21
19
  super(message);
20
+ this.name = this.constructor.name;
22
21
  if (extensions) {
23
22
  this.extensions = extensions;
24
23
  }
package/dist/encode.d.ts CHANGED
@@ -1,34 +1,33 @@
1
1
  import { DataModel } from "./types.js";
2
- export declare enum EncodeErrorMessage {
2
+ export declare const EncodeErrorMessage: {
3
3
  /**
4
4
  * @description - find invalid value in extensions
5
5
  */
6
- BySquareType = "Invalid BySquareType value in header, valid range <0,15>",
6
+ readonly BySquareType: "Invalid BySquareType value in header, valid range <0,15>";
7
7
  /**
8
8
  * @description - find invalid value in extensions
9
9
  * @see {@link ./types#Version} for valid ranges
10
10
  */
11
- Version = "Invalid Version value in header",
11
+ readonly Version: "Invalid Version value in header";
12
12
  /**
13
13
  * @description - find invalid value in extensions
14
14
  */
15
- DocumentType = "Invalid DocumentType value in header, valid range <0,15>",
15
+ readonly DocumentType: "Invalid DocumentType value in header, valid range <0,15>";
16
16
  /**
17
17
  * @description - find invalid value in extensions
18
18
  */
19
- Reserved = "Invalid Reserved value in header, valid range <0,15>",
19
+ readonly Reserved: "Invalid Reserved value in header, valid range <0,15>";
20
20
  /**
21
21
  * @description - find actual size of header in extensions
22
22
  * @see MAX_COMPRESSED_SIZE
23
23
  */
24
- HeaderDataSize = "Allowed header data size exceeded"
25
- }
24
+ readonly HeaderDataSize: "Allowed header data size exceeded";
25
+ };
26
26
  export declare class EncodeError extends Error {
27
- name: string;
28
27
  extensions?: {
29
28
  [name: string]: any;
30
29
  };
31
- constructor(message: EncodeErrorMessage, extensions?: {
30
+ constructor(message: string, extensions?: {
32
31
  [name: string]: any;
33
32
  });
34
33
  }
package/dist/encode.js CHANGED
@@ -4,36 +4,35 @@ import { crc32 } from "./crc32.js";
4
4
  import { deburr } from "./deburr.js";
5
5
  import { PaymentOptions, Version, } from "./types.js";
6
6
  import { validateDataModel } from "./validations.js";
7
- export var EncodeErrorMessage;
8
- (function (EncodeErrorMessage) {
7
+ export const EncodeErrorMessage = {
9
8
  /**
10
9
  * @description - find invalid value in extensions
11
10
  */
12
- EncodeErrorMessage["BySquareType"] = "Invalid BySquareType value in header, valid range <0,15>";
11
+ BySquareType: "Invalid BySquareType value in header, valid range <0,15>",
13
12
  /**
14
13
  * @description - find invalid value in extensions
15
14
  * @see {@link ./types#Version} for valid ranges
16
15
  */
17
- EncodeErrorMessage["Version"] = "Invalid Version value in header";
16
+ Version: "Invalid Version value in header",
18
17
  /**
19
18
  * @description - find invalid value in extensions
20
19
  */
21
- EncodeErrorMessage["DocumentType"] = "Invalid DocumentType value in header, valid range <0,15>";
20
+ DocumentType: "Invalid DocumentType value in header, valid range <0,15>",
22
21
  /**
23
22
  * @description - find invalid value in extensions
24
23
  */
25
- EncodeErrorMessage["Reserved"] = "Invalid Reserved value in header, valid range <0,15>";
24
+ Reserved: "Invalid Reserved value in header, valid range <0,15>",
26
25
  /**
27
26
  * @description - find actual size of header in extensions
28
27
  * @see MAX_COMPRESSED_SIZE
29
28
  */
30
- EncodeErrorMessage["HeaderDataSize"] = "Allowed header data size exceeded";
31
- })(EncodeErrorMessage || (EncodeErrorMessage = {}));
29
+ HeaderDataSize: "Allowed header data size exceeded",
30
+ };
32
31
  export class EncodeError extends Error {
33
- name = "EncodeError";
34
32
  extensions;
35
33
  constructor(message, extensions) {
36
34
  super(message);
35
+ this.name = this.constructor.name;
37
36
  if (extensions) {
38
37
  this.extensions = extensions;
39
38
  }