bysquare 2.7.0 → 2.8.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 +6 -6
- package/dist/cli.js +40 -19
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,14 +33,14 @@ npm install bysquare
|
|
|
33
33
|
|
|
34
34
|
```html
|
|
35
35
|
<script type="module">
|
|
36
|
-
import { encode, decode } from "https://esm.sh/bysquare@2.
|
|
36
|
+
import { encode, decode } from "https://esm.sh/bysquare@2.7.1/";
|
|
37
37
|
</script>
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
-
**Deno** `v1.28
|
|
40
|
+
**Deno** `v1.28+` using npm prefix
|
|
41
41
|
|
|
42
42
|
```ts
|
|
43
|
-
import { encode, decode } from "npm:bysquare@2.1
|
|
43
|
+
import { encode, decode } from "npm:bysquare@2.7.1";
|
|
44
44
|
```
|
|
45
45
|
|
|
46
46
|
**CLI** (Node.JS `v18`+)
|
|
@@ -119,11 +119,11 @@ const model = decode(
|
|
|
119
119
|
|
|
120
120
|
## Encode
|
|
121
121
|
|
|
122
|
-
Encode JSON data from
|
|
123
|
-
argument should be a path to a JSON file.
|
|
122
|
+
Encode JSON or JSONL data from files and print the corresponding QR code.
|
|
124
123
|
|
|
125
124
|
```sh
|
|
126
|
-
npx bysquare --encode
|
|
125
|
+
npx bysquare --encode file1.json file2.json...
|
|
126
|
+
npx bysquare --encode file.jsonl
|
|
127
127
|
```
|
|
128
128
|
|
|
129
129
|
## Decode
|
package/dist/cli.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync, readFileSync } from "node:fs";
|
|
3
3
|
import { parseArgs } from "node:util";
|
|
4
|
+
import process from "node:process";
|
|
4
5
|
import { encode } from "./encode.js";
|
|
5
6
|
import { decode } from "./decode.js";
|
|
6
7
|
const args = parseArgs({
|
|
@@ -11,7 +12,7 @@ const args = parseArgs({
|
|
|
11
12
|
short: "d"
|
|
12
13
|
},
|
|
13
14
|
encode: {
|
|
14
|
-
type: "
|
|
15
|
+
type: "boolean",
|
|
15
16
|
short: "e"
|
|
16
17
|
},
|
|
17
18
|
help: {
|
|
@@ -21,30 +22,50 @@ const args = parseArgs({
|
|
|
21
22
|
}
|
|
22
23
|
});
|
|
23
24
|
if (process.stdin.isTTY) {
|
|
24
|
-
/** json file */
|
|
25
25
|
if (args.values.encode) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const data = readFileSync(file, "utf8");
|
|
29
|
-
console.log(encode(JSON.parse(data)));
|
|
30
|
-
}
|
|
31
|
-
else {
|
|
32
|
-
console.error(`File ${file} doesn't exists`);
|
|
26
|
+
if (args.positionals.length === 0) {
|
|
27
|
+
console.error("No files provided for encoding.");
|
|
33
28
|
process.exit(1);
|
|
34
29
|
}
|
|
30
|
+
for (const file of args.positionals) {
|
|
31
|
+
if (existsSync(file) === false) {
|
|
32
|
+
console.error(`File ${file} doesn't exist`);
|
|
33
|
+
process.exit(1);
|
|
34
|
+
}
|
|
35
|
+
if (file.endsWith(".json") === false &&
|
|
36
|
+
file.endsWith(".jsonl") === false) {
|
|
37
|
+
console.error(`Unsupported file format for ${file}`);
|
|
38
|
+
process.exit(1);
|
|
39
|
+
}
|
|
40
|
+
const data = readFileSync(file, "utf8");
|
|
41
|
+
if (file.endsWith(".jsonl")) {
|
|
42
|
+
const lines = data.split('\n');
|
|
43
|
+
for (const line of lines) {
|
|
44
|
+
if (!line)
|
|
45
|
+
continue;
|
|
46
|
+
const json = JSON.parse(line);
|
|
47
|
+
console.log(encode(json));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (file.endsWith(".json")) {
|
|
51
|
+
console.log(encode(JSON.parse(data)));
|
|
52
|
+
}
|
|
53
|
+
process.exit(0);
|
|
54
|
+
}
|
|
35
55
|
}
|
|
36
|
-
/** input string */
|
|
37
56
|
if (args.values.decode) {
|
|
38
57
|
const qrstring = args.values.decode;
|
|
39
58
|
console.log(JSON.stringify(decode(qrstring), null, 4));
|
|
59
|
+
process.exit(0);
|
|
40
60
|
}
|
|
41
|
-
if (args.values.help ||
|
|
61
|
+
if (args.values.help ||
|
|
62
|
+
Object.keys(args.values).length === 0) {
|
|
42
63
|
console.log([
|
|
43
64
|
"NAME",
|
|
44
65
|
" bysquare - Simple Node.js library to generate and parse PAY bysquare standard",
|
|
45
66
|
"",
|
|
46
67
|
"SYNOPSIS",
|
|
47
|
-
" bysquare [OPTIONS]",
|
|
68
|
+
" bysquare [OPTIONS] [FILES...]",
|
|
48
69
|
"",
|
|
49
70
|
"DESCRIPTION",
|
|
50
71
|
" bysquare is a command-line tool that provides a simple Node.js library to generate ",
|
|
@@ -56,19 +77,19 @@ if (process.stdin.isTTY) {
|
|
|
56
77
|
" Decode the specified QR code string and print the corresponding JSON data.",
|
|
57
78
|
" The qrstring argument should be a valid QR code string.",
|
|
58
79
|
"",
|
|
59
|
-
" -e, --encode
|
|
60
|
-
" Encode JSON data from
|
|
61
|
-
" The file argument should be a path to a JSON file.",
|
|
80
|
+
" -e, --encode",
|
|
81
|
+
" Encode JSON data from one or more files and print the corresponding QR code.",
|
|
62
82
|
"",
|
|
63
83
|
" -h, --help",
|
|
64
84
|
" Display the help message and exit.",
|
|
65
85
|
"",
|
|
66
86
|
"USAGE",
|
|
67
|
-
" Encoding JSON data from
|
|
87
|
+
" Encoding JSON data from one or more files",
|
|
68
88
|
"",
|
|
69
|
-
` ${process.argv[1]} --encode
|
|
70
|
-
" The
|
|
71
|
-
"
|
|
89
|
+
` ${process.argv[1]} --encode file1.json file2.json ...`,
|
|
90
|
+
" The file1.json, file2.json, ... arguments should be the paths to the JSON or JSONL",
|
|
91
|
+
" files you want to encode. The tool will read each file, generate a QR code representing",
|
|
92
|
+
" the JSON data, and print them.",
|
|
72
93
|
"",
|
|
73
94
|
" Decoding a QR code string",
|
|
74
95
|
"",
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { generate } from "./encode.js";
|
|
2
|
-
export { detect, parse } from "./decode.js";
|
|
1
|
+
export { encode, generate } from "./encode.js";
|
|
2
|
+
export { decode, detect, parse } from "./decode.js";
|
|
3
3
|
export * from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { generate } from "./encode.js";
|
|
2
|
-
export { detect, parse } from "./decode.js";
|
|
1
|
+
export { encode, generate } from "./encode.js";
|
|
2
|
+
export { decode, 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.
|
|
4
|
+
"version": "2.8.0",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"funding": "https://github.com/sponsors/xseman",
|
|
7
7
|
"homepage": "https://github.com/xseman/bysquare#readme",
|