New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

niimbotjs

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

niimbotjs - npm Package Compare versions

Comparing version 0.3.0 to 0.3.1

5

dist/bin.js

@@ -21,6 +21,3 @@ #!/usr/bin/env node

.name('niimbot')
.description('Printer client for Niimbot printers over USB');
program
.command('print')
.description('Prints an image')
.description('Printer client for Niimbot printers over USB')
.argument('<image>', 'path of the image to print')

@@ -27,0 +24,0 @@ .addOption(new Option('-m, --model <model>', 'niimbot model')

11

dist/lib/printer.d.ts
/// <reference types="node" resolution-mode="require"/>
import sharp from 'sharp';
import { Packet } from './packet.js';
import { SerialTransport } from './serial.js';
export declare enum InfoCode {

@@ -38,9 +37,9 @@ DENSITY = 1,

export declare class PrinterClient {
_packetBuffer: Buffer | null;
_serial: SerialTransport;
private packetBuffer;
private serial;
open: (path?: string) => Promise<void>;
close: () => void;
_sendPacket: (type: number, data?: Buffer | number[], responseOffset?: number) => Promise<Packet>;
_receivePacket: (responseCode: number) => Promise<Packet>;
_processChunk: () => Packet[];
private sendPacket;
private receivePacket;
private processChunk;
print: (sharpImage: sharp.Sharp, { density }: {

@@ -47,0 +46,0 @@ density: number;

@@ -55,11 +55,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

constructor() {
this._packetBuffer = null;
this._serial = new SerialTransport();
this.packetBuffer = null;
this.serial = new SerialTransport();
this.open = (path) => {
return this._serial.open(path);
return this.serial.open(path);
};
this.close = () => {
this._serial.close();
this.serial.close();
};
this._sendPacket = (type_1, ...args_1) => __awaiter(this, [type_1, ...args_1], void 0, function* (type, data = [1], responseOffset = 1) {
this.sendPacket = (type_1, ...args_1) => __awaiter(this, [type_1, ...args_1], void 0, function* (type, data = [1], responseOffset = 1) {
debugLog('Writing packet!', type, data);

@@ -69,4 +69,4 @@ const buffer = data instanceof Buffer ? data : Buffer.from(data);

const responseCode = type + responseOffset;
yield this._serial.write(packet.toBytes());
const response = yield this._receivePacket(responseCode);
yield this.serial.write(packet.toBytes());
const response = yield this.receivePacket(responseCode);
if (response) {

@@ -79,5 +79,5 @@ return response;

});
this._receivePacket = (responseCode) => __awaiter(this, void 0, void 0, function* () {
this.receivePacket = (responseCode) => __awaiter(this, void 0, void 0, function* () {
for (let i = 0; i < PACKET_READ_COUNT; i++) {
const packets = this._processChunk();
const packets = this.processChunk();
for (let j = 0; j < packets.length; j++) {

@@ -105,22 +105,22 @@ const packet = packets[j];

});
this._processChunk = () => {
this.processChunk = () => {
const packets = [];
const chunk = this._serial.read();
const chunk = this.serial.read();
if (!chunk)
return packets;
debugLog('Received data!', chunk);
if (this._packetBuffer) {
if (this.packetBuffer) {
// Add the new data to the buffer
this._packetBuffer = Buffer.concat([this._packetBuffer, chunk]);
this.packetBuffer = Buffer.concat([this.packetBuffer, chunk]);
}
else {
this._packetBuffer = Buffer.concat([chunk]);
this.packetBuffer = Buffer.concat([chunk]);
}
while (this._packetBuffer.length > 4) {
const packetLength = this._packetBuffer[3] + 7;
if (this._packetBuffer.length >= packetLength) {
const packet = Packet.fromBytes(this._packetBuffer.subarray(0, packetLength));
while (this.packetBuffer.length > 4) {
const packetLength = this.packetBuffer[3] + 7;
if (this.packetBuffer.length >= packetLength) {
const packet = Packet.fromBytes(this.packetBuffer.subarray(0, packetLength));
debugLog('Received packet!', packet.type, packet.data);
packets.push(packet);
this._packetBuffer = this._packetBuffer.subarray(packetLength);
this.packetBuffer = this.packetBuffer.subarray(packetLength);
}

@@ -140,3 +140,3 @@ }

for (let i = 0; i < imageData.length; i++) {
yield this._serial.write(imageData[i]);
yield this.serial.write(imageData[i]);
}

@@ -157,3 +157,3 @@ // Wait for all data to be transmitted

this.getPrintStatus = () => __awaiter(this, void 0, void 0, function* () {
const { data } = yield this._sendPacket(RequestCode.GET_PRINT_STATUS, [1], 16);
const { data } = yield this.sendPacket(RequestCode.GET_PRINT_STATUS, [1], 16);
// >HBB

@@ -166,3 +166,3 @@ const page = data.readUInt16BE(0);

this.getInfo = (key) => __awaiter(this, void 0, void 0, function* () {
const { data } = yield this._sendPacket(RequestCode.GET_INFO, [key], key);
const { data } = yield this.sendPacket(RequestCode.GET_INFO, [key], key);
switch (key) {

@@ -194,3 +194,3 @@ case InfoCode.DEVICE_SERIAL: {

};
const { data } = yield this._sendPacket(RequestCode.GET_HEART_BEAT, [variant], offsets[variant]);
const { data } = yield this.sendPacket(RequestCode.GET_HEART_BEAT, [variant], offsets[variant]);
let doorOpen = null;

@@ -213,3 +213,3 @@ let hasPaper = null;

this.getRFID = () => __awaiter(this, void 0, void 0, function* () {
const { data } = yield this._sendPacket(RequestCode.GET_RFID);
const { data } = yield this.sendPacket(RequestCode.GET_RFID);
if (data[0] == 0)

@@ -243,19 +243,19 @@ return null;

assert(type >= 1 && type <= 3);
return this._sendPacket(RequestCode.SET_LABEL_TYPE, [type], 16);
return this.sendPacket(RequestCode.SET_LABEL_TYPE, [type], 16);
};
this.setLabelDensity = (density) => {
assert(density >= 1 && density <= 5, `Invalid density range; expected 1 - 5 but got ${density}`);
return this._sendPacket(RequestCode.SET_LABEL_DENSITY, [density], 16);
return this.sendPacket(RequestCode.SET_LABEL_DENSITY, [density], 16);
};
this.startPrint = () => {
return this._sendPacket(RequestCode.START_PRINT);
return this.sendPacket(RequestCode.START_PRINT);
};
this.endPrint = () => {
return this._sendPacket(RequestCode.END_PRINT);
return this.sendPacket(RequestCode.END_PRINT);
};
this.startPagePrint = () => {
return this._sendPacket(RequestCode.START_PAGE_PRINT);
return this.sendPacket(RequestCode.START_PAGE_PRINT);
};
this.endPagePrint = () => {
return this._sendPacket(RequestCode.END_PAGE_PRINT);
return this.sendPacket(RequestCode.END_PAGE_PRINT);
};

@@ -267,14 +267,14 @@ this.setDimensions = (width, height) => {

data.writeUInt16BE(width, 2);
return this._sendPacket(RequestCode.SET_DIMENSION, data);
return this.sendPacket(RequestCode.SET_DIMENSION, data);
};
this.setPowerSound = (enabled) => {
const data = [1, 2, enabled ? 1 : 0];
return this._sendPacket(RequestCode.SET_AUDIO_SETTING, data);
return this.sendPacket(RequestCode.SET_AUDIO_SETTING, data);
};
this.setBluetoothSound = (enabled) => {
const data = [1, 1, enabled ? 1 : 0];
return this._sendPacket(RequestCode.SET_AUDIO_SETTING, data);
return this.sendPacket(RequestCode.SET_AUDIO_SETTING, data);
};
this.calibrateLabel = (label) => {
return this._sendPacket(RequestCode.CALIBRATE_LABEL, [label]);
return this.sendPacket(RequestCode.CALIBRATE_LABEL, [label]);
};

@@ -281,0 +281,0 @@ }

/// <reference types="node" resolution-mode="require"/>
import { SerialPort } from 'serialport';
export type SerialDevice = {

@@ -10,4 +9,4 @@ path?: string;

export declare class SerialTransport {
_port: SerialPort | null;
_handlePortClose: () => void;
private port;
private handlePortClose;
open: (path?: string) => Promise<void>;

@@ -14,0 +13,0 @@ close: () => void;

@@ -20,5 +20,5 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {

constructor() {
this._port = null;
this._handlePortClose = () => {
this._port = null;
this.port = null;
this.handlePortClose = () => {
this.port = null;
};

@@ -43,4 +43,4 @@ this.open = (path) => __awaiter(this, void 0, void 0, function* () {

};
this._port = new SerialPort(portOptions, connectCallback);
this._port.on('close', this._handlePortClose);
this.port = new SerialPort(portOptions, connectCallback);
this.port.on('close', this.handlePortClose);
});

@@ -50,5 +50,5 @@ });

var _a;
if ((_a = this._port) === null || _a === void 0 ? void 0 : _a.isOpen) {
this._port.close();
this._port = null;
if ((_a = this.port) === null || _a === void 0 ? void 0 : _a.isOpen) {
this.port.close();
this.port = null;
}

@@ -58,15 +58,15 @@ };

var _a;
return Boolean((_a = this._port) === null || _a === void 0 ? void 0 : _a.isOpen);
return Boolean((_a = this.port) === null || _a === void 0 ? void 0 : _a.isOpen);
};
this.read = (size) => {
var _a;
assert((_a = this._port) === null || _a === void 0 ? void 0 : _a.isOpen, 'Transport not open');
return this._port.read(size);
assert((_a = this.port) === null || _a === void 0 ? void 0 : _a.isOpen, 'Transport not open');
return this.port.read(size);
};
this.write = (data) => {
var _a;
assert((_a = this._port) === null || _a === void 0 ? void 0 : _a.isOpen, 'Transport not open');
assert((_a = this.port) === null || _a === void 0 ? void 0 : _a.isOpen, 'Transport not open');
debugLog('Writing data!', data);
this._port.write(data);
return promisify(this._port.drain).call(this._port);
this.port.write(data);
return promisify(this.port.drain).call(this.port);
};

@@ -73,0 +73,0 @@ }

{
"name": "niimbotjs",
"version": "0.3.0",
"version": "0.3.1",
"description": "",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc