{"_id":"@bytarch/qrcode","_rev":"1-8666f75dc993a3c4abf1f10d4e6ce4b3","name":"@bytarch/qrcode","dist-tags":{"latest":"1.0.2"},"versions":{"1.0.0":{"name":"@bytarch/qrcode","version":"1.0.0","keywords":["qrcode","javascript","qr","png","data-url","buffer"],"author":{"name":"bytarch"},"license":"MIT","_id":"@bytarch/qrcode@1.0.0","maintainers":[{"name":"bytarch","email":"bytarchbit@gmail.com"}],"homepage":"https://github.com/bytarch/qrcode#readme","bugs":{"url":"https://github.com/bytarch/qrcode/issues"},"dist":{"shasum":"175f1d03604c94e219a9b6197eeb4d07672f270f","tarball":"https://registry.npmjs.org/@bytarch/qrcode/-/qrcode-1.0.0.tgz","fileCount":5,"integrity":"sha512-aaGZASDNOJ0sb7aPk8XLKyrcLlyyYRN28EM0lJ+p3uWYjVPi5KitFe+geYomZaoWxHHKOjFY6Gyx4D6rTM8Jzw==","signatures":[{"sig":"MEQCIHPuzUCtaAoc/rI0hO3O79cGIqg0/Lm7EK9SVX17bKkrAiA8F9f2uJ5Zvv/HhARA1dGcmjg0xpKj7h32/F7q8Wpg/Q==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":8710},"main":"lib/index.js","scripts":{"test":"node tests/run.js"},"_npmUser":{"name":"bytarch","email":"bytarchbit@gmail.com"},"repository":{"url":"git+https://github.com/bytarch/qrcode.git","type":"git"},"_npmVersion":"10.8.2","description":"A simple JavaScript package to generate QR codes that can output PNG files, Data URLs, and Buffers.","directories":{},"_nodeVersion":"20.18.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/qrcode_1.0.0_1729263708473_0.5790337888763755","host":"s3://npm-registry-packages"}},"1.0.2":{"name":"@bytarch/qrcode","version":"1.0.2","description":"A simple JavaScript package to generate QR codes that can output PNG files, Data URLs, and Buffers.","main":"lib/index.js","scripts":{"test":"node tests/run.js"},"repository":{"type":"git","url":"git+https://github.com/bytarch/qrcode.git"},"keywords":["qrcode","javascript","qr","png","data-url","buffer"],"author":{"name":"bytarch"},"license":"MIT","bugs":{"url":"https://github.com/bytarch/qrcode/issues"},"homepage":"https://github.com/bytarch/qrcode#readme","dependencies":{"qrcode":"^1.5.4"},"_id":"@bytarch/qrcode@1.0.2","_nodeVersion":"20.18.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-Y2EdU9RxOPfhApBOp59n+axxTj1i84BcUmGNmsdc7kLAdE+1Slv17BVYJrBwpl+Qf15z/nbB34nTASvcRwHVhw==","shasum":"601713b0c0733e165d94d53e4dfea787f2776e17","tarball":"https://registry.npmjs.org/@bytarch/qrcode/-/qrcode-1.0.2.tgz","fileCount":5,"unpackedSize":8519,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDgf31vi5RXoyUIs6q8to/Y+RJRQswNTpLWHqSkX20fDQIhALTxuJL8L000pRy+6+xKoH5Qi+axJBpLh5Ec7xH8wrS8"}]},"_npmUser":{"name":"bytarch","email":"bytarchbit@gmail.com"},"directories":{},"maintainers":[{"name":"bytarch","email":"bytarchbit@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/qrcode_1.0.2_1729268351651_0.10448528999004747"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-18T15:01:48.384Z","modified":"2024-10-18T16:19:12.051Z","1.0.0":"2024-10-18T15:01:48.678Z","1.0.2":"2024-10-18T16:19:11.864Z"},"bugs":{"url":"https://github.com/bytarch/qrcode/issues"},"author":{"name":"bytarch"},"license":"MIT","homepage":"https://github.com/bytarch/qrcode#readme","keywords":["qrcode","javascript","qr","png","data-url","buffer"],"repository":{"type":"git","url":"git+https://github.com/bytarch/qrcode.git"},"description":"A simple JavaScript package to generate QR codes that can output PNG files, Data URLs, and Buffers.","maintainers":[{"name":"bytarch","email":"bytarchbit@gmail.com"}],"readme":"\r\n# QR Code Generator\r\n\r\nA simple JavaScript package to generate QR codes that can output PNG files, Data URLs, and Buffers.\r\n\r\n## Installation\r\n\r\nYou can install the package using npm:\r\n\r\n```bash\r\nnpm install @bytarch/qrcode\r\n```\r\n\r\n## Code\r\n\r\n```javascript\r\nconst { QRCreation, QR64, QRBuffer } = require('@bytarch/qrcode'); // Use .js extension\r\n\r\n// Generate a QR code and save it as a PNG file\r\nQRCreation('HELLO WORLD', 'generated_code.png'); // Added .png extension to the filename\r\n\r\n// Generate a QR code as a data URL\r\nQR64('HELLO WORLD')\r\n    .then(url => {\r\n        console.log('QR Code Data URL:', url);\r\n    })\r\n    .catch(err => {\r\n        console.error('Error generating QR Code Data URL:', err);\r\n    }); // Added error handling\r\n\r\n// Generate a QR code as a buffer\r\nQRBuffer('HELLO WORLD')\r\n    .then(buffer => {\r\n        if (buffer) { // Check if buffer is defined\r\n            // Save the buffer as a file (this part is removed)\r\n            console.log('QR Code buffer generated but not saved.');\r\n        } else {\r\n            console.error('No buffer returned for QR Code');\r\n        }\r\n    })\r\n    .catch(err => {\r\n        console.error('Error generating QR Code Buffer:', err);\r\n    }); // Added error handling\r\n\r\n```\r\n\r\n## Usage\r\n\r\n### 1. Importing the Package\r\n\r\nTo use the QR code generator, require it in your JavaScript file:\r\n\r\n```javascript\r\nconst { QRCreation, QR64, QRBuffer } = require('@bytarch/qrcode');\r\n```\r\n\r\n### 2. Generating a QR Code\r\n\r\n#### A. Save QR Code as PNG\r\n\r\nTo generate and save a QR code as a PNG file, use the `QRCreation` function:\r\n\r\n```javascript\r\nQRCreation(text, [filename='qrcode.png'], [options={}]);\r\n```\r\n\r\n- **Parameters:**\r\n  - `text` (string): The text to encode in the QR code.\r\n  - `filename` (string, optional): The name of the output file (defaults to `'qrcode.png'`).\r\n  - `options` (object, optional): Optional QR code generation settings.\r\n\r\n- **Example:**\r\n\r\n```javascript\r\nconst text = 'https://bytarch.netlify.app!';\r\nQRCreation(text, 'bytarch-qr.png');\r\n```\r\n\r\n#### B. Generate QR Code as a Data URL\r\n\r\nTo generate a QR code as a Data URL (suitable for embedding in HTML or displaying as an image), use the `QR64` function:\r\n\r\n```javascript\r\nQR64(text, [options={}]);\r\n```\r\n\r\n- **Parameters:**\r\n  - `text` (string): The text to encode in the QR code.\r\n  - `options` (object, optional): Optional QR code generation settings.\r\n\r\n- **Returns:** A Promise that resolves to a string containing the Data URL of the generated QR code.\r\n\r\n- **Example:**\r\n\r\n```javascript\r\nconst dataUrl = await QR64('https://bytarch.netlify.app!');\r\nconsole.log(dataUrl); // Outputs the Data URL of the QR code\r\n```\r\n\r\n#### C. Generate QR Code as a Buffer\r\n\r\nTo generate a QR code as a Buffer (for file writing or other manipulation), use the `QRBuffer` function:\r\n\r\n```javascript\r\nQRBuffer(text, [options={}]);\r\n```\r\n\r\n- **Parameters:**\r\n  - `text` (string): The text to encode in the QR code.\r\n  - `options` (object, optional): Optional QR code generation settings.\r\n\r\n- **Returns:** A Promise that resolves to a Buffer containing the generated QR code image.\r\n\r\n- **Example:**\r\n\r\n```javascript\r\nconst buffer = await QRBuffer('https://bytarch.netlify.app!');\r\n// You can now manipulate the buffer, save it to a file, etc.\r\n```\r\n\r\n## Helper Functions\r\n\r\n### 1. ensurePngExtension\r\n\r\nEnsures that the provided filename has a `.png` extension. This function is used internally in the `QRCreation` function.\r\n\r\n```javascript\r\nconst ensurePngExtension = (filename) => filename.endsWith('.png') ? filename : `${filename}.png`;\r\n```\r\n\r\n- **Parameters:**\r\n  - `filename` (string): The filename to check.\r\n\r\n- **Returns:** The filename with a `.png` extension if necessary.\r\n\r\n## Error Handling\r\n\r\nEach function includes basic error handling that logs any errors encountered during QR code generation to the console. You can further enhance error handling as needed in your application.\r\n\r\n## Example\r\n\r\nHere’s an example of generating a QR code and saving it as a PNG file:\r\n\r\n```javascript\r\nconst { QRCreation } = require('@bytarch/qrcode');\r\n\r\nconst text = 'Visit bytarch!';\r\nQRCreation(text, 'bytarch-qr.png');\r\n```\r\n\r\nThis will create a QR code that encodes the text \"Visit bytarch!\" and saves it as `bytarch-qr.png`.\r\n\r\n\r\n\r\n## GitHub Repository\r\n\r\nYou can find the source code for this package on GitHub:\r\n\r\n[GitHub - QR Code Generator](https://github.com/bytarch/qrcode)\r\n\r\nFeel free to contribute or raise issues on the repository.\r\n","readmeFilename":"README.md"}