sumni-utils
v2.0.1
Published
A collection of hardware utilities for SUMNI devices.
Readme
sumni-utils
Printer Class Documentation
The Printer class provides a set of utility methods to interact with a printing device. It allows for printing text, columns, QR codes, and remote images, as well as setting alignment styles.
The CashDrawer class provides some utilities for using the Sumni Models Cash Drawers.
Before using any of those classes you must first execute the initialize module.
Methods
Description: Prints a string with an optional style.
Syntax:
Printer.print(content: string, style?: PrinterStyle): Promise<void>Parameters:
content(string): The text to print.style(PrinterStyle, optional): The style to apply to the text.
Returns:
- A promise that resolves when the printing is complete.
printColumns
Description: Prints multiple columns with specified text, widths, and styles.
Syntax:
Printer.printColumns(columns: { text: string; width: number; style?: PrinterStyleColumns; }[]): Promise<void>Parameters:
columns(array): An array of objects, each containing:text(string): The text for the column.width(number): The width of the column.style(PrinterStyleColumns, optional): The style for the column.
Returns:
- A promise that resolves when the columns are printed.
Errors:
- Throws an error if
columnsis not an array of valid objects.
setAlignment
Description: Sets the alignment for the printer.
Syntax:
Printer.setAlignment(align: Alignment): Promise<void>Parameters:
align(Alignment): The desired alignment (e.g.,left,center,right).
Returns:
- A promise that resolves when the alignment is set.
Errors:
- Throws an error for invalid alignment values.
printQRCode
Description: Prints a QR code with specified data, alignment, size, and error correction level.
Syntax:
Printer.printQRCode({ data, align, size, ecc }: { data: string; align?: Alignment; size?: number; ecc?: 'L' | 'M' | 'Q' | 'H'; }): Promise<void>Parameters:
data(string): The data to encode in the QR code.align(Alignment, optional): The alignment of the QR code (default:center).size(number, optional): The size of the QR code (range: 4-16, default: 12).ecc(string, optional): The error correction level (L,M,Q, orH, default:M).
Returns:
- A promise that resolves when the QR code is printed.
Errors:
- Throws an error for invalid data, size, alignment, or ECC values.
printRemoteImage
Description: Fetches and prints an image from a remote URL with optional alignment and dimensions.
Syntax:
Printer.printRemoteImage({ url, requestConfig, align, width, height }: { url: string; requestConfig?: RequestInit; align?: Alignment; width?: number | null; height?: number | null; }): Promise<void>Parameters:
url(string): The URL of the image.requestConfig(RequestInit, optional): Configuration for the HTTP request.align(Alignment, optional): The alignment of the image (default:center).width(number | null, optional): The desired width of the image.height(number | null, optional): The desired height of the image.
Returns:
- A promise that resolves when the image is printed.
Errors:
- Throws an error for failed image requests, invalid content types, or alignment issues.
Types
PrinterStyle
An object defining text styling options (implementation-specific).
PrinterStyleColumns
An object defining column-specific styling options.
Alignment
A string indicating alignment options (e.g., left, center, right).
ECC
An array containing valid error correction levels for QR codes (L, M, Q, H).
CashDrawer Methods
open
Description: Opens the cash drawer.
Syntax:
CashDrawer.open(): Promise<void>Parameters:
- None.
Returns:
- A promise that resolves when the cash drawer is successfully opened.
isOpen
Description: Checks if the cash drawer is open.
Syntax:
CashDrawer.isOpen(): Promise<boolean>Parameters:
- None.
Returns:
- A promise that resolves to
trueif the cash drawer is open, orfalseotherwise.
