BlueGit

timfa posprint

Files

posprint / lib / node / posprint_url.js

posprint_url.js

posprint_url.js 718 B Download Raw
1'use strict';
2
3const zlib = require('zlib');
4
5/**
6 * Build a posprint:// URL from a .pos document (object or JSON string).
7 *
8 * Encoding: UTF-8 JSON → raw deflate → base64url (no padding).
9 *
10 * @param {object|string} pos
11 * @param {{ noconfirm?: boolean }} [options]
12 * @returns {string}
13 */
14function posprintUrl(pos, options = {}) {
15 const json = typeof pos === 'string' ? pos : JSON.stringify(pos);
16 const compressed = zlib.deflateRawSync(Buffer.from(json, 'utf8'), { level: 9 });
17 const b64 = compressed.toString('base64url');
18 let url = `posprint://print?v=1&d=${b64}`;
19 if (options.noconfirm) {
20 url += '&noconfirm=1';
21 }
22 return url;
23}
24
25module.exports = { posprintUrl };