bysquare 2.6.0 → 2.7.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/README.md CHANGED
@@ -1,8 +1,9 @@
1
1
  # bysquare
2
2
 
3
- ![version][version] ![build][build]
3
+ ![version][version]
4
+ ![build][build]
4
5
 
5
- Simple JavaScript library to generate and parse "PAY by square" string.
6
+ Simple JavaScript library to encode and decode "PAY by square" string.
6
7
 
7
8
  **What is `PAY by square`?**
8
9
 
@@ -18,6 +19,10 @@ transformed into images depends on how you implement it. See
18
19
 
19
20
  ## Install
20
21
 
22
+ **NOTE**: This package is native [ESM][mozzila-esm] and no longer provides a
23
+ CommonJS export. If your project uses CommonJS, you will have to convert to ESM
24
+ or use the dynamic [`import()`][mozzila-import] function.
25
+
21
26
  **npm registry**
22
27
 
23
28
  ```sh
@@ -28,14 +33,14 @@ npm install bysquare
28
33
 
29
34
  ```html
30
35
  <script type="module">
31
- import { generate, parse } from "https://esm.sh/bysquare@2.4.0/";
36
+ import { encode, decode } from "https://esm.sh/bysquare@2.4.0/";
32
37
  </script>
33
38
  ```
34
39
 
35
40
  **Deno** `v1.28+`, just import `npm:bysquare` `v2.1.0+`
36
41
 
37
42
  ```ts
38
- import { generate, parse } from "npm:bysquare@2.1.0"
43
+ import { encode, decode } from "npm:bysquare@2.1.0";
39
44
  ```
40
45
 
41
46
  **CLI** (Node.JS `v18`+)
@@ -53,42 +58,45 @@ npm install --global bysquare
53
58
  # API
54
59
 
55
60
  ```ts
56
- generate(model: DataModel, options?: Options): string
57
- parse(qr: string): DataModel
61
+ encode(model: DataModel, options?: Options): string
62
+ decode(qr: string): DataModel
58
63
  detect(qr: string): Boolean
59
64
  ```
60
65
 
61
66
  # Usage
62
67
 
63
- ## Generate
68
+ ## Encode
64
69
 
65
70
  ```ts
66
- import { CurrencyCode, DataModel, generate, PaymentOptions } from "bysquare"
71
+ import { CurrencyCode, DataModel, encode, PaymentOptions } from "bysquare";
67
72
 
68
73
  // string ready to be encoded to QR
69
- const qrString = generate({
74
+ const qrString = encode({
70
75
  invoiceId: "random-id",
71
76
  payments: [
72
77
  {
73
78
  type: PaymentOptions.PaymentOrder,
74
79
  amount: 100.0,
75
80
  bankAccounts: [
76
- { iban: "SK9611000000002918599669" }
81
+ {
82
+ iban: "SK9611000000002918599669",
83
+ },
77
84
  ],
78
85
  currencyCode: CurrencyCode.EUR,
79
- variableSymbol: "123"
80
- }
81
- ]
82
- })
86
+ variableSymbol: "123",
87
+ },
88
+ ],
89
+ });
83
90
  ```
84
91
 
85
- ## Parse
92
+ ## Decode
86
93
 
87
94
  ```ts
88
- import { parse } from "bysquare"
95
+ import { decode } from "bysquare";
89
96
 
90
- const model =
91
- parse("0405QH8090IFU27IV0J6HGGLIOTIBVHNQQJQ6LAVGNBT363HR13JC6CB54HSI0KH9FCRASHNQBSKAQD2LJ4AU400UVKDNDPFRKLOBEVVVU0QJ000")
97
+ const model = decode(
98
+ "0405QH8090IFU27IV0J6HGGLIOTIBVHNQQJQ6LAVGNBT363HR13JC6CB54HSI0KH9FCRASHNQBSKAQD2LJ4AU400UVKDNDPFRKLOBEVVVU0QJ000"
99
+ );
92
100
 
93
101
  // {
94
102
  // invoiceId: "random-id",
@@ -107,7 +115,9 @@ const model =
107
115
  //
108
116
  ```
109
117
 
110
- ## CLI
118
+ # CLI
119
+
120
+ ## Encode
111
121
 
112
122
  Encode JSON data from a file and print the corresponding QR code. The file
113
123
  argument should be a path to a JSON file.
@@ -116,6 +126,8 @@ argument should be a path to a JSON file.
116
126
  npx bysquare --encode <file>
117
127
  ```
118
128
 
129
+ ## Decode
130
+
119
131
  Decode the specified QR code string and print the corresponding JSON data. The
120
132
  qrstring argument should be a valid QR code string.
121
133
 
@@ -125,12 +137,14 @@ npx bysquare --decode <qrstring>
125
137
 
126
138
  ## Related
127
139
 
128
- - <https://bysquare.com/>
129
- - <https://devel.cz/otazka/qr-kod-pay-by-square>
130
- - <https://github.com/matusf/pay-by-square>
131
- - <https://www.bsqr.co/schema/>
132
- - <https://www.sbaonline.sk/wp-content/uploads/2020/03/pay-by-square-specifications-1_1_0.pdf>
133
- - <https://www.vutbr.cz/studenti/zav-prace/detail/78439>
140
+ - <https://bysquare.com/>
141
+ - <https://devel.cz/otazka/qr-kod-pay-by-square>
142
+ - <https://github.com/matusf/pay-by-square>
143
+ - <https://www.bsqr.co/schema/>
144
+ - <https://www.sbaonline.sk/wp-content/uploads/2020/03/pay-by-square-specifications-1_1_0.pdf>
145
+ - <https://www.vutbr.cz/studenti/zav-prace/detail/78439>
134
146
 
