baharqris 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.
Files changed (3) hide show
  1. package/README.md +20 -0
  2. package/index.js +80 -0
  3. package/package.json +24 -0
package/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # BaharQR
2
+
3
+ A simple CLI tool to generate QR codes directly in your terminal.
4
+
5
+ ## Installation
6
+
7
+ You can run this tool directly using `npx` without installation:
8
+
9
+ ```bash
10
+ npx baharqr
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ This tool generates a QR code from a **hardcoded string**.
16
+
17
+ To change the QR code content:
18
+ 1. Open `index.js`
19
+ 2. Change the `HARDCODED_STRING` variable
20
+ 3. Run `npx baharqr` again
package/index.js ADDED
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { program } = require('commander');
4
+ const qrcode = require('qrcode-terminal');
5
+ const packageJson = require('./package.json');
6
+
7
+ // USER: CHANGE THIS STRING
8
+ const HARDCODED_STRING = "00020101021126570011ID.DANA.WWW011893600915312510577302091251057730303UMI51440014ID.CO.QRIS.WWW0215ID10210671417910303UMI5204737253033605802ID5908Baharsah6014Kab. Tangerang61051581063048DF8";
9
+ // Note: The previous string provided ended with '0215I' which implies tag 02, length 15, but was truncated.
10
+ // I replaced 'I' with a placeholder ID of proper length (15 chars) to make the TLV valid for demonstration.
11
+ // Please update 'ID1234567890123' to your actual Merchant ID.
12
+
13
+ function crc16(str) {
14
+ let crc = 0xFFFF;
15
+ for (let c = 0; c < str.length; c++) {
16
+ crc ^= str.charCodeAt(c) << 8;
17
+ for (let i = 0; i < 8; i++) {
18
+ if (crc & 0x8000) {
19
+ crc = (crc << 1) ^ 0x1021;
20
+ } else {
21
+ crc = crc << 1;
22
+ }
23
+ }
24
+ }
25
+ let hex = (crc & 0xFFFF).toString(16).toUpperCase();
26
+ return hex.padStart(4, '0');
27
+ }
28
+
29
+ function formatQRIS(str) {
30
+ // Check if string needs CRC
31
+ // QRIS ends with "6304" + 4 hex digits.
32
+ // We assume the input provided is the payload WITHOUT the final CRC value,
33
+ // or properly formatted up to "6304".
34
+
35
+ let payload = str;
36
+
37
+ // If it doesn't have the CRC tag 63 at the end, append it
38
+ // Note: This is a naive check. A robust one would parse TLVs.
39
+ // For now, we assume the user provides the raw data blocks.
40
+
41
+ // Check if 6304 exists near end
42
+ if (!payload.includes('6304', payload.length - 8)) {
43
+ payload += '6304';
44
+ } else {
45
+ // If it ends with 6304, we are good to calculate.
46
+ // If it has 6304XXXX, we might want to strip XXXX to recalculate?
47
+ // Let's assume input is "Raw Data" + "6304" (optional)
48
+ if (payload.match(/6304[0-9A-F]{4}$/)) {
49
+ payload = payload.slice(0, -4); // Remove checksum to verify/recalc
50
+ } else if (!payload.endsWith('6304')) {
51
+ // Tag 63 missing completely
52
+ payload += '6304';
53
+ }
54
+ }
55
+
56
+ const checksum = crc16(payload);
57
+ return payload + checksum;
58
+ }
59
+
60
+ program
61
+ .version(packageJson.version)
62
+ .description('Generate a QR code from a hardcoded string')
63
+ .action(() => {
64
+ try {
65
+ console.log('Original String:', HARDCODED_STRING);
66
+
67
+ const distinctQRIS = formatQRIS(HARDCODED_STRING);
68
+ console.log(`\nQRIS with CRC: "${distinctQRIS}"\n`);
69
+
70
+ qrcode.generate(distinctQRIS, { small: true }, (qrcode) => {
71
+ console.log(qrcode);
72
+ });
73
+
74
+ } catch (error) {
75
+ console.error('An error occurred:', error.message);
76
+ process.exit(1);
77
+ }
78
+ });
79
+
80
+ program.parse(process.argv);
package/package.json ADDED
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "baharqris",
3
+ "version": "1.0.0",
4
+ "description": "Bayar QRIS Buat Bahar",
5
+ "main": "index.js",
6
+ "bin": {
7
+ "baharqris": "./index.js"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "keywords": [
13
+ "qr",
14
+ "qrcode",
15
+ "cli",
16
+ "generator"
17
+ ],
18
+ "author": "",
19
+ "license": "ISC",
20
+ "dependencies": {
21
+ "qrcode-terminal": "^0.12.0",
22
+ "commander": "^11.1.0"
23
+ }
24
+ }