Socket
Socket
Sign inDemoInstall

escpos-buffer

Package Overview
Dependencies
3
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 3.1.0 to 4.0.0

.vscode/launch.json

1

dist/connection/index.d.ts
/// <reference types="node" />
export { default as InMemory } from './InMemory';
export { default as WebUSB } from './WebUSB';
export { default as WebBluetooth } from './WebBluetooth';
export interface Connection {

@@ -6,0 +5,0 @@ open(): Promise<void>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WebBluetooth = exports.WebUSB = exports.InMemory = void 0;
exports.WebUSB = exports.InMemory = void 0;
var InMemory_1 = require("./InMemory");

@@ -8,4 +8,2 @@ Object.defineProperty(exports, "InMemory", { enumerable: true, get: function () { return InMemory_1.default; } });

Object.defineProperty(exports, "WebUSB", { enumerable: true, get: function () { return WebUSB_1.default; } });
var WebBluetooth_1 = require("./WebBluetooth");
Object.defineProperty(exports, "WebBluetooth", { enumerable: true, get: function () { return WebBluetooth_1.default; } });
//# sourceMappingURL=index.js.map
{
"name": "escpos-buffer",
"version": "3.1.0",
"version": "4.0.0",
"description": "Library to generate buffer for thermal printers.",

@@ -32,4 +32,2 @@ "author": "GrandChef Team <desenvolvimento@grandchef.com.br>",

"iconv-lite": "^0.6.3",
"pngjs": "^5.0.0",
"qrcode": "^1.5.1",
"tslib": "^2.5.0"

@@ -40,3 +38,2 @@ },

"@types/node": "^12.12.5",
"@types/pngjs": "^6.0.1",
"@types/w3c-web-usb": "1.0.6",

@@ -43,0 +40,0 @@ "@types/web-bluetooth": "^0.0.16",

import { Filter } from '.';
import { PNG } from 'pngjs';
import { ImageData } from '../Image';
export default class BayerOrdered implements Filter {
process(image: PNG): PNG {
process(image: ImageData): ImageData {
const width = image.width;

@@ -31,5 +31,4 @@ const height = image.height;

}
image.data = new_data;
return image;
return { width, height, data: new_data };
}
}
import { Filter } from '.';
import { PNG } from 'pngjs';
import { ImageData } from '../Image';
export default class FloydSteinberg implements Filter {
process(image: PNG): PNG {
process(image: ImageData): ImageData {
const width = image.width;

@@ -51,5 +51,4 @@ const height = image.height;

}
image.data = new_data;
return image;
return { width, height, data: new_data };
}
}

@@ -0,8 +1,9 @@

import { ImageData } from '../Image';
export { default as Threshold } from './Threshold';
export { default as BayerOrdered } from './BayerOrdered';
export { default as FloydSteinberg } from './FloydSteinberg';
import { PNG } from 'pngjs';
export interface Filter {
process(image: PNG): PNG;
process(imageData: ImageData): ImageData;
}
import { Filter } from '.';
import { PNG } from 'pngjs';
import { ImageData } from '../Image';
export default class Threshold implements Filter {
process(image: PNG): PNG {
process(image: ImageData): ImageData {
const width = image.width;

@@ -23,5 +23,4 @@ const height = image.height;

}
image.data = new_data;
return image;
return { width, height, data: new_data };
}
}
import { Filter, FloydSteinberg } from './filter';
import * as fs from 'fs';
import { PNG } from 'pngjs';
export interface ImageData {
readonly data: Buffer;
readonly height: number;
readonly width: number;
}
export default class Image {

@@ -11,33 +15,10 @@ data: Buffer;

constructor(
input: string | Buffer | PNG = null,
filter: Filter = new FloydSteinberg(),
) {
if (input instanceof PNG) {
this.readImage(filter.process(input));
} else if (typeof input === 'string') {
this.loadImage(input, filter);
} else if (input) {
this.loadImageData(input, filter);
}
constructor(imageData: ImageData, filter: Filter = new FloydSteinberg()) {
this.readImage(filter.process(imageData));
}
loadImage(filename: string, filter: Filter): void {
// tslint:disable-next-line: non-literal-fs-path
const data = fs.readFileSync(filename);
this.loadImageData(data, filter);
}
loadImageData(data: Buffer, filter: Filter): void {
const png = PNG.sync.read(data);
const image = filter.process(png);
this.readImage(image);
}
/**
* Load actual image pixels from PNG image.
*
* @param image PNG image
* Load actual image pixels from image data.
*/
private readImage(image: PNG): void {
private readImage(image: ImageData): void {
const width = image.width;

@@ -44,0 +25,0 @@ const img_height = image.height;

@@ -5,5 +5,6 @@ export * from './actions';

export { default as Image } from './graphics/Image';
export * from './graphics/Image';
export { default as Manager } from './graphics/Manager';
export * from './graphics/filter';
export * from './Printer';
export { default as Printer } from './Printer';
export { PNG } from 'pngjs';
import Model from './Model';
import { Connection } from './connection';
import Image from './graphics/Image';
import { StyleConf } from './profile';
import { Cut, Drawer, Align } from './actions';
import { SupportedModel } from './capabilities';
import Image from './graphics/Image';
import Manager from './graphics/Manager';

@@ -87,2 +88,3 @@ export default class Printer {

connection: Connection,
imageManager?: Manager,
): Promise<Printer> {

@@ -97,2 +99,3 @@ let model: Model;

model.profile.connection = connection;
model.profile.imageManager = imageManager;
await model.profile.initialize();

@@ -99,0 +102,0 @@ return new Printer(model);

@@ -5,5 +5,5 @@ import { Connection } from '../connection';

import * as iconv from 'iconv-lite';
import * as QRCode from 'qrcode';
import Image from '../graphics/Image';
import { Threshold } from '../graphics/filter';
import Manager from '../graphics/Manager';

@@ -25,2 +25,3 @@ export type StyleConf = {

protected capabilities: Capability;
public imageManager?: Manager;

@@ -144,4 +145,7 @@ constructor(capabilities: Capability) {

protected async drawQrcode(data: string, size: number): Promise<void> {
const buffer = await QRCode.toBuffer(data, { scale: size });
const image = new Image(buffer, new Threshold());
if (!this.imageManager) {
throw new Error('No image manager to draw qrcode');
}
const imageData = await this.imageManager.buildQrcodeImage(data, size);
const image = new Image(imageData, new Threshold());
return this.draw(image);

@@ -148,0 +152,0 @@ }

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc