bysquare 1.3.3 → 2.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/README.md +67 -53
- package/lib/cli.js +17 -22
- package/lib/generate.d.ts +14 -13
- package/lib/generate.js +107 -114
- package/lib/index.d.ts +3 -3
- package/lib/index.js +3 -24
- package/lib/parse.d.ts +6 -11
- package/lib/parse.js +116 -164
- package/lib/types.d.ts +117 -225
- package/lib/types.js +221 -259
- package/package.json +36 -35
package/README.md
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
# bysquare
|
|
2
2
|
|
|
3
|
-
![
|
|
4
|
-
|
|
5
|
-
<!-- Dependency free simple -->
|
|
3
|
+
![version][version] ![build][build]
|
|
6
4
|
|
|
7
5
|
Simple `Node.js` library to generate "PAY by square" `QR` string.
|
|
8
6
|
|
|
@@ -19,21 +17,24 @@ your implementation. See [examples](examples).
|
|
|
19
17
|
|
|
20
18
|
## How it works
|
|
21
19
|
|
|
22
|
-

|
|
27
21
|
|
|
28
22
|
## Install
|
|
29
23
|
|
|
30
|
-
|
|
24
|
+
GitHub
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
npm install xseman/bysquare#master
|
|
28
|
+
npm install xseman/bysquare#develop
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
npm registry
|
|
31
32
|
|
|
32
33
|
```sh
|
|
33
34
|
npm install bysquare
|
|
34
35
|
```
|
|
35
36
|
|
|
36
|
-
CLI
|
|
37
|
+
CLI
|
|
37
38
|
|
|
38
39
|
```sh
|
|
39
40
|
npm install --global bysquare
|
|
@@ -42,24 +43,29 @@ npm install --global bysquare
|
|
|
42
43
|
## API
|
|
43
44
|
|
|
44
45
|
```ts
|
|
45
|
-
generate(model:
|
|
46
|
-
parse(qr: string): Promise<
|
|
46
|
+
generate(model: DataModel): Promise<string>
|
|
47
|
+
parse(qr: string): Promise<DataModel>
|
|
47
48
|
detect(qr: string): Boolean
|
|
48
49
|
```
|
|
49
50
|
|
|
50
|
-
**generate(model:
|
|
51
|
+
**generate(model: DataModel): Promise\<string>**
|
|
51
52
|
|
|
52
53
|
```ts
|
|
53
|
-
import { generate,
|
|
54
|
-
|
|
55
|
-
const model:
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
54
|
+
import { generate, DataModel, parse, PaymentOptions } from "bysquare"
|
|
55
|
+
|
|
56
|
+
const model: DataModel = {
|
|
57
|
+
invoiceId: "random-id",
|
|
58
|
+
payments: [
|
|
59
|
+
{
|
|
60
|
+
type: PaymentOptions.PaymentOrder,
|
|
61
|
+
amount: 100.0,
|
|
62
|
+
bankAccounts: [
|
|
63
|
+
{ iban: "SK9611000000002918599669" },
|
|
64
|
+
],
|
|
65
|
+
currencyCode: "EUR",
|
|
66
|
+
variableSymbol: "123",
|
|
67
|
+
}
|
|
68
|
+
]
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
generate(model).then((qr: string) => {
|
|
@@ -67,15 +73,15 @@ generate(model).then((qr: string) => {
|
|
|
67
73
|
})
|
|
68
74
|
```
|
|
69
75
|
|
|
70
|
-
**parse(qr: string): Promise\<
|
|
76
|
+
**parse(qr: string): Promise\<DataModel>**
|
|
71
77
|
|
|
72
78
|
```ts
|
|
73
|
-
import {
|
|
79
|
+
import { parse, DataModel } from "bysquare"
|
|
74
80
|
|
|
75
81
|
const qr = "0004A00090IFU27IV0J6HGGLIOTIBVHNQQJQ6LAVGNBT363HR13JC6C75G19O246KTT5G8LTLM67HOIATP4OOG8F8FDLJ6T26KFCB1690NEVPQVSG0"
|
|
76
|
-
parse(qr).then((model:
|
|
82
|
+
parse(qr).then((model: DataModel) => {
|
|
77
83
|
// your logic...
|
|
78
|
-
})
|
|
84
|
+
});
|
|
79
85
|
```
|
|
80
86
|
|
|
81
87
|
**detect(qr: string): Boolean**
|
|
@@ -85,8 +91,6 @@ import { detect } from "bysquare"
|
|
|
85
91
|
|
|
86
92
|
const qr = "0004A00090IFU27IV0J6HGGLIOTIBVHNQQJQ6LAVGNBT363HR13JC6C75G19O246KTT5G8LTLM67HOIATP4OOG8F8FDLJ6T26KFCB1690NEVPQVSG0"
|
|
87
93
|
const isBysquare = detect(qr)
|
|
88
|
-
|
|
89
|
-
// your logic...
|
|
90
94
|
```
|
|
91
95
|
|
|
92
96
|
## CLI
|
|
@@ -96,14 +100,18 @@ You can use json file with valid model to generate qr-string.
|
|
|
96
100
|
```sh
|
|
97
101
|
# example.json
|
|
98
102
|
# {
|
|
99
|
-
#
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
-
#
|
|
103
|
-
#
|
|
104
|
-
#
|
|
105
|
-
#
|
|
106
|
-
#
|
|
103
|
+
# "invoiceId": "random-id",
|
|
104
|
+
# "payments": [
|
|
105
|
+
# {
|
|
106
|
+
# "type": 1,
|
|
107
|
+
# "amount": 100.0,
|
|
108
|
+
# "bankAccounts": [
|
|
109
|
+
# { "iban": "SK9611000000002918599669" }
|
|
110
|
+
# ],
|
|
111
|
+
# "currencyCode": "EUR",
|
|
112
|
+
# "variableSymbol": "123"
|
|
113
|
+
# }
|
|
114
|
+
# ]
|
|
107
115
|
# }
|
|
108
116
|
|
|
109
117
|
$ npx bysquare ./example.json
|
|
@@ -114,14 +122,18 @@ You can also use stdin.
|
|
|
114
122
|
|
|
115
123
|
```sh
|
|
116
124
|
$ bysquare <<< '{
|
|
117
|
-
"
|
|
118
|
-
"
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
+
"invoiceId": "random-id",
|
|
126
|
+
"payments": [
|
|
127
|
+
{
|
|
128
|
+
"type": 1,
|
|
129
|
+
"amount": 100.0,
|
|
130
|
+
"bankAccounts": [
|
|
131
|
+
{ "iban": "SK9611000000002918599669" }
|
|
132
|
+
],
|
|
133
|
+
"currencyCode": "EUR",
|
|
134
|
+
"variableSymbol": "123"
|
|
135
|
+
}
|
|
136
|
+
]
|
|
125
137
|
}'
|
|
126
138
|
$ 0004A00090IFU27IV0J6HGGLIOTIBVHNQQJQ6LAVGNBT363HR13JC6C75G19O246KTT5G8LTLM67HOIATP4OOG8F8FDLJ6T26KFCB1690NEVPQVSG0
|
|
127
139
|
```
|
|
@@ -142,14 +154,16 @@ Versioning
|
|
|
142
154
|
https://github.com/dherges/npm-version-git-flow
|
|
143
155
|
|
|
144
156
|
- Stash unfinished work
|
|
145
|
-
- Run
|
|
146
|
-
- Run
|
|
147
|
-
-
|
|
148
|
-
- Run
|
|
149
|
-
-
|
|
150
|
-
- Run the `postversion` script
|
|
157
|
+
- Run `npm test`
|
|
158
|
+
- Run `npm version <patch, minor, major>`
|
|
159
|
+
- Commit and push
|
|
160
|
+
- Run `npm version`
|
|
161
|
+
- Follow git-flow instructions
|
|
151
162
|
- Checkout to master
|
|
152
163
|
- Push commits and tag, git push && git push --tags
|
|
153
|
-
- npm publish --dry-run
|
|
154
|
-
- Publish to npm, npm publish
|
|
164
|
+
- Validate with `npm publish --dry-run`
|
|
165
|
+
- Publish to npm, `npm publish`
|
|
155
166
|
-->
|
|
167
|
+
|
|
168
|
+
[build]: https://img.shields.io/github/actions/workflow/status/xseman/bysquare/tests.yml
|
|
169
|
+
[version]: https://img.shields.io/npm/v/bysquare
|
package/lib/cli.js
CHANGED
|
@@ -1,27 +1,22 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const path_1 = __importDefault(require("path"));
|
|
9
|
-
const readline_1 = require("readline");
|
|
10
|
-
const generate_1 = require("./generate");
|
|
2
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { createInterface } from "node:readline";
|
|
5
|
+
import { generate } from "./generate.js";
|
|
11
6
|
if (process.stdin.isTTY) {
|
|
12
|
-
|
|
7
|
+
// bysquare "file"
|
|
13
8
|
handleInput(process.argv[2]);
|
|
14
9
|
}
|
|
15
10
|
else {
|
|
16
|
-
|
|
11
|
+
// echo "data" | bysquare
|
|
17
12
|
;
|
|
18
13
|
(async () => {
|
|
19
14
|
const stdin = await handleStdin();
|
|
20
|
-
const
|
|
15
|
+
const qr = await fromJsonString(stdin).catch((e) => {
|
|
21
16
|
console.error(e);
|
|
22
17
|
process.exit(1);
|
|
23
18
|
});
|
|
24
|
-
console.log(
|
|
19
|
+
console.log(qr);
|
|
25
20
|
process.exit(0);
|
|
26
21
|
})();
|
|
27
22
|
}
|
|
@@ -30,24 +25,24 @@ async function handleInput(input) {
|
|
|
30
25
|
console.log(help());
|
|
31
26
|
process.exit(0);
|
|
32
27
|
}
|
|
33
|
-
if (
|
|
34
|
-
const file =
|
|
35
|
-
const
|
|
28
|
+
if (existsSync(process.argv[2])) {
|
|
29
|
+
const file = readFileSync(process.argv[2], "utf8");
|
|
30
|
+
const qr = await fromJsonString(file).catch((e) => {
|
|
36
31
|
console.error(e);
|
|
37
32
|
process.exit(1);
|
|
38
33
|
});
|
|
39
|
-
console.log(
|
|
34
|
+
console.log(qr);
|
|
40
35
|
}
|
|
41
36
|
else {
|
|
42
37
|
console.error(`File ${process.argv[2]} doesn't exists`);
|
|
43
38
|
process.exit(1);
|
|
44
39
|
}
|
|
45
40
|
}
|
|
46
|
-
async function
|
|
41
|
+
async function fromJsonString(stdin) {
|
|
47
42
|
return new Promise((resolve, reject) => {
|
|
48
43
|
try {
|
|
49
44
|
const data = JSON.parse(stdin);
|
|
50
|
-
const qrString =
|
|
45
|
+
const qrString = generate(data);
|
|
51
46
|
resolve(qrString);
|
|
52
47
|
}
|
|
53
48
|
catch (e) {
|
|
@@ -56,7 +51,7 @@ async function jsonStringToQrString(stdin) {
|
|
|
56
51
|
});
|
|
57
52
|
}
|
|
58
53
|
async function handleStdin() {
|
|
59
|
-
const readline =
|
|
54
|
+
const readline = createInterface({
|
|
60
55
|
input: process.stdin,
|
|
61
56
|
output: process.stdout,
|
|
62
57
|
terminal: false
|
|
@@ -70,11 +65,11 @@ async function handleStdin() {
|
|
|
70
65
|
.on("close", () => {
|
|
71
66
|
resolve(lines.join(""));
|
|
72
67
|
})
|
|
73
|
-
.on("SIGINT" /* CTRL+C
|
|
68
|
+
.on("SIGINT", /* CTRL+C */ reject);
|
|
74
69
|
});
|
|
75
70
|
}
|
|
76
71
|
function help() {
|
|
77
|
-
const exe =
|
|
72
|
+
const exe = path.basename(process.argv[1]);
|
|
78
73
|
return [
|
|
79
74
|
"Simple Node.js library to generate 'PAY by square' QR string.",
|
|
80
75
|
"",
|
package/lib/generate.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="node" />
|
|
2
|
-
import {
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
import { DataModel } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Returns a 2 byte buffer that represents the header of the bysquare
|
|
5
5
|
* specification
|
|
@@ -15,7 +15,7 @@ import { Model } from "./index";
|
|
|
15
15
|
*
|
|
16
16
|
* @see 3.5. by square header
|
|
17
17
|
*/
|
|
18
|
-
export declare function
|
|
18
|
+
export declare function bysquareHeader(header?: [
|
|
19
19
|
bySquareType: number,
|
|
20
20
|
version: number,
|
|
21
21
|
documentType: number,
|
|
@@ -24,24 +24,25 @@ export declare function makeHeaderBysquare(header?: [
|
|
|
24
24
|
/**
|
|
25
25
|
* @see 3.10 Appending CRC32 checksum
|
|
26
26
|
*/
|
|
27
|
-
export declare function
|
|
27
|
+
export declare function checksum(intermediate: string): Buffer;
|
|
28
28
|
/**
|
|
29
29
|
* Transfer object to a tabbed string and append a CRC32 checksum
|
|
30
30
|
*
|
|
31
31
|
* @see 3.10. Appending CRC32 checksum
|
|
32
32
|
*/
|
|
33
|
-
export declare function
|
|
33
|
+
export declare function prepareCompression(model: DataModel): Buffer;
|
|
34
34
|
/**
|
|
35
|
-
*
|
|
35
|
+
* Transform data to ordered tab-separated intermediate representation ready for
|
|
36
|
+
* encoding
|
|
36
37
|
*
|
|
37
38
|
* @see Table 15 PAY by square sequence data model
|
|
38
39
|
*/
|
|
39
|
-
export declare function
|
|
40
|
+
export declare function toIntermediate(data: DataModel): string;
|
|
41
|
+
type Options = {
|
|
42
|
+
deburr: boolean;
|
|
43
|
+
};
|
|
40
44
|
/**
|
|
41
|
-
*
|
|
45
|
+
* Generate QR string ready for encoding into text QR code
|
|
42
46
|
*/
|
|
43
|
-
export declare function
|
|
44
|
-
|
|
45
|
-
* Generate QR string ready for encoding into basic QR code
|
|
46
|
-
*/
|
|
47
|
-
export declare function generate(model: Model): Promise<string>;
|
|
47
|
+
export declare function generate(model: DataModel, options?: Options): Promise<string>;
|
|
48
|
+
export {};
|
package/lib/generate.js
CHANGED
|
@@ -1,35 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.generate = exports.alphanumericConversion = exports.makeTabbed = exports.prepareForCompression = exports.makeChecksum = exports.makeHeaderBysquare = void 0;
|
|
30
|
-
const lodash_deburr_1 = __importDefault(require("lodash.deburr"));
|
|
31
|
-
const lzma = __importStar(require("lzma-native"));
|
|
32
|
-
const index_1 = require("./index");
|
|
1
|
+
import deburr from "lodash.deburr";
|
|
2
|
+
import lzma from "lzma-native";
|
|
3
|
+
import { base32hex } from "rfc4648";
|
|
4
|
+
import { PaymentOptions } from "./types.js";
|
|
33
5
|
// echo "Hello" | xz --format=raw --lzma1=lc=3,lp=0,pb=2,dict=32KiB --stdout | hexdump -C
|
|
34
6
|
/**
|
|
35
7
|
* Returns a 2 byte buffer that represents the header of the bysquare
|
|
@@ -46,23 +18,22 @@ const index_1 = require("./index");
|
|
|
46
18
|
*
|
|
47
19
|
* @see 3.5. by square header
|
|
48
20
|
*/
|
|
49
|
-
function
|
|
50
|
-
|
|
51
|
-
|
|
21
|
+
export function bysquareHeader(header = [
|
|
22
|
+
0, 0,
|
|
23
|
+
0, 0
|
|
52
24
|
]) {
|
|
53
25
|
const isValid = header.every((nibble) => 0 <= nibble && nibble <= 15);
|
|
54
26
|
if (!isValid) {
|
|
55
|
-
throw new Error(
|
|
27
|
+
throw new Error(`Invalid header byte value, valid range <0,15>`);
|
|
56
28
|
}
|
|
57
29
|
const [bySquareType, version, documentType, reserved] = header;
|
|
58
|
-
|
|
59
|
-
const
|
|
30
|
+
// Combine 4-nibbles to 2-bytes
|
|
31
|
+
const mergedNibbles = Buffer.from([
|
|
60
32
|
(bySquareType << 4) | (version << 0),
|
|
61
|
-
(documentType << 4) | (reserved << 0)
|
|
33
|
+
(documentType << 4) | (reserved << 0),
|
|
62
34
|
]);
|
|
63
|
-
return
|
|
35
|
+
return mergedNibbles;
|
|
64
36
|
}
|
|
65
|
-
exports.makeHeaderBysquare = makeHeaderBysquare;
|
|
66
37
|
/**
|
|
67
38
|
* Allocates a new buffer of a 2 bytes that represents LZMA header which
|
|
68
39
|
* contains 16-bit unsigned integer (word, little-endian), which is the size of
|
|
@@ -71,7 +42,7 @@ exports.makeHeaderBysquare = makeHeaderBysquare;
|
|
|
71
42
|
*
|
|
72
43
|
* @see 3.11. LZMA Compression
|
|
73
44
|
*/
|
|
74
|
-
function
|
|
45
|
+
function lzmaHeader(decompressedData) {
|
|
75
46
|
const bytesCount = decompressedData.length;
|
|
76
47
|
if (bytesCount >= 2 ** 16) {
|
|
77
48
|
throw new Error("The maximum compressed data size has been reached");
|
|
@@ -83,121 +54,143 @@ function makeHeaderLzma(decompressedData) {
|
|
|
83
54
|
/**
|
|
84
55
|
* @see 3.10 Appending CRC32 checksum
|
|
85
56
|
*/
|
|
86
|
-
function
|
|
57
|
+
export function checksum(intermediate) {
|
|
87
58
|
// @ts-ignore: Wrong return type
|
|
88
|
-
const data = lzma.crc32(
|
|
59
|
+
const data = lzma.crc32(intermediate);
|
|
89
60
|
const crc32 = Buffer.alloc(4);
|
|
90
61
|
crc32.writeUInt32LE(data);
|
|
91
62
|
return crc32;
|
|
92
63
|
}
|
|
93
|
-
exports.makeChecksum = makeChecksum;
|
|
94
64
|
/**
|
|
95
65
|
* Transfer object to a tabbed string and append a CRC32 checksum
|
|
96
66
|
*
|
|
97
67
|
* @see 3.10. Appending CRC32 checksum
|
|
98
68
|
*/
|
|
99
|
-
function
|
|
100
|
-
const
|
|
69
|
+
export function prepareCompression(model) {
|
|
70
|
+
const intermediate = toIntermediate(model);
|
|
101
71
|
return Buffer.concat([
|
|
102
|
-
|
|
103
|
-
Buffer.from(
|
|
72
|
+
checksum(intermediate),
|
|
73
|
+
Buffer.from(intermediate, "utf-8")
|
|
104
74
|
]);
|
|
105
75
|
}
|
|
106
|
-
exports.prepareForCompression = prepareForCompression;
|
|
107
76
|
/**
|
|
108
|
-
*
|
|
77
|
+
* Transform data to ordered tab-separated intermediate representation ready for
|
|
78
|
+
* encoding
|
|
109
79
|
*
|
|
110
80
|
* @see Table 15 PAY by square sequence data model
|
|
111
81
|
*/
|
|
112
|
-
function
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
82
|
+
export function toIntermediate(data) {
|
|
83
|
+
const intermediate = new Array();
|
|
84
|
+
intermediate.push(data.invoiceId?.toString());
|
|
85
|
+
intermediate.push(data.payments.length.toString());
|
|
86
|
+
for (const p of data.payments) {
|
|
87
|
+
intermediate.push(p.type.toString());
|
|
88
|
+
intermediate.push(p.amount?.toString());
|
|
89
|
+
intermediate.push(p.currencyCode);
|
|
90
|
+
intermediate.push(p.paymentDueDate);
|
|
91
|
+
intermediate.push(p.variableSymbol);
|
|
92
|
+
intermediate.push(p.constantSymbol);
|
|
93
|
+
intermediate.push(p.specificSymbol);
|
|
94
|
+
intermediate.push(p.originatorRefInfo);
|
|
95
|
+
intermediate.push(p.paymentNote);
|
|
96
|
+
intermediate.push(p.bankAccounts.length.toString());
|
|
97
|
+
for (const ba of p.bankAccounts) {
|
|
98
|
+
intermediate.push(ba.iban);
|
|
99
|
+
intermediate.push(ba.bic);
|
|
100
|
+
}
|
|
101
|
+
if (p.type === PaymentOptions.StandingOrder) {
|
|
102
|
+
intermediate.push('1');
|
|
103
|
+
intermediate.push(p.day?.toString());
|
|
104
|
+
intermediate.push(p.month?.toString());
|
|
105
|
+
intermediate.push(p.periodicity);
|
|
106
|
+
intermediate.push(p.lastDate);
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
intermediate.push('0');
|
|
119
110
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
111
|
+
if (p.type === PaymentOptions.DirectDebit) {
|
|
112
|
+
intermediate.push('1');
|
|
113
|
+
intermediate.push(p.directDebitScheme?.toString());
|
|
114
|
+
intermediate.push(p.directDebitType?.toString());
|
|
115
|
+
intermediate.push(p.variableSymbol?.toString());
|
|
116
|
+
intermediate.push(p.specificSymbol?.toString());
|
|
117
|
+
intermediate.push(p.originatorRefInfo?.toString());
|
|
118
|
+
intermediate.push(p.mandateId?.toString());
|
|
119
|
+
intermediate.push(p.creditorId?.toString());
|
|
120
|
+
intermediate.push(p.contractId?.toString());
|
|
121
|
+
intermediate.push(p.maxAmount?.toString());
|
|
122
|
+
intermediate.push(p.validTillDate?.toString());
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
intermediate.push('0');
|
|
132
126
|
}
|
|
133
|
-
return tabbed.join("\t");
|
|
134
127
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
128
|
+
for (const p of data.payments) {
|
|
129
|
+
intermediate.push(p.beneficiary?.name);
|
|
130
|
+
intermediate.push(p.beneficiary?.street);
|
|
131
|
+
intermediate.push(p.beneficiary?.city);
|
|
139
132
|
}
|
|
140
|
-
return
|
|
133
|
+
return intermediate.join('\t');
|
|
141
134
|
}
|
|
142
|
-
exports.makeTabbed = makeTabbed;
|
|
143
135
|
/**
|
|
144
|
-
*
|
|
136
|
+
* Transfer diacritics to basic latin letters
|
|
145
137
|
*/
|
|
146
|
-
function
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
let encoded = "";
|
|
161
|
-
for (let i = 0; i < paddedLength / 5; i++) {
|
|
162
|
-
const binStart = 5 * i;
|
|
163
|
-
const binEnd = 5 * i + 5;
|
|
164
|
-
const sliced = paddedBinString.slice(binStart, binEnd);
|
|
165
|
-
const key = parseInt(sliced, 2);
|
|
166
|
-
encoded += index_1.SUBST[key];
|
|
138
|
+
function removeDiacritics(model) {
|
|
139
|
+
for (const payment of model.payments) {
|
|
140
|
+
if (payment.paymentNote) {
|
|
141
|
+
payment.paymentNote = deburr(payment.paymentNote);
|
|
142
|
+
}
|
|
143
|
+
if (payment.beneficiary?.name) {
|
|
144
|
+
payment.beneficiary.name = deburr(payment.beneficiary.name);
|
|
145
|
+
}
|
|
146
|
+
if (payment.beneficiary?.city) {
|
|
147
|
+
payment.beneficiary.city = deburr(payment.beneficiary.city);
|
|
148
|
+
}
|
|
149
|
+
if (payment.beneficiary?.street) {
|
|
150
|
+
payment.beneficiary.street = deburr(payment.beneficiary.street);
|
|
151
|
+
}
|
|
167
152
|
}
|
|
168
|
-
return encoded;
|
|
169
153
|
}
|
|
170
|
-
exports.alphanumericConversion = alphanumericConversion;
|
|
171
154
|
/**
|
|
172
|
-
* Generate QR string ready for encoding into
|
|
155
|
+
* Generate QR string ready for encoding into text QR code
|
|
173
156
|
*/
|
|
174
|
-
function generate(model) {
|
|
175
|
-
|
|
157
|
+
export function generate(model, options = { deburr: true }) {
|
|
158
|
+
if (options.deburr) {
|
|
159
|
+
removeDiacritics(model);
|
|
160
|
+
}
|
|
161
|
+
const data = prepareCompression(model);
|
|
176
162
|
const compressedData = [];
|
|
177
163
|
return new Promise((resolve, reject) => {
|
|
178
164
|
const encoder = lzma.createStream("rawEncoder", {
|
|
179
165
|
synchronous: true,
|
|
180
166
|
// @ts-ignore: Missing filter types
|
|
181
|
-
filters: [
|
|
167
|
+
filters: [
|
|
168
|
+
{
|
|
169
|
+
// @ts-ignore: Missing filter types
|
|
170
|
+
id: lzma.FILTER_LZMA1,
|
|
171
|
+
lc: 3,
|
|
172
|
+
lp: 0,
|
|
173
|
+
pb: 2,
|
|
174
|
+
dict_size: 2 ** 17, // 128 kilobytes
|
|
175
|
+
},
|
|
176
|
+
],
|
|
182
177
|
});
|
|
183
178
|
encoder
|
|
184
|
-
.on("data", (chunk) => {
|
|
185
|
-
compressedData.push(chunk);
|
|
186
|
-
})
|
|
187
|
-
.on("error", reject)
|
|
188
179
|
.on("end", () => {
|
|
189
180
|
const output = Buffer.concat([
|
|
190
|
-
|
|
191
|
-
|
|
181
|
+
bysquareHeader(),
|
|
182
|
+
lzmaHeader(data),
|
|
192
183
|
...compressedData
|
|
193
184
|
]);
|
|
194
|
-
|
|
195
|
-
resolve(qr);
|
|
185
|
+
resolve(base32hex.stringify(output, { pad: false }));
|
|
196
186
|
})
|
|
187
|
+
.on("data", (chunk) => {
|
|
188
|
+
compressedData.push(chunk);
|
|
189
|
+
})
|
|
190
|
+
.on("error", reject)
|
|
197
191
|
.write(data, (error) => {
|
|
198
192
|
error && reject(error);
|
|
199
193
|
encoder.end();
|
|
200
194
|
});
|
|
201
195
|
});
|
|
202
196
|
}
|
|
203
|
-
exports.generate = generate;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export * from "./types";
|
|
1
|
+
export { generate } from "./generate.js";
|
|
2
|
+
export { detect, parse } from "./parse.js";
|
|
3
|
+
export * from "./types.js";
|
package/lib/index.js
CHANGED
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.generate = exports.detect = exports.parse = void 0;
|
|
18
|
-
// Library exposed functions and types
|
|
19
|
-
var parse_1 = require("./parse");
|
|
20
|
-
Object.defineProperty(exports, "parse", { enumerable: true, get: function () { return parse_1.parse; } });
|
|
21
|
-
Object.defineProperty(exports, "detect", { enumerable: true, get: function () { return parse_1.detect; } });
|
|
22
|
-
var generate_1 = require("./generate");
|
|
23
|
-
Object.defineProperty(exports, "generate", { enumerable: true, get: function () { return generate_1.generate; } });
|
|
24
|
-
__exportStar(require("./types"), exports);
|
|
1
|
+
export { generate } from "./generate.js";
|
|
2
|
+
export { detect, parse } from "./parse.js";
|
|
3
|
+
export * from "./types.js";
|