@vn-contrib/napas-qr 0.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 CHANGED
@@ -1,2 +1,24 @@
1
1
  # NapasQR
2
- NapasQR's value generation
2
+ NapasQR code generation following [NAPAS standard](https://vietqr.net/portal-service/download/documents/QR_Format_T&C_v1.5.2_EN_102022.pdf).
3
+
4
+ > [!NOTE]
5
+ > This package only generate code in string format, use your own package like [qrcode](https://www.npmjs.com/package/qrcode) or [qrcode.react](https://www.npmjs.com/package/qrcode.react) to generate QR image
6
+
7
+ ## Installation
8
+ ```bash
9
+ npm install @vn-contrib/napas-qr
10
+ ```
11
+
12
+ ## Usage
13
+ ```tsx
14
+ import { QRCodeSVG } from 'qrcode.react'
15
+ import { generateCode } from '@vn-contrib/napas-qr'
16
+
17
+ function Example() {
18
+ const code = generateCode({ bin: '970403', account: '0123456789' })
19
+ return <QRCodeSVG value={code} />
20
+ }
21
+ ```
22
+
23
+ ## License
24
+ [MIT License](LICENSE)
package/dist/main.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Method, ServiceCode } from './constants';
2
+ export * from './constants';
2
3
  interface NapasQRProps {
3
4
  method?: Method;
4
5
  system?: number;
@@ -8,7 +9,7 @@ interface NapasQRProps {
8
9
  amount?: number;
9
10
  currency?: number;
10
11
  countryCode?: string;
11
- description?: string;
12
+ purpose?: string;
13
+ bill?: string;
12
14
  }
13
- export declare function generateValue({ method, system, serviceCode, bin, account, amount, currency, countryCode, description }: NapasQRProps): string;
14
- export {};
15
+ export declare function generateCode({ method, system, serviceCode, bin, account, amount, currency, countryCode, purpose, bill }: NapasQRProps): string;
package/dist/main.js CHANGED
@@ -1,5 +1,5 @@
1
- var l = /* @__PURE__ */ ((t) => (t[t.Static = 11] = "Static", t[t.Dynamic = 12] = "Dynamic", t))(l || {}), s = /* @__PURE__ */ ((t) => (t[t.NAPAS = 38] = "NAPAS", t))(s || {}), f = /* @__PURE__ */ ((t) => (t.Push = "QRPUSH", t.Cash = "QRCASH", t.CardTransfer = "QRIBFTTC", t.AccountTransfer = "QRIBFTTA", t))(f || {}), i = /* @__PURE__ */ ((t) => (t[t.VND = 704] = "VND", t))(i || {}), A = /* @__PURE__ */ ((t) => (t.VN = "VN", t))(A || {});
2
- function T(t) {
1
+ var u = /* @__PURE__ */ ((t) => (t[t.Static = 11] = "Static", t[t.Dynamic = 12] = "Dynamic", t))(u || {}), i = /* @__PURE__ */ ((t) => (t[t.NAPAS = 38] = "NAPAS", t))(i || {}), A = /* @__PURE__ */ ((t) => (t.Push = "QRPUSH", t.Cash = "QRCASH", t.CardTransfer = "QRIBFTTC", t.AccountTransfer = "QRIBFTTA", t))(A || {}), l = /* @__PURE__ */ ((t) => (t[t.VND = 704] = "VND", t))(l || {}), N = /* @__PURE__ */ ((t) => (t.VN = "VN", t))(N || {});
2
+ function V(t) {
3
3
  let r = 65535;
4
4
  for (let n = 0; n < t.length; n++) {
5
5
  r ^= t.charCodeAt(n) << 8;
@@ -9,26 +9,27 @@ function T(t) {
9
9
  }
10
10
  return r;
11
11
  }
12
- function N(t) {
12
+ function S(t) {
13
13
  let e = "";
14
14
  for (const [r, n] of Object.entries(t).sort((a, o) => a[0] > o[0] ? 1 : -1)) {
15
- const a = typeof n == "string" ? n : typeof n == "number" ? n.toString() : N(n);
15
+ const a = typeof n == "string" ? n : typeof n == "number" ? n.toString() : S(n);
16
16
  e += r + a.length.toString().padStart(2, "0") + a;
17
17
  }
18
18
  return e;
19
19
  }
20
- function V({
21
- method: t = l.Static,
22
- system: e = s.NAPAS,
23
- serviceCode: r = f.AccountTransfer,
20
+ function p({
21
+ method: t = u.Static,
22
+ system: e = i.NAPAS,
23
+ serviceCode: r = A.AccountTransfer,
24
24
  bin: n,
25
25
  account: a,
26
26
  amount: o,
27
- currency: S = i.VND,
28
- countryCode: p = A.VN,
29
- description: c
27
+ currency: g = l.VND,
28
+ countryCode: T = N.VN,
29
+ purpose: c,
30
+ bill: s
30
31
  }) {
31
- const g = {
32
+ const D = {
32
33
  // payload format indicator
33
34
  "00": "01",
34
35
  // point of initiation method
@@ -48,17 +49,29 @@ function V({
48
49
  "02": r
49
50
  },
50
51
  // currency
51
- 53: S,
52
+ 53: g,
52
53
  ...o && {
53
54
  54: o
54
55
  },
55
- 58: p,
56
- ...c && {
57
- 62: c
56
+ 58: T,
57
+ ...(s || c) && {
58
+ 62: {
59
+ ...s && {
60
+ "01": s
61
+ },
62
+ ...c && {
63
+ "08": c
64
+ }
65
+ }
58
66
  }
59
- }, u = N(g) + "6304";
60
- return u + T(u).toString(16).toUpperCase().padStart(4, "0");
67
+ }, f = S(D) + "6304";
68
+ return f + V(f).toString(16).toUpperCase().padStart(4, "0");
61
69
  }
62
70
  export {
63
- V as generateValue
71
+ N as CountryCode,
72
+ l as Currency,
73
+ u as Method,
74
+ A as ServiceCode,
75
+ i as System,
76
+ p as generateCode
64
77
  };
package/dist/main.umd.cjs CHANGED
@@ -1 +1 @@
1
- (function(a,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(a=typeof globalThis<"u"?globalThis:a||self,o(a.NapasQR={}))})(this,(function(a){"use strict";var o=(t=>(t[t.Static=11]="Static",t[t.Dynamic=12]="Dynamic",t))(o||{}),f=(t=>(t[t.NAPAS=38]="NAPAS",t))(f||{}),s=(t=>(t.Push="QRPUSH",t.Cash="QRCASH",t.CardTransfer="QRIBFTTC",t.AccountTransfer="QRIBFTTA",t))(s||{}),c=(t=>(t[t.VND=704]="VND",t))(c||{}),l=(t=>(t.VN="VN",t))(l||{});function g(t){let e=65535;for(let n=0;n<t.length;n++){e^=t.charCodeAt(n)<<8;for(let r=0;r<8;r++)e&32768?e=e<<1^4129:e<<=1;e&=65535}return e}function p(t){let i="";for(const[e,n]of Object.entries(t).sort((r,u)=>r[0]>u[0]?1:-1)){const r=typeof n=="string"?n:typeof n=="number"?n.toString():p(n);i+=e+r.length.toString().padStart(2,"0")+r}return i}function N({method:t=o.Static,system:i=f.NAPAS,serviceCode:e=s.AccountTransfer,bin:n,account:r,amount:u,currency:T=c.VND,countryCode:d=l.VN,description:A}){const y={"00":"01","01":t,[i]:{"00":"A000000727","01":{"00":n,"01":r},"02":e},53:T,...u&&{54:u},58:d,...A&&{62:A}},S=p(y)+"6304";return S+g(S).toString(16).toUpperCase().padStart(4,"0")}a.generateValue=N,Object.defineProperty(a,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(n,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(n=typeof globalThis<"u"?globalThis:n||self,o(n.NapasQR={}))})(this,(function(n){"use strict";var o=(t=>(t[t.Static=11]="Static",t[t.Dynamic=12]="Dynamic",t))(o||{}),c=(t=>(t[t.NAPAS=38]="NAPAS",t))(c||{}),u=(t=>(t.Push="QRPUSH",t.Cash="QRCASH",t.CardTransfer="QRIBFTTC",t.AccountTransfer="QRIBFTTA",t))(u||{}),s=(t=>(t[t.VND=704]="VND",t))(s||{}),l=(t=>(t.VN="VN",t))(l||{});function g(t){let e=65535;for(let r=0;r<t.length;r++){e^=t.charCodeAt(r)<<8;for(let a=0;a<8;a++)e&32768?e=e<<1^4129:e<<=1;e&=65535}return e}function A(t){let i="";for(const[e,r]of Object.entries(t).sort((a,f)=>a[0]>f[0]?1:-1)){const a=typeof r=="string"?r:typeof r=="number"?r.toString():A(r);i+=e+a.length.toString().padStart(2,"0")+a}return i}function C({method:t=o.Static,system:i=c.NAPAS,serviceCode:e=u.AccountTransfer,bin:r,account:a,amount:f,currency:N=s.VND,countryCode:T=l.VN,purpose:d,bill:S}){const m={"00":"01","01":t,[i]:{"00":"A000000727","01":{"00":r,"01":a},"02":e},53:N,...f&&{54:f},58:T,...(S||d)&&{62:{...S&&{"01":S},...d&&{"08":d}}}},y=A(m)+"6304";return y+g(y).toString(16).toUpperCase().padStart(4,"0")}n.CountryCode=l,n.Currency=s,n.Method=o,n.ServiceCode=u,n.System=c,n.generateCode=C,Object.defineProperty(n,Symbol.toStringTag,{value:"Module"})}));
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export declare function calculateCRC(data: string): number;
2
- export interface QRData {
2
+ interface QRData {
3
3
  [id: string]: number | string | this;
4
4
  }
5
5
  export declare function formatData(data: QRData): string;
6
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vn-contrib/napas-qr",
3
- "version": "0.0.0",
3
+ "version": "1.0.1",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist"
@@ -16,6 +16,7 @@
16
16
  "devDependencies": {
17
17
  "@types/react": "^19.2.7",
18
18
  "@types/react-dom": "^19.2.3",
19
+ "@vitejs/plugin-react": "^5.1.2",
19
20
  "@vitest/coverage-v8": "^4.0.16",
20
21
  "qrcode.react": "^4.2.0",
21
22
  "react": "^19.2.3",
@@ -25,9 +26,23 @@
25
26
  "vite-plugin-dts": "^4.5.4",
26
27
  "vitest": "^4.0.16"
27
28
  },
29
+ "homepage": "https://vn-contrib.github.io/napas-qr/",
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "https://github.com/vn-contrib/napas-qr.git"
33
+ },
34
+ "license": "MIT",
35
+ "keywords": [
36
+ "napas",
37
+ "qrcode",
38
+ "vietqr"
39
+ ],
28
40
  "scripts": {
29
41
  "dev": "vite",
30
- "build": "vite build",
31
- "test": "vitest"
42
+ "build": "pnpm run /^build:.*/",
43
+ "build:lib": "vite build",
44
+ "build:pages": "vite build --config vite.config.pages.ts",
45
+ "test": "vitest",
46
+ "preview": "vite preview --outDir pages"
32
47
  }
33
48
  }
package/dist/vite.svg DELETED
@@ -1 +0,0 @@
1
- <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>