135
147
  [build]: https://img.shields.io/github/actions/workflow/status/xseman/bysquare/tests.yml
136
148
  [version]: https://img.shields.io/npm/v/bysquare
149
+ [mozzila-esm]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules
150
+ [mozzila-import]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/import
package/dist/cli.js CHANGED
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { existsSync, readFileSync } from "node:fs";
3
3
  import { parseArgs } from "node:util";
4
- import { generate } from "./generate.js";
5
- import { parse } from "./parse.js";
4
+ import { encode } from "./encode.js";
5
+ import { decode } from "./decode.js";
6
6
  const args = parseArgs({
7
7
  allowPositionals: true,
8
8
  options: {
@@ -26,7 +26,7 @@ if (process.stdin.isTTY) {
26
26
  const file = args.values.encode;
27
27
  if (existsSync(file)) {
28
28
  const data = readFileSync(file, "utf8");
29
- console.log(generate(JSON.parse(data)));
29
+ console.log(encode(JSON.parse(data)));
30
30
  }
31
31
  else {
32
32
  console.error(`File ${file} doesn't exists`);
@@ -36,7 +36,7 @@ if (process.stdin.isTTY) {
36
36
  /** input string */
37
37
  if (args.values.decode) {
38
38
  const qrstring = args.values.decode;
39
- console.log(JSON.stringify(parse(qrstring), null, 4));
39
+ console.log(JSON.stringify(decode(qrstring), null, 4));
40
40
  }
41
41
  if (args.values.help || Object.keys(args.values).length === 0) {
42
42
  console.log([
@@ -10,12 +10,15 @@ export declare class DecodeError extends Error {
10
10
  name: string;
11
11
  constructor(cause: Error, msg?: string);
12
12
  }
13
+ /** @deprecated */
14
+ export declare const parse: typeof decode;
13
15
  /**
14
16
  * Decoding client data from QR Code 2005 symbol
15
17
  *
16
18
  * @see 3.16.
19
+ *
17
20
  */
18
- export declare function parse(qr: string): DataModel;
21
+ export declare function decode(qr: string): DataModel;
19
22
  /**
20
23
  * Detect if qr string contains bysquare header.
21
24
  *
@@ -155,12 +155,15 @@ export class DecodeError extends Error {
155
155
  this.name = "DecodeError";
156
156
  }
157
157
  }
158
+ /** @deprecated */
159
+ export const parse = decode;
158
160
  /**
159
161
  * Decoding client data from QR Code 2005 symbol
160
162
  *
161
163
  * @see 3.16.
164
+ *
162
165
  */
163
- export function parse(qr) {
166
+ export function decode(qr) {
164
167
  try {
165
168
  var bytes = base32hex.parse(qr, {
166
169
  loose: true
@@ -49,8 +49,10 @@ type Options = {
49
49
  */
50
50
  deburr: boolean;
51
51
  };
52
+ /** @deprecated */
53
+ export declare const generate: typeof encode;
52
54
  /**
53
55
  * Generate QR string ready for encoding into text QR code
54
56
  */
55
- export declare function generate(model: DataModel, options?: Options): string;
57
+ export declare function encode(model: DataModel, options?: Options): string;
56
58
  export {};
@@ -137,10 +137,12 @@ function removeDiacritics(model) {
137
137
  }
138
138
  }
139
139
  }
140
+ /** @deprecated */
141
+ export const generate = encode;
140
142
  /**
141
143
  * Generate QR string ready for encoding into text QR code
142
144
  */
143
- export function generate(model, options = { deburr: true }) {
145
+ export function encode(model, options = { deburr: true }) {
144
146
  if (options.deburr) {
145
147
  removeDiacritics(model);
146
148
  }
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { generate } from "./generate.js";
2
- export { detect, parse } from "./parse.js";
1
+ export { generate } from "./encode.js";
2
+ export { detect, parse } from "./decode.js";
3
3
  export * from "./types.js";
package/dist/index.js CHANGED
@@ -1,3 +1,3 @@
1
- export { generate } from "./generate.js";
2
- export { detect, parse } from "./parse.js";
1
+ export { generate } from "./encode.js";
2
+ export { detect, parse } from "./decode.js";
3
3
  export * from "./types.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "bysquare",
3
3
  "description": "It's a national standard for payment QR codes adopted by Slovak Banking Association (SBA)",
4
- "version": "2.6.0",
4
+ "version": "2.7.0",
5
5
  "license": "Apache-2.0",
6
6
  "funding": "https://github.com/sponsors/xseman",
7
7
  "homepage": "https://github.com/xseman/bysquare#readme",
@@ -35,14 +35,13 @@
35
35
  "devDependencies": {
36
36
  "@types/lodash.deburr": "~4.1.0",
37
37
  "@types/node": ">=16.14",
38
- "dprint": "~0.36.0",
38
+ "dprint": "~0.41.0",
39
39
  "tsx": "~3.12.0",
40
40
  "typescript": "~5.0.0"
41
41
  },
42
42
  "type": "module",
43
43
  "bin": "./dist/cli.js",
44
44
  "types": "./dist/index.d.ts",
45
- "main": "./dist/index.js",
46
45
  "module": "./dist/index.js",
47
46
  "exports": {
48
47
  ".": {
@@ -54,7 +53,7 @@
54
53
  "!dist/*.test.*"
55
54
  ],
56
55
  "engines": {
57
- "node": ">=14.13.1 || >=16.0.0",
58
- "npm": ">=7.0"
56
+ "node": ">=16",
57
+ "npm": ">=7"
59
58
  }
60
59
  }