@vn-contrib/napas-qr 0.0.0 → 1.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 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;
@@ -10,5 +11,4 @@ interface NapasQRProps {
10
11
  countryCode?: string;
11
12
  description?: string;
12
13
  }
13
- export declare function generateValue({ method, system, serviceCode, bin, account, amount, currency, countryCode, description }: NapasQRProps): string;
14
- export {};
14
+ export declare function generateCode({ method, system, serviceCode, bin, account, amount, currency, countryCode, description }: NapasQRProps): string;
package/dist/main.js CHANGED
@@ -1,4 +1,4 @@
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 || {});
1
+ var u = /* @__PURE__ */ ((t) => (t[t.Static = 11] = "Static", t[t.Dynamic = 12] = "Dynamic", t))(u || {}), l = /* @__PURE__ */ ((t) => (t[t.NAPAS = 38] = "NAPAS", t))(l || {}), 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
2
  function T(t) {
3
3
  let r = 65535;
4
4
  for (let n = 0; n < t.length; n++) {
@@ -17,9 +17,9 @@ function N(t) {
17
17
  }
18
18
  return e;
19
19
  }
20
- function V({
21
- method: t = l.Static,
22
- system: e = s.NAPAS,
20
+ function D({
21
+ method: t = u.Static,
22
+ system: e = l.NAPAS,
23
23
  serviceCode: r = f.AccountTransfer,
24
24
  bin: n,
25
25
  account: a,
@@ -56,9 +56,14 @@ function V({
56
56
  ...c && {
57
57
  62: c
58
58
  }
59
- }, u = N(g) + "6304";
60
- return u + T(u).toString(16).toUpperCase().padStart(4, "0");
59
+ }, s = N(g) + "6304";
60
+ return s + T(s).toString(16).toUpperCase().padStart(4, "0");
61
61
  }
62
62
  export {
63
- V as generateValue
63
+ A as CountryCode,
64
+ i as Currency,
65
+ u as Method,
66
+ f as ServiceCode,
67
+ l as System,
68
+ D as generateCode
64
69
  };
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(e,o){typeof exports=="object"&&typeof module<"u"?o(exports):typeof define=="function"&&define.amd?define(["exports"],o):(e=typeof globalThis<"u"?globalThis:e||self,o(e.NapasQR={}))})(this,(function(e){"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||{}),c=(t=>(t.Push="QRPUSH",t.Cash="QRCASH",t.CardTransfer="QRIBFTTC",t.AccountTransfer="QRIBFTTA",t))(c||{}),s=(t=>(t[t.VND=704]="VND",t))(s||{}),l=(t=>(t.VN="VN",t))(l||{});function y(t){let n=65535;for(let r=0;r<t.length;r++){n^=t.charCodeAt(r)<<8;for(let a=0;a<8;a++)n&32768?n=n<<1^4129:n<<=1;n&=65535}return n}function d(t){let i="";for(const[n,r]of Object.entries(t).sort((a,u)=>a[0]>u[0]?1:-1)){const a=typeof r=="string"?r:typeof r=="number"?r.toString():d(r);i+=n+a.length.toString().padStart(2,"0")+a}return i}function g({method:t=o.Static,system:i=f.NAPAS,serviceCode:n=c.AccountTransfer,bin:r,account:a,amount:u,currency:p=s.VND,countryCode:C=l.VN,description:S}){const N={"00":"01","01":t,[i]:{"00":"A000000727","01":{"00":r,"01":a},"02":n},53:p,...u&&{54:u},58:C,...S&&{62:S}},A=d(N)+"6304";return A+y(A).toString(16).toUpperCase().padStart(4,"0")}e.CountryCode=l,e.Currency=s,e.Method=o,e.ServiceCode=c,e.System=f,e.generateCode=g,Object.defineProperty(e,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.0",
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",
@@ -27,7 +28,10 @@
27
28
  },
28
29
  "scripts": {
29
30
  "dev": "vite",
30
- "build": "vite build",
31
- "test": "vitest"
31
+ "build": "pnpm run /^build:.*/",
32
+ "build:lib": "vite build",
33
+ "build:pages": "vite build --config vite.config.pages.ts",
34
+ "test": "vitest",
35
+ "preview": "vite preview --outDir pages"
32
36
  }
33
37
  }