upn-library-v2 1.0.0 → 1.0.1

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 ADDED
@@ -0,0 +1,56 @@
1
+ # upn-library
2
+
3
+ A simple JS library for creating UPN QR codes using the https://www.npmjs.com/package/qrcode package
4
+
5
+ # installation:
6
+
7
+ Inside your project folder:
8
+
9
+ ```shell
10
+ npm i upn-library-v2
11
+ ```
12
+
13
+ # usage
14
+
15
+ Example using VueJs
16
+
17
+ ```html
18
+ <script>
19
+ import { generateUPNQR } from "upn-library-v2";
20
+
21
+ export default {
22
+ name: "QrCodePage",
23
+ async mounted() {
24
+ this.$refs.qrCodeImg = await generateUPNQR({
25
+ price: 10,
26
+ title_code: 'COST',
27
+ title: 'Payment for x',
28
+ due_date: new Date(),
29
+ reference: 'SI00 xxxxx',
30
+
31
+ payer: {
32
+ name: 'x',
33
+ surname: 'x',
34
+ address: 'Example 14',
35
+ zip: '1234',
36
+ city: 'city'
37
+ },
38
+
39
+ payee: {
40
+ title: 'X company',
41
+ iban: 'SI100 00 00 00',
42
+ address: 'Example 14',
43
+ zip: '1234',
44
+ city: 'city'
45
+ }
46
+ })
47
+ }
48
+ }
49
+ </script>
50
+
51
+ <template>
52
+ <div>
53
+ <img ref="qrCodeImg" />
54
+ </div>
55
+ </template>
56
+ ```
package/package.json CHANGED
@@ -1,8 +1,13 @@
1
1
  {
2
2
  "name": "upn-library-v2",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "main": "src/index.js",
5
- "keywords": [],
5
+ "keywords": [
6
+ "UPN",
7
+ "QR",
8
+ "QR code",
9
+ "generation"
10
+ ],
6
11
  "author": "Tomaž Čede",
7
12
  "license": "ISC",
8
13
  "description": "",
package/src/index.js CHANGED
@@ -38,7 +38,7 @@ function validateOption(object, option, level = '') {
38
38
  function validateOptions(options) {
39
39
  if (!options) throw new Error('Options are not defined');
40
40
 
41
- const requiredTopLevel = ['payer', 'payee', 'price', 'payment_date', 'title_code', 'title', 'due_date', 'reference'];
41
+ const requiredTopLevel = ['payer', 'payee', 'price', 'title_code', 'title', 'due_date', 'reference'];
42
42
  for (const field of requiredTopLevel) {
43
43
  validateOption(options, field)
44
44
  }
package/dist/upn-qr.es.js DELETED
@@ -1,74 +0,0 @@
1
- import e from "qrcode";
2
- //#region src/index.js
3
- function t(e) {
4
- return !e || typeof e !== Date ? "" : String(e.getDate()).padStart(2, "0") + "." + String(e.getMonth() + 1).padStart(2, "0") + "." + e.getFullYear();
5
- }
6
- function n(e) {
7
- return (e * 100 + "").padStart(11, "0");
8
- }
9
- function r(e) {
10
- return e.replace(/\s/g, "");
11
- }
12
- function i(e) {
13
- return 19 + e.reduce((e, t) => e + t.length, 0);
14
- }
15
- function a(e) {
16
- return e.reduce((e, t) => e + t + "\n", "") + i(e) + "";
17
- }
18
- function o(e, t, n = "") {
19
- if (e[t] === void 0 || e[t] === null) throw Error(`${n} ${t} is not defined, define it using options.${n ? n + "." : ""}${t}`);
20
- }
21
- function s(e) {
22
- if (!e) throw Error("Options are not defined");
23
- for (let t of [
24
- "payer",
25
- "payee",
26
- "price",
27
- "payment_date",
28
- "title_code",
29
- "title",
30
- "due_date",
31
- "reference"
32
- ]) o(e, t);
33
- for (let t of [
34
- "name",
35
- "surname",
36
- "address",
37
- "zip",
38
- "city"
39
- ]) o(e.payer, t, "Payer");
40
- for (let t of [
41
- "iban",
42
- "title",
43
- "address",
44
- "zip",
45
- "city"
46
- ]) o(e.payee, t, "Payee");
47
- }
48
- async function c(i, o = 300) {
49
- s(i);
50
- let c = a([
51
- "UPNQR",
52
- r(i.payer.iban ?? ""),
53
- "",
54
- "",
55
- "",
56
- i.payer.name + " " + i.payer.surname,
57
- i.payer.address + "",
58
- i.payer.zip + " " + i.payer.city,
59
- n(i.price) + "",
60
- t(i.payment_date),
61
- "",
62
- i.title_code ?? "COST",
63
- i.title + "",
64
- t(i.due_date) + "",
65
- r(i.payee.iban) + "",
66
- i.reference + "",
67
- i.payee.title + "",
68
- i.payee.address + "",
69
- i.payee.zip + " " + i.payee.city
70
- ]);
71
- return e.toDataURL(c, { width: o });
72
- }
73
- //#endregion
74
- export { c as generateUPNQR };