react-native-thermal-receipt-printer-image-qr
Advanced tools
Comparing version 0.1.3 to 0.1.4
@@ -1,334 +0,335 @@ | ||
import {NativeEventEmitter} from "react-native"; | ||
import { NativeEventEmitter } from "react-native"; | ||
export interface PrinterOptions { | ||
beep?: boolean; | ||
cut?: boolean; | ||
tailingLine?: boolean; | ||
encoding?: string; | ||
beep?: boolean; | ||
cut?: boolean; | ||
tailingLine?: boolean; | ||
encoding?: string; | ||
} | ||
declare const COMMANDS: { | ||
LF: string; | ||
ESC: string; | ||
FS: string; | ||
GS: string; | ||
US: string; | ||
FF: string; | ||
DLE: string; | ||
DC1: string; | ||
DC4: string; | ||
EOT: string; | ||
NUL: string; | ||
EOL: string; | ||
HORIZONTAL_LINE: { | ||
HR_58MM: string; | ||
HR2_58MM: string; | ||
HR3_58MM: string; | ||
HR_80MM: string; | ||
HR2_80MM: string; | ||
HR3_80MM: string; | ||
}; | ||
FEED_CONTROL_SEQUENCES: { | ||
/** | ||
* Print and line feed | ||
*/ | ||
CTL_LF: string; | ||
/** | ||
* Form feed | ||
*/ | ||
CTL_FF: string; | ||
/** | ||
* Carriage return | ||
*/ | ||
CTL_CR: string; | ||
/** | ||
* Horizontal tab | ||
*/ | ||
CTL_HT: string; | ||
/** | ||
* Vertical tab | ||
*/ | ||
CTL_VT: string; | ||
}; | ||
LINE_SPACING: { | ||
LS_DEFAULT: string; | ||
LS_SET: string; | ||
LS_SET1: string; | ||
}; | ||
HARDWARE: { | ||
/** | ||
* Clear data in buffer and reset modes | ||
*/ | ||
HW_INIT: string; | ||
/** | ||
* Printer select | ||
*/ | ||
HW_SELECT: string; | ||
/** | ||
* Reset printer hardware | ||
*/ | ||
HW_RESET: string; | ||
}; | ||
CASH_DRAWER: { | ||
/** | ||
* Sends a pulse to pin 2 [] | ||
*/ | ||
CD_KICK_2: string; | ||
/** | ||
* ends a pulse to pin 5 [] | ||
*/ | ||
CD_KICK_5: string; | ||
}; | ||
MARGINS: { | ||
/** | ||
* Fix bottom size | ||
*/ | ||
BOTTOM: string; | ||
/** | ||
* Fix left size | ||
*/ | ||
LEFT: string; | ||
/** | ||
* Fix right size | ||
*/ | ||
RIGHT: string; | ||
}; | ||
PAPER: { | ||
/** | ||
* Full cut paper | ||
*/ | ||
PAPER_FULL_CUT: string; | ||
/** | ||
* Partial cut paper | ||
*/ | ||
PAPER_PART_CUT: string; | ||
/** | ||
* Partial cut paper | ||
*/ | ||
PAPER_CUT_A: string; | ||
/** | ||
* Partial cut paper | ||
*/ | ||
PAPER_CUT_B: string; | ||
}; | ||
TEXT_FORMAT: { | ||
/** | ||
* Normal text | ||
*/ | ||
TXT_NORMAL: string; | ||
/** | ||
* Double height text | ||
*/ | ||
TXT_2HEIGHT: string; | ||
/** | ||
* Double width text | ||
*/ | ||
TXT_2WIDTH: string; | ||
/** | ||
* Double width & height text | ||
*/ | ||
TXT_4SQUARE: string; | ||
/** | ||
* other sizes | ||
*/ | ||
TXT_CUSTOM_SIZE: (width: number, height: number) => string; | ||
TXT_HEIGHT: { | ||
1: string; | ||
2: string; | ||
3: string; | ||
4: string; | ||
5: string; | ||
6: string; | ||
7: string; | ||
8: string; | ||
LF: string; | ||
ESC: string; | ||
FS: string; | ||
GS: string; | ||
US: string; | ||
FF: string; | ||
DLE: string; | ||
DC1: string; | ||
DC4: string; | ||
EOT: string; | ||
NUL: string; | ||
EOL: string; | ||
HORIZONTAL_LINE: { | ||
HR_58MM: string; | ||
HR2_58MM: string; | ||
HR3_58MM: string; | ||
HR_80MM: string; | ||
HR2_80MM: string; | ||
HR3_80MM: string; | ||
}; | ||
TXT_WIDTH: { | ||
1: string; | ||
2: string; | ||
3: string; | ||
4: string; | ||
5: string; | ||
6: string; | ||
7: string; | ||
8: string; | ||
FEED_CONTROL_SEQUENCES: { | ||
/** | ||
* Print and line feed | ||
*/ | ||
CTL_LF: string; | ||
/** | ||
* Form feed | ||
*/ | ||
CTL_FF: string; | ||
/** | ||
* Carriage return | ||
*/ | ||
CTL_CR: string; | ||
/** | ||
* Horizontal tab | ||
*/ | ||
CTL_HT: string; | ||
/** | ||
* Vertical tab | ||
*/ | ||
CTL_VT: string; | ||
}; | ||
LINE_SPACING: { | ||
LS_DEFAULT: string; | ||
LS_SET: string; | ||
LS_SET1: string; | ||
}; | ||
HARDWARE: { | ||
/** | ||
* Clear data in buffer and reset modes | ||
*/ | ||
HW_INIT: string; | ||
/** | ||
* Printer select | ||
*/ | ||
HW_SELECT: string; | ||
/** | ||
* Reset printer hardware | ||
*/ | ||
HW_RESET: string; | ||
}; | ||
CASH_DRAWER: { | ||
/** | ||
* Sends a pulse to pin 2 [] | ||
*/ | ||
CD_KICK_2: string; | ||
/** | ||
* ends a pulse to pin 5 [] | ||
*/ | ||
CD_KICK_5: string; | ||
}; | ||
MARGINS: { | ||
/** | ||
* Fix bottom size | ||
*/ | ||
BOTTOM: string; | ||
/** | ||
* Fix left size | ||
*/ | ||
LEFT: string; | ||
/** | ||
* Fix right size | ||
*/ | ||
RIGHT: string; | ||
}; | ||
PAPER: { | ||
/** | ||
* Full cut paper | ||
*/ | ||
PAPER_FULL_CUT: string; | ||
/** | ||
* Partial cut paper | ||
*/ | ||
PAPER_PART_CUT: string; | ||
/** | ||
* Partial cut paper | ||
*/ | ||
PAPER_CUT_A: string; | ||
/** | ||
* Partial cut paper | ||
*/ | ||
PAPER_CUT_B: string; | ||
}; | ||
TEXT_FORMAT: { | ||
/** | ||
* Normal text | ||
*/ | ||
TXT_NORMAL: string; | ||
/** | ||
* Double height text | ||
*/ | ||
TXT_2HEIGHT: string; | ||
/** | ||
* Double width text | ||
*/ | ||
TXT_2WIDTH: string; | ||
/** | ||
* Double width & height text | ||
*/ | ||
TXT_4SQUARE: string; | ||
/** | ||
* other sizes | ||
*/ | ||
TXT_CUSTOM_SIZE: (width: number, height: number) => string; | ||
TXT_HEIGHT: { | ||
1: string; | ||
2: string; | ||
3: string; | ||
4: string; | ||
5: string; | ||
6: string; | ||
7: string; | ||
8: string; | ||
}; | ||
TXT_WIDTH: { | ||
1: string; | ||
2: string; | ||
3: string; | ||
4: string; | ||
5: string; | ||
6: string; | ||
7: string; | ||
8: string; | ||
}; | ||
/** | ||
* Underline font OFF | ||
*/ | ||
TXT_UNDERL_OFF: string; | ||
/** | ||
* Underline font 1-dot ON | ||
*/ | ||
TXT_UNDERL_ON: string; | ||
/** | ||
* Underline font 2-dot ON | ||
*/ | ||
TXT_UNDERL2_ON: string; | ||
/** | ||
* Bold font OFF | ||
*/ | ||
TXT_BOLD_OFF: string; | ||
/** | ||
* Bold font ON | ||
*/ | ||
TXT_BOLD_ON: string; | ||
/** | ||
* Italic font ON | ||
*/ | ||
TXT_ITALIC_OFF: string; | ||
/** | ||
* Italic font ON | ||
*/ | ||
TXT_ITALIC_ON: string; | ||
/** | ||
* Font type A | ||
*/ | ||
TXT_FONT_A: string; | ||
/** | ||
* Font type B | ||
*/ | ||
TXT_FONT_B: string; | ||
/** | ||
* Font type C | ||
*/ | ||
TXT_FONT_C: string; | ||
/** | ||
* Left justification | ||
*/ | ||
TXT_ALIGN_LT: string; | ||
/** | ||
* Centering | ||
*/ | ||
TXT_ALIGN_CT: string; | ||
/** | ||
* Right justification | ||
*/ | ||
TXT_ALIGN_RT: string; | ||
}; | ||
}; | ||
export interface PrinterImageOptions { | ||
beep?: boolean; | ||
cut?: boolean; | ||
tailingLine?: boolean; | ||
encoding?: string; | ||
/** | ||
* Underline font OFF | ||
* ios only | ||
*/ | ||
TXT_UNDERL_OFF: string; | ||
imageWidth?: number; | ||
paddingX?: number; | ||
} | ||
export interface IUSBPrinter { | ||
device_name: string; | ||
vendor_id: string; | ||
product_id: string; | ||
} | ||
export interface IBLEPrinter { | ||
device_name: string; | ||
inner_mac_address: string; | ||
} | ||
export interface INetPrinter { | ||
device_name: string; | ||
host: string; | ||
port: number; | ||
} | ||
export declare enum ColumnAliment { | ||
LEFT = 0, | ||
CENTER = 1, | ||
RIGHT = 2 | ||
} | ||
export declare const USBPrinter: { | ||
init: () => Promise<void>; | ||
getDeviceList: () => Promise<IUSBPrinter[]>; | ||
connectPrinter: (vendorId: string, productId: string) => Promise<IUSBPrinter>; | ||
closeConn: () => Promise<void>; | ||
printText: (text: string, opts?: PrinterOptions) => void; | ||
printBill: (text: string, opts?: PrinterOptions) => void; | ||
/** | ||
* Underline font 1-dot ON | ||
* image url | ||
* @param imgUrl | ||
* @param opts | ||
*/ | ||
TXT_UNDERL_ON: string; | ||
printImage: (imgUrl: string, opts?: PrinterImageOptions) => void; | ||
/** | ||
* Underline font 2-dot ON | ||
* base64string, except -> data:image/png;base64, | ||
* @param qrCodeBase64 | ||
* @param opts | ||
*/ | ||
TXT_UNDERL2_ON: string; | ||
printQrCode: (qrCodeBase64: string, opts?: PrinterImageOptions) => void; | ||
/** | ||
* Bold font OFF | ||
* android print with encoder | ||
* @param text | ||
*/ | ||
TXT_BOLD_OFF: string; | ||
printRaw: (text: string) => void; | ||
/** | ||
* Bold font ON | ||
* `columnWidth` | ||
* 80mm => 46 character | ||
* 58mm => 30 character | ||
*/ | ||
TXT_BOLD_ON: string; | ||
printColumnsText: (texts: string[], columnWidth: number[], columnAliment: (ColumnAliment)[], columnStyle: string[], opts?: PrinterOptions) => void; | ||
}; | ||
export declare const BLEPrinter: { | ||
init: () => Promise<void>; | ||
getDeviceList: () => Promise<IBLEPrinter[]>; | ||
connectPrinter: (inner_mac_address: string) => Promise<IBLEPrinter>; | ||
closeConn: () => Promise<void>; | ||
printText: (text: string, opts?: PrinterOptions) => void; | ||
printBill: (text: string, opts?: PrinterOptions) => void; | ||
/** | ||
* Italic font ON | ||
* image url | ||
* @param imgUrl | ||
* @param opts | ||
*/ | ||
TXT_ITALIC_OFF: string; | ||
printImage: (imgUrl: string, opts?: PrinterImageOptions) => void; | ||
/** | ||
* Italic font ON | ||
* base64string, except -> data:image/png;base64, | ||
* @param qrCodeBase64 | ||
* @param opts | ||
*/ | ||
TXT_ITALIC_ON: string; | ||
printQrCode: (qrCodeBase64: string, opts?: PrinterImageOptions) => void; | ||
/** | ||
* Font type A | ||
* android print with encoder | ||
* @param text | ||
*/ | ||
TXT_FONT_A: string; | ||
printRaw: (text: string) => void; | ||
/** | ||
* Font type B | ||
* `columnWidth` | ||
* 80mm => 46 character | ||
* 58mm => 30 character | ||
*/ | ||
TXT_FONT_B: string; | ||
printColumnsText: (texts: string[], columnWidth: number[], columnAliment: (ColumnAliment)[], columnStyle: string[], opts?: PrinterOptions) => void; | ||
}; | ||
export declare const NetPrinter: { | ||
init: () => Promise<void>; | ||
getDeviceList: () => Promise<INetPrinter[]>; | ||
connectPrinter: (host: string, port: number) => Promise<INetPrinter>; | ||
closeConn: () => Promise<void>; | ||
printText: (text: string, opts?: {}) => void; | ||
printBill: (text: string, opts?: PrinterOptions) => void; | ||
/** | ||
* Font type C | ||
* image url | ||
* @param imgUrl | ||
* @param opts | ||
*/ | ||
TXT_FONT_C: string; | ||
printImage: (imgUrl: string, opts?: PrinterImageOptions) => void; | ||
/** | ||
* Left justification | ||
* base64string, except -> data:image/png;base64, | ||
* @param qrCodeBase64 | ||
* @param opts | ||
*/ | ||
TXT_ALIGN_LT: string; | ||
printQrCode: (qrCodeBase64: string, opts?: PrinterImageOptions) => void; | ||
/** | ||
* Centering | ||
* Android print with encoder | ||
* @param text | ||
*/ | ||
TXT_ALIGN_CT: string; | ||
printRaw: (text: string) => void; | ||
/** | ||
* Right justification | ||
* `columnWidth` | ||
* 80mm => 46 character | ||
* 58mm => 30 character | ||
*/ | ||
TXT_ALIGN_RT: string; | ||
}; | ||
printColumnsText: (texts: string[], columnWidth: number[], columnAliment: (ColumnAliment)[], columnStyle?: string[], opts?: PrinterOptions) => void; | ||
}; | ||
export interface PrinterImageOptions { | ||
beep?: boolean; | ||
cut?: boolean; | ||
tailingLine?: boolean; | ||
encoding?: string; | ||
/** | ||
* ios only | ||
*/ | ||
imageWidth?: number; | ||
paddingX?: number; | ||
} | ||
export interface IUSBPrinter { | ||
device_name: string; | ||
vendor_id: string; | ||
product_id: string; | ||
} | ||
export interface IBLEPrinter { | ||
device_name: string; | ||
inner_mac_address: string; | ||
} | ||
export interface INetPrinter { | ||
device_name: string; | ||
host: string; | ||
port: number; | ||
} | ||
export declare enum ColumnAliment { | ||
LEFT = 0, | ||
CENTER = 1, | ||
RIGHT = 2 | ||
} | ||
export declare const USBPrinter: { | ||
init: () => Promise<void>; | ||
getDeviceList: () => Promise<IUSBPrinter[]>; | ||
connectPrinter: (vendorId: string, productId: string) => Promise<IUSBPrinter>; | ||
closeConn: () => Promise<void>; | ||
printText: (text: string, opts?: PrinterOptions) => void; | ||
printBill: (text: string, opts?: PrinterOptions) => void; | ||
/** | ||
* image url | ||
* @param imgUrl | ||
* @param opts | ||
*/ | ||
printImage: (imgUrl: string, opts?: PrinterImageOptions) => void; | ||
/** | ||
* base64string, except -> data:image/png;base64, | ||
* @param qrCodeBase64 | ||
* @param opts | ||
*/ | ||
printQrCode: (qrCodeBase64: string, opts?: PrinterImageOptions) => void; | ||
/** | ||
* android print with encoder | ||
* @param text | ||
*/ | ||
printRaw: (text: string) => void; | ||
printColumnsText: (texts: string[], columnWidth: number[], columnAliment: (ColumnAliment)[], columnStyle: string[], opts?: PrinterOptions) => void; | ||
}; | ||
export declare const BLEPrinter: { | ||
init: () => Promise<void>; | ||
getDeviceList: () => Promise<IBLEPrinter[]>; | ||
connectPrinter: (inner_mac_address: string) => Promise<IBLEPrinter>; | ||
closeConn: () => Promise<void>; | ||
printText: (text: string, opts?: PrinterOptions) => void; | ||
printBill: (text: string, opts?: PrinterOptions) => void; | ||
/** | ||
* image url | ||
* @param imgUrl | ||
* @param opts | ||
*/ | ||
printImage: (imgUrl: string, opts?: PrinterImageOptions) => void; | ||
/** | ||
* base64string, except -> data:image/png;base64, | ||
* @param qrCodeBase64 | ||
* @param opts | ||
*/ | ||
printQrCode: (qrCodeBase64: string, opts?: PrinterImageOptions) => void; | ||
/** | ||
* android print with encoder | ||
* @param text | ||
*/ | ||
printRaw: (text: string) => void; | ||
printColumnsText: (texts: string[], columnWidth: number[], columnAliment: (ColumnAliment)[], columnStyle: string[], opts?: PrinterOptions) => void; | ||
}; | ||
export declare const NetPrinter: { | ||
init: () => Promise<void>; | ||
getDeviceList: () => Promise<INetPrinter[]>; | ||
connectPrinter: (host: string, port: number) => Promise<INetPrinter>; | ||
closeConn: () => Promise<void>; | ||
printText: (text: string, opts?: {}) => void; | ||
printBill: (text: string, opts?: PrinterOptions) => void; | ||
/** | ||
* image url | ||
* @param imgUrl | ||
* @param opts | ||
*/ | ||
printImage: (imgUrl: string, opts?: PrinterImageOptions) => void; | ||
/** | ||
* base64string, except -> data:image/png;base64, | ||
* @param qrCodeBase64 | ||
* @param opts | ||
*/ | ||
printQrCode: (qrCodeBase64: string, opts?: PrinterImageOptions) => void; | ||
/** | ||
* Android print with encoder | ||
* @param text | ||
*/ | ||
printRaw: (text: string) => void; | ||
/** | ||
* `columnWidth` | ||
* 80mm => 46 character | ||
* 58mm => 30 character | ||
*/ | ||
printColumnsText: (texts: string[], columnWidth: number[], columnAliment: (ColumnAliment)[], columnStyle: string[], opts?: PrinterOptions) => void; | ||
}; | ||
export declare const NetPrinterEventEmitter: NativeEventEmitter; | ||
export declare enum RN_THERMAL_RECEIPT_PRINTER_EVENTS { | ||
EVENT_NET_PRINTER_SCANNED_SUCCESS = "scannerResolved", | ||
EVENT_NET_PRINTER_SCANNING = "scannerRunning", | ||
EVENT_NET_PRINTER_SCANNED_ERROR = "registerError" | ||
EVENT_NET_PRINTER_SCANNED_SUCCESS = "scannerResolved", | ||
EVENT_NET_PRINTER_SCANNING = "scannerRunning", | ||
EVENT_NET_PRINTER_SCANNED_ERROR = "registerError" | ||
} |
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function (t) { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
@@ -12,7 +12,6 @@ s = arguments[i]; | ||
}; | ||
import {NativeModules, NativeEventEmitter, Platform} from "react-native"; | ||
import { NativeModules, NativeEventEmitter, Platform } from "react-native"; | ||
import * as EPToolkit from "./utils/EPToolkit"; | ||
import {processColumnText} from './utils/print-column'; | ||
import { processColumnText } from './utils/print-column'; | ||
import PRINTER_COMMANDS from './utils/printer-commands'; | ||
var RNUSBPrinter = NativeModules.RNUSBPrinter; | ||
@@ -52,8 +51,4 @@ var RNBLEPrinter = NativeModules.RNBLEPrinter; | ||
var textPreprocessingIOS = function (text, canCut, beep) { | ||
if (canCut === void 0) { | ||
canCut = true; | ||
} | ||
if (beep === void 0) { | ||
beep = true; | ||
} | ||
if (canCut === void 0) { canCut = true; } | ||
if (beep === void 0) { beep = true; } | ||
var options = { | ||
@@ -82,7 +77,3 @@ beep: beep, | ||
return new Promise(function (resolve, reject) { | ||
return RNUSBPrinter.init(function () { | ||
return resolve(); | ||
}, function (error) { | ||
return reject(error); | ||
}); | ||
return RNUSBPrinter.init(function () { return resolve(); }, function (error) { return reject(error); }); | ||
}); | ||
@@ -92,7 +83,3 @@ }, | ||
return new Promise(function (resolve, reject) { | ||
return RNUSBPrinter.getDeviceList(function (printers) { | ||
return resolve(printers); | ||
}, function (error) { | ||
return reject(error); | ||
}); | ||
return RNUSBPrinter.getDeviceList(function (printers) { return resolve(printers); }, function (error) { return reject(error); }); | ||
}); | ||
@@ -102,7 +89,3 @@ }, | ||
return new Promise(function (resolve, reject) { | ||
return RNUSBPrinter.connectPrinter(vendorId, productId, function (printer) { | ||
return resolve(printer); | ||
}, function (error) { | ||
return reject(error); | ||
}); | ||
return RNUSBPrinter.connectPrinter(vendorId, productId, function (printer) { return resolve(printer); }, function (error) { return reject(error); }); | ||
}); | ||
@@ -117,5 +100,3 @@ }, | ||
printText: function (text, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (opts === void 0) { opts = {}; } | ||
return RNUSBPrinter.printRawData(textTo64Buffer(text, opts), function (error) { | ||
@@ -126,5 +107,3 @@ return console.warn(error); | ||
printBill: function (text, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (opts === void 0) { opts = {}; } | ||
return RNUSBPrinter.printRawData(billTo64Buffer(text, opts), function (error) { | ||
@@ -140,14 +119,9 @@ return console.warn(error); | ||
printImage: function (imgUrl, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (opts === void 0) { opts = {}; } | ||
if (Platform.OS === "ios") { | ||
RNUSBPrinter.printImageData(imgUrl, opts, function (error) { | ||
return console.warn(error); | ||
}); | ||
} else { | ||
RNUSBPrinter.printImageData(imgUrl, function (error) { | ||
return console.warn(error); | ||
}); | ||
RNUSBPrinter.printImageData(imgUrl, opts, function (error) { return console.warn(error); }); | ||
} | ||
else { | ||
RNUSBPrinter.printImageData(imgUrl, function (error) { return console.warn(error); }); | ||
} | ||
}, | ||
@@ -160,14 +134,9 @@ /** | ||
printQrCode: function (qrCodeBase64, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (opts === void 0) { opts = {}; } | ||
if (Platform.OS === "ios") { | ||
RNUSBPrinter.printQrCode(qrCodeBase64, opts, function (error) { | ||
return console.warn(error); | ||
}); | ||
} else { | ||
RNUSBPrinter.printQrCode(qrCodeBase64, function (error) { | ||
return console.warn(error); | ||
}); | ||
RNUSBPrinter.printQrCode(qrCodeBase64, opts, function (error) { return console.warn(error); }); | ||
} | ||
else { | ||
RNUSBPrinter.printQrCode(qrCodeBase64, function (error) { return console.warn(error); }); | ||
} | ||
}, | ||
@@ -180,3 +149,4 @@ /** | ||
if (Platform.OS === "ios") { | ||
} else { | ||
} | ||
else { | ||
RNUSBPrinter.printRawData(text, function (error) { | ||
@@ -187,6 +157,9 @@ return console.warn(error); | ||
}, | ||
/** | ||
* `columnWidth` | ||
* 80mm => 46 character | ||
* 58mm => 30 character | ||
*/ | ||
printColumnsText: function (texts, columnWidth, columnAliment, columnStyle, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (opts === void 0) { opts = {}; } | ||
var result = processColumnText(texts, columnWidth, columnAliment, columnStyle); | ||
@@ -201,7 +174,3 @@ RNUSBPrinter.printRawData(textTo64Buffer(result, opts), function (error) { | ||
return new Promise(function (resolve, reject) { | ||
return RNBLEPrinter.init(function () { | ||
return resolve(); | ||
}, function (error) { | ||
return reject(error); | ||
}); | ||
return RNBLEPrinter.init(function () { return resolve(); }, function (error) { return reject(error); }); | ||
}); | ||
@@ -211,7 +180,3 @@ }, | ||
return new Promise(function (resolve, reject) { | ||
return RNBLEPrinter.getDeviceList(function (printers) { | ||
return resolve(printers); | ||
}, function (error) { | ||
return reject(error); | ||
}); | ||
return RNBLEPrinter.getDeviceList(function (printers) { return resolve(printers); }, function (error) { return reject(error); }); | ||
}); | ||
@@ -221,7 +186,3 @@ }, | ||
return new Promise(function (resolve, reject) { | ||
return RNBLEPrinter.connectPrinter(inner_mac_address, function (printer) { | ||
return resolve(printer); | ||
}, function (error) { | ||
return reject(error); | ||
}); | ||
return RNBLEPrinter.connectPrinter(inner_mac_address, function (printer) { return resolve(printer); }, function (error) { return reject(error); }); | ||
}); | ||
@@ -236,11 +197,8 @@ }, | ||
printText: function (text, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (opts === void 0) { opts = {}; } | ||
if (Platform.OS === "ios") { | ||
var processedText = textPreprocessingIOS(text, false, false); | ||
RNBLEPrinter.printRawData(processedText.text, processedText.opts, function (error) { | ||
return console.warn(error); | ||
}); | ||
} else { | ||
RNBLEPrinter.printRawData(processedText.text, processedText.opts, function (error) { return console.warn(error); }); | ||
} | ||
else { | ||
RNBLEPrinter.printRawData(textTo64Buffer(text, opts), function (error) { | ||
@@ -253,11 +211,8 @@ return console.warn(error); | ||
var _a, _b; | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (opts === void 0) { opts = {}; } | ||
if (Platform.OS === "ios") { | ||
var processedText = textPreprocessingIOS(text, (_a = opts === null || opts === void 0 ? void 0 : opts.cut) !== null && _a !== void 0 ? _a : true, (_b = opts.beep) !== null && _b !== void 0 ? _b : true); | ||
RNBLEPrinter.printRawData(processedText.text, processedText.opts, function (error) { | ||
return console.warn(error); | ||
}); | ||
} else { | ||
RNBLEPrinter.printRawData(processedText.text, processedText.opts, function (error) { return console.warn(error); }); | ||
} | ||
else { | ||
RNBLEPrinter.printRawData(billTo64Buffer(text, opts), function (error) { | ||
@@ -274,5 +229,3 @@ return console.warn(error); | ||
printImage: function (imgUrl, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (opts === void 0) { opts = {}; } | ||
if (Platform.OS === "ios") { | ||
@@ -282,10 +235,7 @@ /** | ||
*/ | ||
RNBLEPrinter.printImageData(imgUrl, opts, function (error) { | ||
return console.warn(error); | ||
}); | ||
} else { | ||
RNBLEPrinter.printImageData(imgUrl, function (error) { | ||
return console.warn(error); | ||
}); | ||
RNBLEPrinter.printImageData(imgUrl, opts, function (error) { return console.warn(error); }); | ||
} | ||
else { | ||
RNBLEPrinter.printImageData(imgUrl, function (error) { return console.warn(error); }); | ||
} | ||
}, | ||
@@ -298,5 +248,3 @@ /** | ||
printQrCode: function (qrCodeBase64, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (opts === void 0) { opts = {}; } | ||
if (Platform.OS === "ios") { | ||
@@ -306,12 +254,9 @@ /** | ||
*/ | ||
RNBLEPrinter.printQrCode(qrCodeBase64, opts, function (error) { | ||
return console.warn(error); | ||
}); | ||
} else { | ||
RNBLEPrinter.printQrCode(qrCodeBase64, opts, function (error) { return console.warn(error); }); | ||
} | ||
else { | ||
/** | ||
* just development | ||
*/ | ||
RNBLEPrinter.printQrCode(qrCodeBase64, function (error) { | ||
return console.warn(error); | ||
}); | ||
RNBLEPrinter.printQrCode(qrCodeBase64, function (error) { return console.warn(error); }); | ||
} | ||
@@ -325,3 +270,4 @@ }, | ||
if (Platform.OS === "ios") { | ||
} else { | ||
} | ||
else { | ||
RNBLEPrinter.printRawData(text, function (error) { | ||
@@ -332,13 +278,15 @@ return console.warn(error); | ||
}, | ||
/** | ||
* `columnWidth` | ||
* 80mm => 46 character | ||
* 58mm => 30 character | ||
*/ | ||
printColumnsText: function (texts, columnWidth, columnAliment, columnStyle, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (opts === void 0) { opts = {}; } | ||
var result = processColumnText(texts, columnWidth, columnAliment, columnStyle); | ||
if (Platform.OS === "ios") { | ||
var processedText = textPreprocessingIOS(result, false, false); | ||
RNBLEPrinter.printRawData(processedText.text, processedText.opts, function (error) { | ||
return console.warn(error); | ||
}); | ||
} else { | ||
RNBLEPrinter.printRawData(processedText.text, processedText.opts, function (error) { return console.warn(error); }); | ||
} | ||
else { | ||
RNBLEPrinter.printRawData(textTo64Buffer(result, opts), function (error) { | ||
@@ -353,7 +301,3 @@ return console.warn(error); | ||
return new Promise(function (resolve, reject) { | ||
return RNNetPrinter.init(function () { | ||
return resolve(); | ||
}, function (error) { | ||
return reject(error); | ||
}); | ||
return RNNetPrinter.init(function () { return resolve(); }, function (error) { return reject(error); }); | ||
}); | ||
@@ -363,7 +307,3 @@ }, | ||
return new Promise(function (resolve, reject) { | ||
return RNNetPrinter.getDeviceList(function (printers) { | ||
return resolve(printers); | ||
}, function (error) { | ||
return reject(error); | ||
}); | ||
return RNNetPrinter.getDeviceList(function (printers) { return resolve(printers); }, function (error) { return reject(error); }); | ||
}); | ||
@@ -373,7 +313,3 @@ }, | ||
return new Promise(function (resolve, reject) { | ||
return RNNetPrinter.connectPrinter(host, port, function (printer) { | ||
return resolve(printer); | ||
}, function (error) { | ||
return reject(error); | ||
}); | ||
return RNNetPrinter.connectPrinter(host, port, function (printer) { return resolve(printer); }, function (error) { return reject(error); }); | ||
}); | ||
@@ -388,11 +324,8 @@ }, | ||
printText: function (text, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (opts === void 0) { opts = {}; } | ||
if (Platform.OS === "ios") { | ||
var processedText = textPreprocessingIOS(text, false, false); | ||
RNNetPrinter.printRawData(processedText.text, processedText.opts, function (error) { | ||
return console.warn(error); | ||
}); | ||
} else { | ||
RNNetPrinter.printRawData(processedText.text, processedText.opts, function (error) { return console.warn(error); }); | ||
} | ||
else { | ||
RNNetPrinter.printRawData(textTo64Buffer(text, opts), function (error) { | ||
@@ -405,11 +338,8 @@ return console.warn(error); | ||
var _a, _b; | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (opts === void 0) { opts = {}; } | ||
if (Platform.OS === "ios") { | ||
var processedText = textPreprocessingIOS(text, (_a = opts === null || opts === void 0 ? void 0 : opts.cut) !== null && _a !== void 0 ? _a : true, (_b = opts.beep) !== null && _b !== void 0 ? _b : true); | ||
RNNetPrinter.printRawData(processedText.text, processedText.opts, function (error) { | ||
return console.warn(error); | ||
}); | ||
} else { | ||
RNNetPrinter.printRawData(processedText.text, processedText.opts, function (error) { return console.warn(error); }); | ||
} | ||
else { | ||
RNNetPrinter.printRawData(billTo64Buffer(text, opts), function (error) { | ||
@@ -426,14 +356,9 @@ return console.warn(error); | ||
printImage: function (imgUrl, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (opts === void 0) { opts = {}; } | ||
if (Platform.OS === "ios") { | ||
RNNetPrinter.printImageData(imgUrl, opts, function (error) { | ||
return console.warn(error); | ||
}); | ||
} else { | ||
RNNetPrinter.printImageData(imgUrl, function (error) { | ||
return console.warn(error); | ||
}); | ||
RNNetPrinter.printImageData(imgUrl, opts, function (error) { return console.warn(error); }); | ||
} | ||
else { | ||
RNNetPrinter.printImageData(imgUrl, function (error) { return console.warn(error); }); | ||
} | ||
}, | ||
@@ -446,14 +371,9 @@ /** | ||
printQrCode: function (qrCodeBase64, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (opts === void 0) { opts = {}; } | ||
if (Platform.OS === "ios") { | ||
RNNetPrinter.printQrCode(qrCodeBase64, opts, function (error) { | ||
return console.warn(error); | ||
}); | ||
} else { | ||
RNNetPrinter.printQrCode(qrCodeBase64, function (error) { | ||
return console.warn(error); | ||
}); | ||
RNNetPrinter.printQrCode(qrCodeBase64, opts, function (error) { return console.warn(error); }); | ||
} | ||
else { | ||
RNNetPrinter.printQrCode(qrCodeBase64, function (error) { return console.warn(error); }); | ||
} | ||
}, | ||
@@ -466,3 +386,4 @@ /** | ||
if (Platform.OS === "ios") { | ||
} else { | ||
} | ||
else { | ||
RNNetPrinter.printRawData(text, function (error) { | ||
@@ -479,12 +400,10 @@ return console.warn(error); | ||
printColumnsText: function (texts, columnWidth, columnAliment, columnStyle, opts) { | ||
if (opts === void 0) { | ||
opts = {}; | ||
} | ||
if (columnStyle === void 0) { columnStyle = []; } | ||
if (opts === void 0) { opts = {}; } | ||
var result = processColumnText(texts, columnWidth, columnAliment, columnStyle); | ||
if (Platform.OS === "ios") { | ||
var processedText = textPreprocessingIOS(result, false, false); | ||
RNNetPrinter.printRawData(processedText.text, processedText.opts, function (error) { | ||
return console.warn(error); | ||
}); | ||
} else { | ||
RNNetPrinter.printRawData(processedText.text, processedText.opts, function (error) { return console.warn(error); }); | ||
} | ||
else { | ||
RNNetPrinter.printRawData(textTo64Buffer(result, opts), function (error) { | ||
@@ -491,0 +410,0 @@ return console.warn(error); |
import { ColumnAliment } from ".."; | ||
export declare const processColumnText: (texts: string[], columnWidth: number[], columnAliment: (ColumnAliment)[], columnStyle: string[]) => string; | ||
export declare const processColumnText: (texts: string[], columnWidth: number[], columnAliment: (ColumnAliment)[], columnStyle?: string[]) => string; |
@@ -14,2 +14,3 @@ var processAlignText = function (text, restLength, align) { | ||
var processNewLine = function (text, maxLength) { | ||
var _a; | ||
var newText; | ||
@@ -34,24 +35,26 @@ var newTextTail; | ||
return { | ||
text: newText, | ||
text_tail: newTextTail.trim() | ||
text: newText !== null && newText !== void 0 ? newText : '', | ||
text_tail: (_a = newTextTail.trim()) !== null && _a !== void 0 ? _a : '' | ||
}; | ||
}; | ||
export var processColumnText = function (texts, columnWidth, columnAliment, columnStyle) { | ||
var new_texts = ['', '', '']; | ||
if (columnStyle === void 0) { columnStyle = []; } | ||
var rest_texts = ['', '', '']; | ||
var result = ''; | ||
texts.map(function (text, idx) { | ||
var _a, _b; | ||
if (text.length >= columnWidth[idx]) { | ||
var processedText = processNewLine(text, columnWidth[idx]); | ||
result += (columnStyle === null || columnStyle === void 0 ? void 0 : columnStyle[idx]) + processAlignText(processedText.text, columnWidth[idx] - processedText.text.length, columnAliment[idx]) + (idx !== 2 ? " " : ""); | ||
new_texts[idx] = processedText.text_tail; | ||
result += ((_a = columnStyle === null || columnStyle === void 0 ? void 0 : columnStyle[idx]) !== null && _a !== void 0 ? _a : '') + processAlignText(processedText.text, columnWidth[idx] - processedText.text.length, columnAliment[idx]) + (idx !== 2 ? " " : ""); | ||
rest_texts[idx] = processedText.text_tail; | ||
} | ||
else { | ||
result += (columnStyle === null || columnStyle === void 0 ? void 0 : columnStyle[idx]) + processAlignText(text.trim(), columnWidth[idx] - text.length, columnAliment[idx]) + (idx !== 2 ? " " : ""); | ||
result += ((_b = columnStyle === null || columnStyle === void 0 ? void 0 : columnStyle[idx]) !== null && _b !== void 0 ? _b : '') + processAlignText(text.trim(), columnWidth[idx] - text.length, columnAliment[idx]) + (idx !== 2 ? " " : ""); | ||
} | ||
}); | ||
var index_nonEmpty = new_texts.findIndex(function (new_text) { return new_text != ''; }); | ||
var index_nonEmpty = rest_texts.findIndex(function (rest_text) { return rest_text != ''; }); | ||
if (index_nonEmpty !== -1) { | ||
result += "\n" + processColumnText(new_texts, columnWidth, columnAliment, columnStyle); | ||
result += "\n" + processColumnText(rest_texts, columnWidth, columnAliment, columnStyle); | ||
} | ||
return result; | ||
}; |
{ | ||
"name": "react-native-thermal-receipt-printer-image-qr", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "Fork of react-native-thermal-receipt-printer. A React Native Library to support USB/BLE/Net printer", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
Sorry, the diff of this file is not supported yet
7008919
1431