bysquare 2.0.0 → 2.1.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 +42 -44
- package/lib/{cli.d.ts → cjs/cli.d.ts} +0 -0
- package/lib/cjs/cli.js +90 -0
- package/lib/cjs/generate.d.ts +54 -0
- package/lib/cjs/generate.js +185 -0
- package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- package/lib/cjs/index.js +23 -0
- package/lib/cjs/package.json +71 -0
- package/lib/{parse.d.ts → cjs/parse.d.ts} +2 -2
- package/lib/cjs/parse.js +234 -0
- package/lib/{types.d.ts → cjs/types.d.ts} +0 -0
- package/lib/cjs/types.js +246 -0
- package/lib/mjs/cli.d.ts +2 -0
- package/lib/{cli.js → mjs/cli.js} +18 -35
- package/lib/{generate.d.ts → mjs/generate.d.ts} +10 -4
- package/lib/{generate.js → mjs/generate.js} +35 -57
- package/lib/{index.js → mjs/index.d.ts} +0 -0
- package/lib/mjs/index.js +3 -0
- package/lib/mjs/package.json +71 -0
- package/lib/mjs/parse.d.ts +16 -0
- package/lib/{parse.js → mjs/parse.js} +79 -28
- package/lib/mjs/types.d.ts +379 -0
- package/lib/{types.js → mjs/types.js} +0 -0
- package/package.json +15 -8
package/lib/cjs/parse.js
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.detect = exports.parse = exports.serialize = void 0;
|
|
7
|
+
const rfc4648_1 = require("rfc4648");
|
|
8
|
+
// @ts-ignore: missing types
|
|
9
|
+
const lzma_1 = __importDefault(require("lzma"));
|
|
10
|
+
const index_js_1 = require("./index.js");
|
|
11
|
+
function cleanEmptyProps(obj) {
|
|
12
|
+
Object.keys(obj).forEach((key) => {
|
|
13
|
+
if (typeof obj[key] === 'undefined') {
|
|
14
|
+
delete obj[key];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* @see 3.14. Generating by square Code
|
|
20
|
+
*/
|
|
21
|
+
function serialize(qr) {
|
|
22
|
+
const intermediate = qr
|
|
23
|
+
.split("\t")
|
|
24
|
+
/** The end of the qr-string might contain a NULL-terminated string */
|
|
25
|
+
.map((entry) => entry.replace("\x00", ""));
|
|
26
|
+
const invoiceId = intermediate.shift();
|
|
27
|
+
const output = {
|
|
28
|
+
invoiceId: invoiceId?.length ? invoiceId : undefined,
|
|
29
|
+
payments: []
|
|
30
|
+
};
|
|
31
|
+
const paymentslen = Number(intermediate.shift());
|
|
32
|
+
for (let i = 0; i < paymentslen; i++) {
|
|
33
|
+
const paymentOptions = intermediate.shift();
|
|
34
|
+
const ammount = intermediate.shift();
|
|
35
|
+
const currency = intermediate.shift();
|
|
36
|
+
const dueDate = intermediate.shift();
|
|
37
|
+
const variables = intermediate.shift();
|
|
38
|
+
const constants = intermediate.shift();
|
|
39
|
+
const specifics = intermediate.shift();
|
|
40
|
+
const originatorRefInfo = intermediate.shift();
|
|
41
|
+
const paymentNote = intermediate.shift();
|
|
42
|
+
let payment = {
|
|
43
|
+
type: Number(paymentOptions),
|
|
44
|
+
bankAccounts: [],
|
|
45
|
+
amount: ammount?.length ? Number(ammount) : undefined,
|
|
46
|
+
currencyCode: currency,
|
|
47
|
+
paymentDueDate: dueDate?.length ? dueDate : undefined,
|
|
48
|
+
variableSymbol: variables?.length ? variables : undefined,
|
|
49
|
+
constantSymbol: constants?.length ? constants : undefined,
|
|
50
|
+
specificSymbol: specifics?.length ? specifics : undefined,
|
|
51
|
+
originatorRefInfo: originatorRefInfo?.length ? originatorRefInfo : undefined,
|
|
52
|
+
paymentNote: paymentNote?.length ? paymentNote : undefined,
|
|
53
|
+
};
|
|
54
|
+
const accountslen = Number(intermediate.shift());
|
|
55
|
+
for (let j = 0; j < accountslen; j++) {
|
|
56
|
+
const iban = intermediate.shift();
|
|
57
|
+
if (iban === undefined || iban.length === 0) {
|
|
58
|
+
throw new Error("Missing IBAN");
|
|
59
|
+
}
|
|
60
|
+
const bic = intermediate.shift();
|
|
61
|
+
const account = {
|
|
62
|
+
iban: iban,
|
|
63
|
+
bic: bic?.length ? bic : undefined,
|
|
64
|
+
};
|
|
65
|
+
cleanEmptyProps(account);
|
|
66
|
+
payment.bankAccounts.push(account);
|
|
67
|
+
}
|
|
68
|
+
intermediate.shift(); // StandingOrderExt
|
|
69
|
+
intermediate.shift(); // DirectDebitExt
|
|
70
|
+
// narrowing payment type
|
|
71
|
+
switch (payment.type) {
|
|
72
|
+
case index_js_1.PaymentOptions.PaymentOrder:
|
|
73
|
+
break;
|
|
74
|
+
case index_js_1.PaymentOptions.StandingOrder:
|
|
75
|
+
payment = {
|
|
76
|
+
...payment,
|
|
77
|
+
day: Number(intermediate.shift()),
|
|
78
|
+
month: Number(intermediate.shift()),
|
|
79
|
+
periodicity: intermediate.shift(),
|
|
80
|
+
lastDate: intermediate.shift()
|
|
81
|
+
};
|
|
82
|
+
break;
|
|
83
|
+
case index_js_1.PaymentOptions.DirectDebit:
|
|
84
|
+
payment = {
|
|
85
|
+
...payment,
|
|
86
|
+
directDebitScheme: Number(intermediate.shift()),
|
|
87
|
+
directDebitType: Number(intermediate.shift()),
|
|
88
|
+
mandateId: intermediate.shift(),
|
|
89
|
+
creditorId: intermediate.shift(),
|
|
90
|
+
contractId: intermediate.shift(),
|
|
91
|
+
maxAmount: Number(intermediate.shift()),
|
|
92
|
+
validTillDate: intermediate.shift()
|
|
93
|
+
};
|
|
94
|
+
break;
|
|
95
|
+
default:
|
|
96
|
+
break;
|
|
97
|
+
}
|
|
98
|
+
cleanEmptyProps(payment);
|
|
99
|
+
output.payments.push(payment);
|
|
100
|
+
}
|
|
101
|
+
for (let i = 0; i < paymentslen; i++) {
|
|
102
|
+
const name = intermediate.shift();
|
|
103
|
+
const addressLine1 = intermediate.shift();
|
|
104
|
+
const addressLine2 = intermediate.shift();
|
|
105
|
+
if (Boolean(name) || Boolean(addressLine1) || Boolean(addressLine2)) {
|
|
106
|
+
const beneficiary = {
|
|
107
|
+
name: name?.length ? name : undefined,
|
|
108
|
+
street: addressLine1?.length ? addressLine1 : undefined,
|
|
109
|
+
city: addressLine2?.length ? addressLine2 : undefined,
|
|
110
|
+
};
|
|
111
|
+
cleanEmptyProps(beneficiary);
|
|
112
|
+
output.payments[i].beneficiary = beneficiary;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return output;
|
|
116
|
+
}
|
|
117
|
+
exports.serialize = serialize;
|
|
118
|
+
/**
|
|
119
|
+
* @see 3.16. Decoding client data from QR Code 2005 symbol
|
|
120
|
+
*/
|
|
121
|
+
function parse(qr) {
|
|
122
|
+
try {
|
|
123
|
+
var decoded = rfc4648_1.base32hex.parse(qr, {
|
|
124
|
+
loose: true
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
catch {
|
|
128
|
+
throw new Error("Unable to parse QR");
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Omited lzma header based on properties lc: 3, lp: 0, pb: 2
|
|
132
|
+
*
|
|
133
|
+
* The LZMA files has a 13-byte header that is followed by the LZMA
|
|
134
|
+
* compressed data. The LZMA header consists of:
|
|
135
|
+
*
|
|
136
|
+
* +------------+----+----+----+----+--+--+--+--+--+--+--+--+
|
|
137
|
+
* | Properties | Dictionary Size | Uncompressed Size |
|
|
138
|
+
* +------------+----+----+----+----+--+--+--+--+--+--+--+--+
|
|
139
|
+
*
|
|
140
|
+
* @see https://docs.fileformat.com/compression/lzma/
|
|
141
|
+
* @see https://en.wikipedia.org/wiki/Lempel–Ziv–Markov_chain_algorithm
|
|
142
|
+
*/
|
|
143
|
+
const header = new Uint8Array([
|
|
144
|
+
0x5D /** lc <0,8> lp<0,4> pb <0,4> = lc + (lp * 9) + (pb * 9 * 5) */,
|
|
145
|
+
0x00, 0x00, 0x80, 0x00,
|
|
146
|
+
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF /** Uncompressed Size 64-bit little endian integer */
|
|
147
|
+
]);
|
|
148
|
+
const _bysquareHeader = decoded.slice(0, 2);
|
|
149
|
+
const _sizeChecksum = decoded.slice(2, 4);
|
|
150
|
+
const body = new Uint8Array([
|
|
151
|
+
...header,
|
|
152
|
+
...decoded.slice(4),
|
|
153
|
+
]);
|
|
154
|
+
const decompressed = lzma_1.default.decompress(body);
|
|
155
|
+
const _crc32 = decompressed.slice(0, 4);
|
|
156
|
+
const deserialized = strFromUTF8Array(decompressed.slice(4));
|
|
157
|
+
return serialize(deserialized);
|
|
158
|
+
}
|
|
159
|
+
exports.parse = parse;
|
|
160
|
+
/**
|
|
161
|
+
* Detect if qr string contains bysquare header.
|
|
162
|
+
*
|
|
163
|
+
* Bysquare header does not have too much information, therefore it is
|
|
164
|
+
* not very reliable, there is room for improvement for the future.
|
|
165
|
+
*/
|
|
166
|
+
function detect(qr) {
|
|
167
|
+
try {
|
|
168
|
+
var parsed = rfc4648_1.base32hex.parse(qr, {
|
|
169
|
+
loose: true
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
catch {
|
|
173
|
+
throw new Error("Unable to parse QR string, invalid data");
|
|
174
|
+
}
|
|
175
|
+
if (parsed.byteLength < 2) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
const header = parsed.subarray(0, 2);
|
|
179
|
+
const valid = [...hexStrFromUint8(header)]
|
|
180
|
+
.map((nibble) => parseInt(nibble, 16))
|
|
181
|
+
.every((nibble, index) => {
|
|
182
|
+
if ( /** version */index === 1) {
|
|
183
|
+
return 0 >= nibble && nibble <= 1;
|
|
184
|
+
}
|
|
185
|
+
return 0 <= nibble && nibble <= 15;
|
|
186
|
+
});
|
|
187
|
+
return valid;
|
|
188
|
+
}
|
|
189
|
+
exports.detect = detect;
|
|
190
|
+
// https://stackoverflow.com/questions/34309988/byte-array-to-hex-string-conversion-in-javascript#answer-34310051
|
|
191
|
+
function hexStrFromUint8(bytes) {
|
|
192
|
+
return Array.from(bytes, function (byte) {
|
|
193
|
+
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
|
|
194
|
+
}).join('');
|
|
195
|
+
}
|
|
196
|
+
// https://stackoverflow.com/questions/17191945/conversion-between-utf-8-arraybuffer-and-string#answer-22373135
|
|
197
|
+
function strFromUTF8Array(bytes) {
|
|
198
|
+
let out, i, len, c;
|
|
199
|
+
let char2, char3;
|
|
200
|
+
out = "";
|
|
201
|
+
len = bytes.length;
|
|
202
|
+
i = 0;
|
|
203
|
+
while (i < len) {
|
|
204
|
+
c = bytes[i++];
|
|
205
|
+
switch (c >> 4) {
|
|
206
|
+
case 0:
|
|
207
|
+
case 1:
|
|
208
|
+
case 2:
|
|
209
|
+
case 3:
|
|
210
|
+
case 4:
|
|
211
|
+
case 5:
|
|
212
|
+
case 6:
|
|
213
|
+
case 7:
|
|
214
|
+
// 0xxxxxxx
|
|
215
|
+
out += String.fromCharCode(c);
|
|
216
|
+
break;
|
|
217
|
+
case 12:
|
|
218
|
+
case 13:
|
|
219
|
+
// 110x xxxx 10xx xxxx
|
|
220
|
+
char2 = bytes[i++];
|
|
221
|
+
out += String.fromCharCode(((c & 0x1F) << 6) | (char2 & 0x3F));
|
|
222
|
+
break;
|
|
223
|
+
case 14:
|
|
224
|
+
// 1110 xxxx 10xx xxxx 10xx xxxx
|
|
225
|
+
char2 = bytes[i++];
|
|
226
|
+
char3 = bytes[i++];
|
|
227
|
+
out += String.fromCharCode(((c & 0x0F) << 12) |
|
|
228
|
+
((char2 & 0x3F) << 6) |
|
|
229
|
+
((char3 & 0x3F) << 0));
|
|
230
|
+
break;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return out;
|
|
234
|
+
}
|
|
File without changes
|
package/lib/cjs/types.js
ADDED
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CurrencyCodeEnum = exports.DirectDebitType = exports.DirectDebitScheme = exports.PaymentOptions = exports.Periodicity = exports.MonthClassifier = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Selection of one or more months on which payment occurs. This is enabled
|
|
6
|
+
* only if periodicity is set to one of the following value: “Weekly,
|
|
7
|
+
* Biweekly, Monthly, Bimonthly”. Otherwise it must not be specified.
|
|
8
|
+
*/
|
|
9
|
+
var MonthClassifier;
|
|
10
|
+
(function (MonthClassifier) {
|
|
11
|
+
MonthClassifier[MonthClassifier["January"] = 1] = "January";
|
|
12
|
+
MonthClassifier[MonthClassifier["February"] = 2] = "February";
|
|
13
|
+
MonthClassifier[MonthClassifier["March"] = 4] = "March";
|
|
14
|
+
MonthClassifier[MonthClassifier["April"] = 8] = "April";
|
|
15
|
+
MonthClassifier[MonthClassifier["May"] = 16] = "May";
|
|
16
|
+
MonthClassifier[MonthClassifier["June"] = 32] = "June";
|
|
17
|
+
MonthClassifier[MonthClassifier["July"] = 64] = "July";
|
|
18
|
+
MonthClassifier[MonthClassifier["August"] = 128] = "August";
|
|
19
|
+
MonthClassifier[MonthClassifier["September"] = 256] = "September";
|
|
20
|
+
MonthClassifier[MonthClassifier["October"] = 512] = "October";
|
|
21
|
+
MonthClassifier[MonthClassifier["November"] = 1024] = "November";
|
|
22
|
+
MonthClassifier[MonthClassifier["December"] = 2048] = "December";
|
|
23
|
+
})(MonthClassifier = exports.MonthClassifier || (exports.MonthClassifier = {}));
|
|
24
|
+
/**
|
|
25
|
+
* Periodicity of the payment. All valid options are „Daily“, „Weekly“,
|
|
26
|
+
* „Biweekly“, „Monthly“, „Bimonthly“, „Quarterly“, „Annually“,
|
|
27
|
+
* „Semiannually“. To find out which periodicity types are supported by the
|
|
28
|
+
* banks see the following web site: http://www.sbaonline.sk/sk/
|
|
29
|
+
*/
|
|
30
|
+
var Periodicity;
|
|
31
|
+
(function (Periodicity) {
|
|
32
|
+
Periodicity["Daily"] = "d";
|
|
33
|
+
Periodicity["Weekly"] = "w";
|
|
34
|
+
Periodicity["Biweekly"] = "b";
|
|
35
|
+
Periodicity["Monthly"] = "m";
|
|
36
|
+
Periodicity["Bimonthly"] = "B";
|
|
37
|
+
Periodicity["Quarterly"] = "q";
|
|
38
|
+
Periodicity["Semiannually"] = "s";
|
|
39
|
+
Periodicity["Annually"] = "a";
|
|
40
|
+
})(Periodicity = exports.Periodicity || (exports.Periodicity = {}));
|
|
41
|
+
var PaymentOptions;
|
|
42
|
+
(function (PaymentOptions) {
|
|
43
|
+
PaymentOptions[PaymentOptions["PaymentOrder"] = 1] = "PaymentOrder";
|
|
44
|
+
PaymentOptions[PaymentOptions["StandingOrder"] = 2] = "StandingOrder";
|
|
45
|
+
PaymentOptions[PaymentOptions["DirectDebit"] = 4] = "DirectDebit";
|
|
46
|
+
})(PaymentOptions = exports.PaymentOptions || (exports.PaymentOptions = {}));
|
|
47
|
+
/**
|
|
48
|
+
* If DirectDebitScheme value is 1, which is „SEPA“ than encoded direct
|
|
49
|
+
* debit follows SEPA direct debit scheme which means that fields MandateID,
|
|
50
|
+
* CreditorID and optional ContractID are used. If direct debit scheme is 0,
|
|
51
|
+
* which is „OTHER“ this means no specific direct debit scheme and following
|
|
52
|
+
* rules do apply:
|
|
53
|
+
*
|
|
54
|
+
* a. Creditor is identified via bank accounts
|
|
55
|
+
*
|
|
56
|
+
* b. Contract between debtor and creditor is identified using one of the
|
|
57
|
+
* following two ways: 1. by two optional fields SpecificSymbol and
|
|
58
|
+
* VariableSymbol. 2. by one optional field OriginatorsReferenceInformation.
|
|
59
|
+
* If SpecificSymbol and VariableSymbol fields or
|
|
60
|
+
* OriginatorsReferenceInformation field is filled in DirectDebitExt then
|
|
61
|
+
* these fields do apply for the direct debit.
|
|
62
|
+
*/
|
|
63
|
+
var DirectDebitScheme;
|
|
64
|
+
(function (DirectDebitScheme) {
|
|
65
|
+
DirectDebitScheme[DirectDebitScheme["Other"] = 0] = "Other";
|
|
66
|
+
DirectDebitScheme[DirectDebitScheme["Sepa"] = 1] = "Sepa";
|
|
67
|
+
})(DirectDebitScheme = exports.DirectDebitScheme || (exports.DirectDebitScheme = {}));
|
|
68
|
+
/**
|
|
69
|
+
* Can be „oneoff“ for one time debit or „recurrent“ for repeated debit
|
|
70
|
+
* until cancelled.
|
|
71
|
+
*
|
|
72
|
+
* Max length 1
|
|
73
|
+
*/
|
|
74
|
+
var DirectDebitType;
|
|
75
|
+
(function (DirectDebitType) {
|
|
76
|
+
DirectDebitType[DirectDebitType["OneOff"] = 0] = "OneOff";
|
|
77
|
+
DirectDebitType[DirectDebitType["Recurrent"] = 1] = "Recurrent";
|
|
78
|
+
})(DirectDebitType = exports.DirectDebitType || (exports.DirectDebitType = {}));
|
|
79
|
+
/**
|
|
80
|
+
* Currency codes based on ISO-4217
|
|
81
|
+
*/
|
|
82
|
+
var CurrencyCodeEnum;
|
|
83
|
+
(function (CurrencyCodeEnum) {
|
|
84
|
+
CurrencyCodeEnum["AED"] = "United Arab Emirates Dirham";
|
|
85
|
+
CurrencyCodeEnum["AFN"] = "Afghanistan Afghani";
|
|
86
|
+
CurrencyCodeEnum["ALL"] = "Albania Lek";
|
|
87
|
+
CurrencyCodeEnum["AMD"] = "Armenia Dram";
|
|
88
|
+
CurrencyCodeEnum["ANG"] = "Netherlands Antilles Guilder";
|
|
89
|
+
CurrencyCodeEnum["AOA"] = "Angola Kwanza";
|
|
90
|
+
CurrencyCodeEnum["ARS"] = "Argentina Peso";
|
|
91
|
+
CurrencyCodeEnum["AUD"] = "Australia Dollar";
|
|
92
|
+
CurrencyCodeEnum["AWG"] = "Aruba Guilder";
|
|
93
|
+
CurrencyCodeEnum["AZN"] = "Azerbaijan New Manat";
|
|
94
|
+
CurrencyCodeEnum["BAM"] = "Bosnia and Herzegovina Convertible Marka";
|
|
95
|
+
CurrencyCodeEnum["BBD"] = "Barbados Dollar";
|
|
96
|
+
CurrencyCodeEnum["BDT"] = "Bangladesh Taka";
|
|
97
|
+
CurrencyCodeEnum["BGN"] = "Bulgaria Lev";
|
|
98
|
+
CurrencyCodeEnum["BHD"] = "Bahrain Dinar";
|
|
99
|
+
CurrencyCodeEnum["BIF"] = "Burundi Franc";
|
|
100
|
+
CurrencyCodeEnum["BMD"] = "Bermuda Dollar";
|
|
101
|
+
CurrencyCodeEnum["BND"] = "Brunei Darussalam Dollar";
|
|
102
|
+
CurrencyCodeEnum["BOB"] = "Bolivia Bol\u00EDviano";
|
|
103
|
+
CurrencyCodeEnum["BRL"] = "Brazil Real";
|
|
104
|
+
CurrencyCodeEnum["BSD"] = "Bahamas Dollar";
|
|
105
|
+
CurrencyCodeEnum["BTN"] = "Bhutan Ngultrum";
|
|
106
|
+
CurrencyCodeEnum["BWP"] = "Botswana Pula";
|
|
107
|
+
CurrencyCodeEnum["BYR"] = "Belarus Ruble";
|
|
108
|
+
CurrencyCodeEnum["BZD"] = "Belize Dollar";
|
|
109
|
+
CurrencyCodeEnum["CAD"] = "Canada Dollar";
|
|
110
|
+
CurrencyCodeEnum["CDF"] = "Congo/Kinshasa Franc";
|
|
111
|
+
CurrencyCodeEnum["CHF"] = "Switzerland Franc";
|
|
112
|
+
CurrencyCodeEnum["CLP"] = "Chile Peso";
|
|
113
|
+
CurrencyCodeEnum["CNY"] = "China Yuan Renminbi";
|
|
114
|
+
CurrencyCodeEnum["COP"] = "Colombia Peso";
|
|
115
|
+
CurrencyCodeEnum["CRC"] = "Costa Rica Colon";
|
|
116
|
+
CurrencyCodeEnum["CUC"] = "Cuba Convertible Peso";
|
|
117
|
+
CurrencyCodeEnum["CUP"] = "Cuba Peso";
|
|
118
|
+
CurrencyCodeEnum["CVE"] = "Cape Verde Escudo";
|
|
119
|
+
CurrencyCodeEnum["CZK"] = "Czech Republic Koruna";
|
|
120
|
+
CurrencyCodeEnum["DJF"] = "Djibouti Franc";
|
|
121
|
+
CurrencyCodeEnum["DKK"] = "Denmark Krone";
|
|
122
|
+
CurrencyCodeEnum["DOP"] = "Dominican Republic Peso";
|
|
123
|
+
CurrencyCodeEnum["DZD"] = "Algeria Dinar";
|
|
124
|
+
CurrencyCodeEnum["EGP"] = "Egypt Pound";
|
|
125
|
+
CurrencyCodeEnum["ERN"] = "Eritrea Nakfa";
|
|
126
|
+
CurrencyCodeEnum["ETB"] = "Ethiopia Birr";
|
|
127
|
+
CurrencyCodeEnum["EUR"] = "Euro Member Countries";
|
|
128
|
+
CurrencyCodeEnum["FJD"] = "Fiji Dollar";
|
|
129
|
+
CurrencyCodeEnum["FKP"] = "Falkland Islands = Malvinas Pound";
|
|
130
|
+
CurrencyCodeEnum["GBP"] = "United Kingdom Pound";
|
|
131
|
+
CurrencyCodeEnum["GEL"] = "Georgia Lari";
|
|
132
|
+
CurrencyCodeEnum["GGP"] = "Guernsey Pound";
|
|
133
|
+
CurrencyCodeEnum["GHS"] = "Ghana Cedi";
|
|
134
|
+
CurrencyCodeEnum["GIP"] = "Gibraltar Pound";
|
|
135
|
+
CurrencyCodeEnum["GMD"] = "Gambia Dalasi";
|
|
136
|
+
CurrencyCodeEnum["GNF"] = "Guinea Franc";
|
|
137
|
+
CurrencyCodeEnum["GTQ"] = "Guatemala Quetzal";
|
|
138
|
+
CurrencyCodeEnum["GYD"] = "Guyana Dollar";
|
|
139
|
+
CurrencyCodeEnum["HKD"] = "Hong Kong Dollar";
|
|
140
|
+
CurrencyCodeEnum["HNL"] = "Honduras Lempira";
|
|
141
|
+
CurrencyCodeEnum["HRK"] = "Croatia Kuna";
|
|
142
|
+
CurrencyCodeEnum["HTG"] = "Haiti Gourde";
|
|
143
|
+
CurrencyCodeEnum["HUF"] = "Hungary Forint";
|
|
144
|
+
CurrencyCodeEnum["IDR"] = "Indonesia Rupiah";
|
|
145
|
+
CurrencyCodeEnum["ILS"] = "Israel Shekel";
|
|
146
|
+
CurrencyCodeEnum["IMP"] = "Isle of Man Pound";
|
|
147
|
+
CurrencyCodeEnum["INR"] = "India Rupee";
|
|
148
|
+
CurrencyCodeEnum["IQD"] = "Iraq Dinar";
|
|
149
|
+
CurrencyCodeEnum["IRR"] = "Iran Rial";
|
|
150
|
+
CurrencyCodeEnum["ISK"] = "Iceland Krona";
|
|
151
|
+
CurrencyCodeEnum["JEP"] = "Jersey Pound";
|
|
152
|
+
CurrencyCodeEnum["JMD"] = "Jamaica Dollar";
|
|
153
|
+
CurrencyCodeEnum["JOD"] = "Jordan Dinar";
|
|
154
|
+
CurrencyCodeEnum["JPY"] = "Japan Yen";
|
|
155
|
+
CurrencyCodeEnum["KES"] = "Kenya Shilling";
|
|
156
|
+
CurrencyCodeEnum["KGS"] = "Kyrgyzstan Som";
|
|
157
|
+
CurrencyCodeEnum["KHR"] = "Cambodia Riel";
|
|
158
|
+
CurrencyCodeEnum["KMF"] = "Comoros Franc";
|
|
159
|
+
CurrencyCodeEnum["KPW"] = "Korea = North Won";
|
|
160
|
+
CurrencyCodeEnum["KRW"] = "Korea = South Won";
|
|
161
|
+
CurrencyCodeEnum["KWD"] = "Kuwait Dinar";
|
|
162
|
+
CurrencyCodeEnum["KYD"] = "Cayman Islands Dollar";
|
|
163
|
+
CurrencyCodeEnum["KZT"] = "Kazakhstan Tenge";
|
|
164
|
+
CurrencyCodeEnum["LAK"] = "Laos Kip";
|
|
165
|
+
CurrencyCodeEnum["LBP"] = "Lebanon Pound";
|
|
166
|
+
CurrencyCodeEnum["LKR"] = "Sri Lanka Rupee";
|
|
167
|
+
CurrencyCodeEnum["LRD"] = "Liberia Dollar";
|
|
168
|
+
CurrencyCodeEnum["LSL"] = "Lesotho Loti";
|
|
169
|
+
CurrencyCodeEnum["LYD"] = "Libya Dinar";
|
|
170
|
+
CurrencyCodeEnum["MAD"] = "Morocco Dirham";
|
|
171
|
+
CurrencyCodeEnum["MDL"] = "Moldova Leu";
|
|
172
|
+
CurrencyCodeEnum["MGA"] = "Madagascar Ariary";
|
|
173
|
+
CurrencyCodeEnum["MKD"] = "Macedonia Denar";
|
|
174
|
+
CurrencyCodeEnum["MMK"] = "Myanmar = Burma Kyat";
|
|
175
|
+
CurrencyCodeEnum["MNT"] = "Mongolia Tughrik";
|
|
176
|
+
CurrencyCodeEnum["MOP"] = "Macau Pataca";
|
|
177
|
+
CurrencyCodeEnum["MRO"] = "Mauritania Ouguiya";
|
|
178
|
+
CurrencyCodeEnum["MUR"] = "Mauritius Rupee";
|
|
179
|
+
CurrencyCodeEnum["MVR"] = "Maldives = Maldive Islands Rufiyaa";
|
|
180
|
+
CurrencyCodeEnum["MWK"] = "Malawi Kwacha";
|
|
181
|
+
CurrencyCodeEnum["MXN"] = "Mexico Peso";
|
|
182
|
+
CurrencyCodeEnum["MYR"] = "Malaysia Ringgit";
|
|
183
|
+
CurrencyCodeEnum["MZN"] = "Mozambique Metical";
|
|
184
|
+
CurrencyCodeEnum["NAD"] = "Namibia Dollar";
|
|
185
|
+
CurrencyCodeEnum["NGN"] = "Nigeria Naira";
|
|
186
|
+
CurrencyCodeEnum["NIO"] = "Nicaragua Cordoba";
|
|
187
|
+
CurrencyCodeEnum["NOK"] = "Norway Krone";
|
|
188
|
+
CurrencyCodeEnum["NPR"] = "Nepal Rupee";
|
|
189
|
+
CurrencyCodeEnum["NZD"] = "New Zealand Dollar";
|
|
190
|
+
CurrencyCodeEnum["OMR"] = "Oman Rial";
|
|
191
|
+
CurrencyCodeEnum["PAB"] = "Panama Balboa";
|
|
192
|
+
CurrencyCodeEnum["PEN"] = "Peru Sol";
|
|
193
|
+
CurrencyCodeEnum["PGK"] = "Papua New Guinea Kina";
|
|
194
|
+
CurrencyCodeEnum["PHP"] = "Philippines Peso";
|
|
195
|
+
CurrencyCodeEnum["PKR"] = "Pakistan Rupee";
|
|
196
|
+
CurrencyCodeEnum["PLN"] = "Poland Zloty";
|
|
197
|
+
CurrencyCodeEnum["PYG"] = "Paraguay Guarani";
|
|
198
|
+
CurrencyCodeEnum["QAR"] = "Qatar Riyal";
|
|
199
|
+
CurrencyCodeEnum["RON"] = "Romania New Leu";
|
|
200
|
+
CurrencyCodeEnum["RSD"] = "Serbia Dinar";
|
|
201
|
+
CurrencyCodeEnum["RUB"] = "Russia Ruble";
|
|
202
|
+
CurrencyCodeEnum["RWF"] = "Rwanda Franc";
|
|
203
|
+
CurrencyCodeEnum["SAR"] = "Saudi Arabia Riyal";
|
|
204
|
+
CurrencyCodeEnum["SBD"] = "Solomon Islands Dollar";
|
|
205
|
+
CurrencyCodeEnum["SCR"] = "Seychelles Rupee";
|
|
206
|
+
CurrencyCodeEnum["SDG"] = "Sudan Pound";
|
|
207
|
+
CurrencyCodeEnum["SEK"] = "Sweden Krona";
|
|
208
|
+
CurrencyCodeEnum["SGD"] = "Singapore Dollar";
|
|
209
|
+
CurrencyCodeEnum["SHP"] = "Saint Helena Pound";
|
|
210
|
+
CurrencyCodeEnum["SLL"] = "Sierra Leone Leone";
|
|
211
|
+
CurrencyCodeEnum["SOS"] = "Somalia Shilling";
|
|
212
|
+
CurrencyCodeEnum["SPL"] = "Seborga Luigino";
|
|
213
|
+
CurrencyCodeEnum["SRD"] = "Suriname Dollar";
|
|
214
|
+
CurrencyCodeEnum["STD"] = "S\u00E3o Tom\u00E9 and Pr\u00EDncipe Dobra";
|
|
215
|
+
CurrencyCodeEnum["SVC"] = "El Salvador Colon";
|
|
216
|
+
CurrencyCodeEnum["SYP"] = "Syria Pound";
|
|
217
|
+
CurrencyCodeEnum["SZL"] = "Swaziland Lilangeni";
|
|
218
|
+
CurrencyCodeEnum["THB"] = "Thailand Baht";
|
|
219
|
+
CurrencyCodeEnum["TJS"] = "Tajikistan Somoni";
|
|
220
|
+
CurrencyCodeEnum["TMT"] = "Turkmenistan Manat";
|
|
221
|
+
CurrencyCodeEnum["TND"] = "Tunisia Dinar";
|
|
222
|
+
CurrencyCodeEnum["TOP"] = "Tonga Pa'anga";
|
|
223
|
+
CurrencyCodeEnum["TRY"] = "Turkey Lira";
|
|
224
|
+
CurrencyCodeEnum["TTD"] = "Trinidad and Tobago Dollar";
|
|
225
|
+
CurrencyCodeEnum["TVD"] = "Tuvalu Dollar";
|
|
226
|
+
CurrencyCodeEnum["TWD"] = "Taiwan New Dollar";
|
|
227
|
+
CurrencyCodeEnum["TZS"] = "Tanzania Shilling";
|
|
228
|
+
CurrencyCodeEnum["UAH"] = "Ukraine Hryvnia";
|
|
229
|
+
CurrencyCodeEnum["UGX"] = "Uganda Shilling";
|
|
230
|
+
CurrencyCodeEnum["USD"] = "United States Dollar";
|
|
231
|
+
CurrencyCodeEnum["UYU"] = "Uruguay Peso";
|
|
232
|
+
CurrencyCodeEnum["UZS"] = "Uzbekistan Som";
|
|
233
|
+
CurrencyCodeEnum["VEF"] = "Venezuela Bolivar";
|
|
234
|
+
CurrencyCodeEnum["VND"] = "Viet Nam Dong";
|
|
235
|
+
CurrencyCodeEnum["VUV"] = "Vanuatu Vatu";
|
|
236
|
+
CurrencyCodeEnum["WST"] = "Samoa Tala";
|
|
237
|
+
CurrencyCodeEnum["XAF"] = "Communaut\u00E9 Financi\u00E8re Africaine = BEAC CFA Franc BEAC";
|
|
238
|
+
CurrencyCodeEnum["XCD"] = "East Caribbean Dollar";
|
|
239
|
+
CurrencyCodeEnum["XDR"] = "International Monetary Fund = IMF Special Drawing Rights";
|
|
240
|
+
CurrencyCodeEnum["XOF"] = "Communaut\u00E9 Financi\u00E8re Africaine = BCEAO Franc";
|
|
241
|
+
CurrencyCodeEnum["XPF"] = "Comptoirs Fran\u00E7ais du Pacifique = CFP Franc";
|
|
242
|
+
CurrencyCodeEnum["YER"] = "Yemen Rial";
|
|
243
|
+
CurrencyCodeEnum["ZAR"] = "South Africa Rand";
|
|
244
|
+
CurrencyCodeEnum["ZMW"] = "Zambia Kwacha";
|
|
245
|
+
CurrencyCodeEnum["ZWD"] = "Zimbabwe Dollar";
|
|
246
|
+
})(CurrencyCodeEnum = exports.CurrencyCodeEnum || (exports.CurrencyCodeEnum = {}));
|
package/lib/mjs/cli.d.ts
ADDED
|
@@ -12,43 +12,27 @@ else {
|
|
|
12
12
|
;
|
|
13
13
|
(async () => {
|
|
14
14
|
const stdin = await handleStdin();
|
|
15
|
-
|
|
16
|
-
console.error(e);
|
|
17
|
-
process.exit(1);
|
|
18
|
-
});
|
|
19
|
-
console.log(qr);
|
|
15
|
+
console.log(fromJsonString(stdin));
|
|
20
16
|
process.exit(0);
|
|
21
17
|
})();
|
|
22
18
|
}
|
|
23
|
-
|
|
19
|
+
function handleInput(input) {
|
|
24
20
|
if (input === undefined || input === "-h" || input === "--help") {
|
|
25
21
|
console.log(help());
|
|
26
22
|
process.exit(0);
|
|
27
23
|
}
|
|
28
24
|
if (existsSync(process.argv[2])) {
|
|
29
25
|
const file = readFileSync(process.argv[2], "utf8");
|
|
30
|
-
|
|
31
|
-
console.error(e);
|
|
32
|
-
process.exit(1);
|
|
33
|
-
});
|
|
34
|
-
console.log(qr);
|
|
26
|
+
console.log(fromJsonString(file));
|
|
35
27
|
}
|
|
36
28
|
else {
|
|
37
29
|
console.error(`File ${process.argv[2]} doesn't exists`);
|
|
38
30
|
process.exit(1);
|
|
39
31
|
}
|
|
40
32
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const data = JSON.parse(stdin);
|
|
45
|
-
const qrString = generate(data);
|
|
46
|
-
resolve(qrString);
|
|
47
|
-
}
|
|
48
|
-
catch (e) {
|
|
49
|
-
reject(e);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
33
|
+
function fromJsonString(stdin) {
|
|
34
|
+
const data = JSON.parse(stdin);
|
|
35
|
+
return generate(data);
|
|
52
36
|
}
|
|
53
37
|
async function handleStdin() {
|
|
54
38
|
const readline = createInterface({
|
|
@@ -85,18 +69,17 @@ function help() {
|
|
|
85
69
|
"If <file> is omitted, reads from stdin.",
|
|
86
70
|
"",
|
|
87
71
|
"Examples:",
|
|
88
|
-
"
|
|
89
|
-
"",
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
"
|
|
100
|
-
" | bysquare"
|
|
72
|
+
" bysquare <<< \"{",
|
|
73
|
+
" \"invoiceId\": \"random-id\",",
|
|
74
|
+
" \"payments\": [",
|
|
75
|
+
" {",
|
|
76
|
+
" \"type\": 1,",
|
|
77
|
+
" \"amount\": 100.0,",
|
|
78
|
+
" \"bankAccounts\": [{ \"iban\": \"SK9611000000002918599669\" }],",
|
|
79
|
+
" \"currencyCode\": \"EUR\",",
|
|
80
|
+
" \"variableSymbol\": \"123\"",
|
|
81
|
+
" }",
|
|
82
|
+
" ]",
|
|
83
|
+
" }\"",
|
|
101
84
|
].join("\n");
|
|
102
85
|
}
|
|
@@ -20,7 +20,7 @@ export declare function bysquareHeader(header?: [
|
|
|
20
20
|
version: number,
|
|
21
21
|
documentType: number,
|
|
22
22
|
reserved: number
|
|
23
|
-
]):
|
|
23
|
+
]): Uint8Array;
|
|
24
24
|
/**
|
|
25
25
|
* @see 3.10 Appending CRC32 checksum
|
|
26
26
|
*/
|
|
@@ -30,19 +30,25 @@ export declare function checksum(intermediate: string): Buffer;
|
|
|
30
30
|
*
|
|
31
31
|
* @see 3.10. Appending CRC32 checksum
|
|
32
32
|
*/
|
|
33
|
-
export declare function
|
|
33
|
+
export declare function addChecksum(model: DataModel): Uint8Array;
|
|
34
34
|
/**
|
|
35
35
|
* Transform data to ordered tab-separated intermediate representation ready for
|
|
36
36
|
* encoding
|
|
37
37
|
*
|
|
38
38
|
* @see Table 15 PAY by square sequence data model
|
|
39
39
|
*/
|
|
40
|
-
export declare function
|
|
40
|
+
export declare function deserialize(data: DataModel): string;
|
|
41
41
|
type Options = {
|
|
42
|
+
/**
|
|
43
|
+
* Many banking apps do not support diacritics, which results in errors when
|
|
44
|
+
* serializing data from QR codes.
|
|
45
|
+
*
|
|
46
|
+
* @default true
|
|
47
|
+
*/
|
|
42
48
|
deburr: boolean;
|
|
43
49
|
};
|
|
44
50
|
/**
|
|
45
51
|
* Generate QR string ready for encoding into text QR code
|
|
46
52
|
*/
|
|
47
|
-
export declare function generate(model: DataModel, options?: Options):
|
|
53
|
+
export declare function generate(model: DataModel, options?: Options): string;
|
|
48
54
|
export {};
|