@risleylima/escpos 0.2.1 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +116 -755
- package/dist/adapter/index.d.ts +29 -0
- package/dist/adapter/index.d.ts.map +1 -0
- package/dist/adapter/index.js +25 -0
- package/dist/adapter/index.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/network-adapter/index.d.ts +24 -0
- package/dist/network-adapter/index.d.ts.map +1 -0
- package/dist/network-adapter/index.js +263 -0
- package/dist/network-adapter/index.js.map +1 -0
- package/dist/printer/commands-types.d.ts +37 -0
- package/dist/printer/commands-types.d.ts.map +1 -0
- package/dist/printer/commands-types.js +63 -0
- package/dist/printer/commands-types.js.map +1 -0
- package/dist/printer/commands.d.ts +169 -0
- package/dist/printer/commands.d.ts.map +1 -0
- package/dist/printer/commands.js +192 -0
- package/dist/printer/commands.js.map +1 -0
- package/dist/printer/image-loader.d.ts +17 -0
- package/dist/printer/image-loader.d.ts.map +1 -0
- package/dist/printer/image-loader.js +462 -0
- package/dist/printer/image-loader.js.map +1 -0
- package/dist/printer/image.d.ts +43 -0
- package/dist/printer/image.d.ts.map +1 -0
- package/dist/printer/image.js +132 -0
- package/dist/printer/image.js.map +1 -0
- package/dist/printer/index.d.ts +158 -0
- package/dist/printer/index.d.ts.map +1 -0
- package/dist/printer/index.js +703 -0
- package/dist/printer/index.js.map +1 -0
- package/dist/printer/profiles/bematech/mp4200th.d.ts +13 -0
- package/dist/printer/profiles/bematech/mp4200th.d.ts.map +1 -0
- package/dist/printer/profiles/bematech/mp4200th.js +29 -0
- package/dist/printer/profiles/bematech/mp4200th.js.map +1 -0
- package/dist/printer/profiles/custom/bematech-mp4200th.d.ts +13 -0
- package/dist/printer/profiles/custom/bematech-mp4200th.d.ts.map +1 -0
- package/dist/printer/profiles/custom/bematech-mp4200th.js +21 -0
- package/dist/printer/profiles/custom/bematech-mp4200th.js.map +1 -0
- package/dist/printer/profiles/custom/vkp80iii.d.ts +19 -0
- package/dist/printer/profiles/custom/vkp80iii.d.ts.map +1 -0
- package/dist/printer/profiles/custom/vkp80iii.js +87 -0
- package/dist/printer/profiles/custom/vkp80iii.js.map +1 -0
- package/dist/printer/profiles/default.d.ts +7 -0
- package/dist/printer/profiles/default.d.ts.map +1 -0
- package/dist/printer/profiles/default.js +15 -0
- package/dist/printer/profiles/default.js.map +1 -0
- package/dist/printer/profiles/index.d.ts +41 -0
- package/dist/printer/profiles/index.d.ts.map +1 -0
- package/dist/printer/profiles/index.js +98 -0
- package/dist/printer/profiles/index.js.map +1 -0
- package/dist/printer/profiles/merge.d.ts +7 -0
- package/dist/printer/profiles/merge.d.ts.map +1 -0
- package/dist/printer/profiles/merge.js +58 -0
- package/dist/printer/profiles/merge.js.map +1 -0
- package/dist/printer/profiles/types.d.ts +99 -0
- package/dist/printer/profiles/types.d.ts.map +1 -0
- package/dist/printer/profiles/types.js +8 -0
- package/dist/printer/profiles/types.js.map +1 -0
- package/dist/printer/utils.d.ts +9 -0
- package/dist/printer/utils.d.ts.map +1 -0
- package/dist/printer/utils.js +54 -0
- package/dist/printer/utils.js.map +1 -0
- package/dist/serial-adapter/index.d.ts +21 -0
- package/dist/serial-adapter/index.d.ts.map +1 -0
- package/dist/serial-adapter/index.js +180 -0
- package/dist/serial-adapter/index.js.map +1 -0
- package/dist/usb-adapter/index.d.ts +20 -0
- package/dist/usb-adapter/index.d.ts.map +1 -0
- package/dist/usb-adapter/index.js +264 -0
- package/dist/usb-adapter/index.js.map +1 -0
- package/package.json +42 -15
- package/CHANGELOG.md +0 -74
- package/docs/COVERAGE_ANALYSIS.md +0 -98
- package/docs/DEPENDENCIES_REVIEW.md +0 -127
- package/docs/JSDOC_REVIEW.md +0 -122
- package/docs/LIBRARY_OVERVIEW.md +0 -383
- package/docs/PRE_PUBLISH_CHECKLIST.md +0 -331
- package/docs/PUBLIC_API_ANALYSIS.md +0 -223
- package/docs/README.md +0 -37
- package/docs/SERIALPORT_V13_MIGRATION_COMPLETE.md +0 -127
- package/docs/TESTS_IMPLEMENTED.md +0 -129
- package/docs/USB_V2_REVIEW.md +0 -148
- package/docs/VERIFICATION_RESULTS.md +0 -172
- package/docs/VERSIONING.md +0 -102
- package/examples/printTest.js +0 -59
- package/index.js +0 -7
- package/jest.config.js +0 -16
- package/src/adapter/index.js +0 -75
- package/src/printer/commands.js +0 -199
- package/src/printer/image.js +0 -159
- package/src/printer/index.js +0 -621
- package/src/printer/utils.js +0 -58
- package/src/serial-adapter/index.js +0 -198
- package/src/usb-adapter/index.js +0 -283
- package/tests/README.md +0 -67
- package/tests/integration/printer-flow.test.js +0 -128
- package/tests/unit/adapters/adapter.test.js +0 -49
- package/tests/unit/adapters/serial-adapter.test.js +0 -238
- package/tests/unit/adapters/usb-adapter.test.js +0 -319
- package/tests/unit/image/image.test.js +0 -157
- package/tests/unit/printer/buffer.test.js +0 -60
- package/tests/unit/printer/commands.test.js +0 -109
- package/tests/unit/printer/printer.test.js +0 -405
- package/tests/unit/utils/utils.test.js +0 -96
package/docs/JSDOC_REVIEW.md
DELETED
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
# JSDoc Documentation Review
|
|
2
|
-
|
|
3
|
-
## Overview
|
|
4
|
-
|
|
5
|
-
This document reviews the JSDoc documentation coverage across the library.
|
|
6
|
-
|
|
7
|
-
## Documentation Status
|
|
8
|
-
|
|
9
|
-
### ✅ Fully Documented Modules
|
|
10
|
-
|
|
11
|
-
#### 1. **Adapter Class** (`src/adapter/index.js`)
|
|
12
|
-
- ✅ Class documentation with `@class` and `@classdesc`
|
|
13
|
-
- ✅ Constructor with `@param` documentation
|
|
14
|
-
- ✅ All abstract methods documented with `@abstract` and `@throws`
|
|
15
|
-
|
|
16
|
-
#### 2. **Printer Class** (`src/printer/index.js`)
|
|
17
|
-
- ✅ Class documentation with `@class` and `@classdesc`
|
|
18
|
-
- ✅ Constructor with detailed `@param` documentation
|
|
19
|
-
- ✅ All public methods have JSDoc with:
|
|
20
|
-
- `@param` for parameters
|
|
21
|
-
- `@return` or `@returns` for return values
|
|
22
|
-
- Method descriptions
|
|
23
|
-
|
|
24
|
-
#### 3. **Image Class** (`src/printer/image.js`)
|
|
25
|
-
- ✅ Class documentation with `@class` and `@classdesc`
|
|
26
|
-
- ✅ Constructor with `@param` documentation
|
|
27
|
-
- ✅ `toBitmap()` method documented
|
|
28
|
-
- ✅ `toRaster()` method documented
|
|
29
|
-
- ✅ `load()` static method documented with `@example`
|
|
30
|
-
|
|
31
|
-
#### 4. **Utils Module** (`src/printer/utils.js`)
|
|
32
|
-
- ✅ All exported functions have JSDoc:
|
|
33
|
-
- `getParityBit()` - with description
|
|
34
|
-
- `codeLength()` - with description
|
|
35
|
-
- `textLength()` - with description
|
|
36
|
-
- `textSubstring()` - with `@param` and `@returns`
|
|
37
|
-
- ✅ Internal `charLength()` function documented
|
|
38
|
-
|
|
39
|
-
#### 5. **Commands Module** (`src/printer/commands.js`)
|
|
40
|
-
- ✅ `numToHexString()` function documented with `@example`
|
|
41
|
-
|
|
42
|
-
### ✅ Recently Added Documentation
|
|
43
|
-
|
|
44
|
-
#### 6. **USB Adapter** (`src/usb-adapter/index.js`)
|
|
45
|
-
- ✅ `listUSB()` - `@async`, `@returns`
|
|
46
|
-
- ✅ `connect()` - `@async`, `@param`, `@returns`, `@throws`, `@fires`
|
|
47
|
-
- ✅ `open()` - `@async`, `@returns`, `@throws`, `@fires`
|
|
48
|
-
- ✅ `close()` - `@async`, `@returns`, `@fires`
|
|
49
|
-
- ✅ `disconnect()` - `@async`, `@returns`, `@fires`
|
|
50
|
-
- ✅ `write()` - `@async`, `@param`, `@returns`, `@throws`
|
|
51
|
-
- ✅ Private `getDescriptor()` function documented
|
|
52
|
-
|
|
53
|
-
#### 7. **Serial Adapter** (`src/serial-adapter/index.js`)
|
|
54
|
-
- ✅ `connect()` - `@async`, `@param`, `@returns`, `@throws`, `@fires`
|
|
55
|
-
- ✅ `open()` - `@async`, `@returns`, `@throws`
|
|
56
|
-
- ✅ `write()` - `@async`, `@param`, `@returns`, `@throws`
|
|
57
|
-
- ✅ `close()` - `@async`, `@param`, `@returns`, `@fires`
|
|
58
|
-
- ✅ `disconnect()` - `@param`, `@returns`
|
|
59
|
-
- ✅ `read()` - `@returns`
|
|
60
|
-
- ✅ Private `verifyPort()` function documented
|
|
61
|
-
|
|
62
|
-
## Documentation Quality
|
|
63
|
-
|
|
64
|
-
### Standards Applied
|
|
65
|
-
|
|
66
|
-
1. **Class Documentation**:
|
|
67
|
-
- `@class` tag
|
|
68
|
-
- `@classdesc` for description
|
|
69
|
-
- `@extends` for inheritance
|
|
70
|
-
|
|
71
|
-
2. **Method Documentation**:
|
|
72
|
-
- `@async` for async methods
|
|
73
|
-
- `@param {Type} name - Description` for parameters
|
|
74
|
-
- `@returns {Type} Description` for return values
|
|
75
|
-
- `@throws {Error} Description` for errors
|
|
76
|
-
- `@fires EventName` for events emitted
|
|
77
|
-
- `@example` for usage examples
|
|
78
|
-
|
|
79
|
-
3. **Function Documentation**:
|
|
80
|
-
- Parameter types and descriptions
|
|
81
|
-
- Return types and descriptions
|
|
82
|
-
- Usage examples where helpful
|
|
83
|
-
|
|
84
|
-
## Coverage Summary
|
|
85
|
-
|
|
86
|
-
| Module | Classes | Methods | Functions | Coverage |
|
|
87
|
-
|--------|---------|---------|-----------|----------|
|
|
88
|
-
| `adapter/index.js` | 1 | 5 | 0 | 100% ✅ |
|
|
89
|
-
| `usb-adapter/index.js` | 0 | 6 | 1 | 100% ✅ |
|
|
90
|
-
| `serial-adapter/index.js` | 0 | 6 | 1 | 100% ✅ |
|
|
91
|
-
| `printer/index.js` | 2 | 30+ | 0 | 100% ✅ |
|
|
92
|
-
| `printer/image.js` | 1 | 3 | 0 | 100% ✅ |
|
|
93
|
-
| `printer/utils.js` | 0 | 0 | 5 | 100% ✅ |
|
|
94
|
-
| `printer/commands.js` | 0 | 0 | 1 | 100% ✅ |
|
|
95
|
-
|
|
96
|
-
**Overall JSDoc Coverage: 100%** ✅
|
|
97
|
-
|
|
98
|
-
## Benefits
|
|
99
|
-
|
|
100
|
-
1. **IDE Support**: Better autocomplete and type hints
|
|
101
|
-
2. **Documentation Generation**: Can generate HTML docs with tools like JSDoc
|
|
102
|
-
3. **Type Safety**: Helps catch errors during development
|
|
103
|
-
4. **Developer Experience**: Clear API documentation for users
|
|
104
|
-
5. **Maintainability**: Self-documenting code
|
|
105
|
-
|
|
106
|
-
## Notes
|
|
107
|
-
|
|
108
|
-
- All public APIs are fully documented
|
|
109
|
-
- Private/internal functions are marked with `@private` where appropriate
|
|
110
|
-
- Event emissions are documented with `@fires`
|
|
111
|
-
- Async methods are marked with `@async`
|
|
112
|
-
- Error conditions are documented with `@throws`
|
|
113
|
-
|
|
114
|
-
## Recommendations
|
|
115
|
-
|
|
116
|
-
The library now has comprehensive JSDoc documentation. Consider:
|
|
117
|
-
|
|
118
|
-
1. **Documentation Generation**: Use tools like `jsdoc` or `typedoc` to generate HTML documentation
|
|
119
|
-
2. **Type Checking**: Consider adding TypeScript or using JSDoc with type checking tools
|
|
120
|
-
3. **Examples**: Add more `@example` tags for complex methods
|
|
121
|
-
4. **Event Documentation**: Document all events that adapters can emit
|
|
122
|
-
|
package/docs/LIBRARY_OVERVIEW.md
DELETED
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
# Library Overview - @risleylima/escpos
|
|
2
|
-
|
|
3
|
-
## 📋 General Information
|
|
4
|
-
|
|
5
|
-
- **Name**: `@risleylima/escpos`
|
|
6
|
-
- **Version**: `0.1.0`
|
|
7
|
-
- **License**: MIT
|
|
8
|
-
- **Node.js**: `>=18.0.0`
|
|
9
|
-
- **Description**: Library to manage ESC/POS commands in Buffer (Node.js), then use an adapter to send the resulting data to the printer.
|
|
10
|
-
|
|
11
|
-
## 🏗️ Architecture
|
|
12
|
-
|
|
13
|
-
### Core Components
|
|
14
|
-
|
|
15
|
-
The library follows a modular architecture with clear separation of concerns:
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
-
escpos/
|
|
19
|
-
├── src/
|
|
20
|
-
│ ├── adapter/ # Base adapter class (EventEmitter)
|
|
21
|
-
│ ├── usb-adapter/ # USB communication adapter
|
|
22
|
-
│ ├── serial-adapter/ # Serial port communication adapter
|
|
23
|
-
│ └── printer/ # ESC/POS command generation
|
|
24
|
-
│ ├── commands.js # ESC/POS command definitions
|
|
25
|
-
│ ├── image.js # Image processing for thermal printers
|
|
26
|
-
│ ├── utils.js # Utility functions
|
|
27
|
-
│ └── index.js # Main Printer class
|
|
28
|
-
├── tests/ # Comprehensive test suite
|
|
29
|
-
│ ├── unit/ # Unit tests
|
|
30
|
-
│ └── integration/ # Integration tests
|
|
31
|
-
└── examples/ # Usage examples
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### Public API
|
|
35
|
-
|
|
36
|
-
The library exports the following modules:
|
|
37
|
-
|
|
38
|
-
```javascript
|
|
39
|
-
const { USB, Serial, Printer, Adapter, Image } = require('@risleylima/escpos');
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
- **USB**: USB adapter instance (EventEmitter)
|
|
43
|
-
- **Serial**: Serial port adapter instance (EventEmitter)
|
|
44
|
-
- **Printer**: ESC/POS command generator class
|
|
45
|
-
- **Adapter**: Base adapter class
|
|
46
|
-
- **Image**: Image processing utilities
|
|
47
|
-
|
|
48
|
-
## 🔌 Adapters
|
|
49
|
-
|
|
50
|
-
### USB Adapter (`usb-adapter`)
|
|
51
|
-
|
|
52
|
-
- **Technology**: `node-usb` v2.16.0 (Promise-based API)
|
|
53
|
-
- **Features**:
|
|
54
|
-
- Device discovery and listing
|
|
55
|
-
- VID/PID-based connection
|
|
56
|
-
- Automatic printer interface detection
|
|
57
|
-
- Kernel driver handling (Linux/macOS)
|
|
58
|
-
- Event-driven architecture (connect, disconnect, close, detach)
|
|
59
|
-
- Error handling and recovery
|
|
60
|
-
|
|
61
|
-
**Key Methods**:
|
|
62
|
-
- `listUSB()`: List all USB printer devices
|
|
63
|
-
- `connect(vid, pid)`: Connect to a specific device
|
|
64
|
-
- `open()`: Open device and claim interface
|
|
65
|
-
- `write(data)`: Send data to printer
|
|
66
|
-
- `close()`: Close device connection
|
|
67
|
-
- `disconnect()`: Disconnect device
|
|
68
|
-
|
|
69
|
-
### Serial Adapter (`serial-adapter`)
|
|
70
|
-
|
|
71
|
-
- **Technology**: `serialport` v13.0.0 (Promise-based API)
|
|
72
|
-
- **Features**:
|
|
73
|
-
- Port verification
|
|
74
|
-
- Auto-open disabled (manual control)
|
|
75
|
-
- Event-driven architecture (connect, disconnect, close)
|
|
76
|
-
- Error handling via events
|
|
77
|
-
- Flush and drain operations
|
|
78
|
-
|
|
79
|
-
**Key Methods**:
|
|
80
|
-
- `connect(port, options)`: Connect to serial port
|
|
81
|
-
- `open()`: Open port if closed
|
|
82
|
-
- `write(data)`: Send data to printer
|
|
83
|
-
- `read()`: Read data from port
|
|
84
|
-
- `close(timeout)`: Close port with optional timeout
|
|
85
|
-
- `disconnect(timeout)`: Disconnect port
|
|
86
|
-
|
|
87
|
-
## 🖨️ Printer Class
|
|
88
|
-
|
|
89
|
-
The `Printer` class generates ESC/POS commands and manages a buffer system.
|
|
90
|
-
|
|
91
|
-
### Core Features
|
|
92
|
-
|
|
93
|
-
- **Buffer Management**: Dynamic buffer for command accumulation
|
|
94
|
-
- **Text Operations**: Print text with encoding support
|
|
95
|
-
- **Formatting**: Alignment, size, style (bold, italic, underline)
|
|
96
|
-
- **Hardware Control**: Cut, beep, cash drawer
|
|
97
|
-
- **Barcode Generation**: Multiple barcode formats
|
|
98
|
-
- **Image Printing**: Convert and print images
|
|
99
|
-
- **Method Chaining**: Fluent API for command composition
|
|
100
|
-
|
|
101
|
-
### Key Methods
|
|
102
|
-
|
|
103
|
-
**Text Operations**:
|
|
104
|
-
- `print(data)`: Print raw data
|
|
105
|
-
- `println(data)`: Print with line break
|
|
106
|
-
- `text(content, encoding)`: Print encoded text
|
|
107
|
-
- `textln(content, encoding)`: Print encoded text with line break
|
|
108
|
-
|
|
109
|
-
**Formatting**:
|
|
110
|
-
- `align(position)`: Set text alignment (left, center, right)
|
|
111
|
-
- `size(width, height)`: Set text size
|
|
112
|
-
- `style(style)`: Set text style (NORMAL, BOLD, ITALIC, UNDERLINE)
|
|
113
|
-
- `encode(codeTable)`: Set character encoding table
|
|
114
|
-
|
|
115
|
-
**Hardware**:
|
|
116
|
-
- `cut(partial)`: Cut paper
|
|
117
|
-
- `beep(count, time)`: Beep buzzer
|
|
118
|
-
- `cashdraw(pin)`: Open cash drawer
|
|
119
|
-
- `hardware(command)`: Hardware initialization
|
|
120
|
-
|
|
121
|
-
**Barcode**:
|
|
122
|
-
- `barcode(code, type, width, height, position, font)`: Print barcode
|
|
123
|
-
|
|
124
|
-
**Image**:
|
|
125
|
-
- `image(image, density)`: Print image
|
|
126
|
-
|
|
127
|
-
**Control**:
|
|
128
|
-
- `flush()`: Send buffered data to printer
|
|
129
|
-
- `close(options)`: Close connection and flush
|
|
130
|
-
|
|
131
|
-
## 📊 Test Coverage
|
|
132
|
-
|
|
133
|
-
### Test Statistics
|
|
134
|
-
|
|
135
|
-
- **Total Test Files**: 9
|
|
136
|
-
- **Total Tests**: 145
|
|
137
|
-
- **Test Suites**: 9
|
|
138
|
-
- **Coverage**: 100% (100% statements, 100% branches, 100% functions, 100% lines) ✅
|
|
139
|
-
- **Test Framework**: Jest 30.2.0
|
|
140
|
-
|
|
141
|
-
### Test Structure
|
|
142
|
-
|
|
143
|
-
```
|
|
144
|
-
tests/
|
|
145
|
-
├── unit/
|
|
146
|
-
│ ├── adapters/
|
|
147
|
-
│ │ ├── adapter.test.js # Base adapter tests
|
|
148
|
-
│ │ ├── usb-adapter.test.js # USB adapter tests
|
|
149
|
-
│ │ └── serial-adapter.test.js # Serial adapter tests
|
|
150
|
-
│ ├── printer/
|
|
151
|
-
│ │ ├── buffer.test.js # Buffer tests
|
|
152
|
-
│ │ └── printer.test.js # Printer class tests
|
|
153
|
-
│ ├── image/
|
|
154
|
-
│ │ └── image.test.js # Image processing tests
|
|
155
|
-
│ └── utils/
|
|
156
|
-
│ └── utils.test.js # Utility function tests
|
|
157
|
-
└── integration/
|
|
158
|
-
└── printer-flow.test.js # End-to-end flow tests
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### Test Coverage by Module
|
|
162
|
-
|
|
163
|
-
| Module | Statements | Branches | Functions | Lines |
|
|
164
|
-
|--------|-----------|----------|-----------|-------|
|
|
165
|
-
| All files | 100% | 100% | 100% | 100% |
|
|
166
|
-
| commands.js | 100% | 100% | 100% | 100% |
|
|
167
|
-
| image.js | 100% | 100% | 100% | 100% |
|
|
168
|
-
| utils.js | 100% | 100% | 100% | 100% |
|
|
169
|
-
|
|
170
|
-
## 📦 Dependencies
|
|
171
|
-
|
|
172
|
-
### Production Dependencies
|
|
173
|
-
|
|
174
|
-
| Package | Version | Purpose |
|
|
175
|
-
|---------|---------|---------|
|
|
176
|
-
| `debug` | ^4.4.3 | Debug logging |
|
|
177
|
-
| `get-pixels` | custom fork | Image pixel extraction |
|
|
178
|
-
| `iconv-lite` | ^0.7.0 | Text encoding conversion |
|
|
179
|
-
| `serialport` | ^13.0.0 | Serial port communication |
|
|
180
|
-
| `usb` | ^2.16.0 | USB device communication |
|
|
181
|
-
|
|
182
|
-
### Development Dependencies
|
|
183
|
-
|
|
184
|
-
| Package | Version | Purpose |
|
|
185
|
-
|---------|---------|---------|
|
|
186
|
-
| `jest` | ^30.2.0 | Testing framework |
|
|
187
|
-
|
|
188
|
-
**All dependencies are up to date!** ✅
|
|
189
|
-
|
|
190
|
-
## 🔄 Recent Improvements
|
|
191
|
-
|
|
192
|
-
### 1. Dependency Updates
|
|
193
|
-
|
|
194
|
-
- ✅ **USB Library**: Migrated from v1.9.1 (callbacks) to v2.16.0 (Promises)
|
|
195
|
-
- ✅ **SerialPort**: Migrated from v12.0.0 to v13.0.0 (Promise-based API)
|
|
196
|
-
- ✅ **iconv-lite**: Updated from 0.6.3 to 0.7.0
|
|
197
|
-
- ✅ **debug**: Updated from 4.3.1 to 4.4.3
|
|
198
|
-
- ✅ **jest**: Updated from 29.7.0 to 30.2.0
|
|
199
|
-
|
|
200
|
-
### 2. Architecture Improvements
|
|
201
|
-
|
|
202
|
-
- ✅ **Event Consistency**: Fixed adapter event emission by using the same object instance internally and externally
|
|
203
|
-
- ✅ **Adapter Pattern**: Simplified Printer to use adapter directly instead of creating wrapper instances
|
|
204
|
-
- ✅ **Code Cleanup**: Removed unused imports and dependencies
|
|
205
|
-
|
|
206
|
-
### 3. Test Suite
|
|
207
|
-
|
|
208
|
-
- ✅ **Comprehensive Coverage**: 126 tests covering all major functionality
|
|
209
|
-
- ✅ **Unit Tests**: All core components tested in isolation
|
|
210
|
-
- ✅ **Integration Tests**: End-to-end printer flow validation
|
|
211
|
-
- ✅ **Mock Strategy**: Proper mocking of USB and Serial adapters
|
|
212
|
-
|
|
213
|
-
### 4. Documentation
|
|
214
|
-
|
|
215
|
-
- ✅ **Migration Guides**: Detailed documentation for USB v2 and SerialPort v13 migrations
|
|
216
|
-
- ✅ **Test Documentation**: Complete test suite documentation
|
|
217
|
-
- ✅ **Dependency Review**: Comprehensive dependency status tracking
|
|
218
|
-
|
|
219
|
-
## 🎯 Key Features
|
|
220
|
-
|
|
221
|
-
### 1. Multi-Adapter Support
|
|
222
|
-
|
|
223
|
-
The library supports multiple connection types:
|
|
224
|
-
- **USB**: Direct USB printer connection
|
|
225
|
-
- **Serial**: Serial port (RS-232) connection
|
|
226
|
-
|
|
227
|
-
Both adapters share the same interface and can be used interchangeably.
|
|
228
|
-
|
|
229
|
-
### 2. Event-Driven Architecture
|
|
230
|
-
|
|
231
|
-
All adapters extend EventEmitter, providing:
|
|
232
|
-
- `connect` event: Emitted when device connects
|
|
233
|
-
- `disconnect` event: Emitted when device disconnects
|
|
234
|
-
- `close` event: Emitted when connection closes
|
|
235
|
-
- `detach` event: Emitted when USB device is unplugged
|
|
236
|
-
|
|
237
|
-
### 3. Fluent API
|
|
238
|
-
|
|
239
|
-
The Printer class supports method chaining:
|
|
240
|
-
|
|
241
|
-
```javascript
|
|
242
|
-
printer
|
|
243
|
-
.hardware('init')
|
|
244
|
-
.align('ct')
|
|
245
|
-
.size(2, 2)
|
|
246
|
-
.textln('Hello World')
|
|
247
|
-
.cut(true);
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
### 4. Encoding Support
|
|
251
|
-
|
|
252
|
-
Full support for various character encodings:
|
|
253
|
-
- GB18030 (default)
|
|
254
|
-
- UTF-8
|
|
255
|
-
- ASCII
|
|
256
|
-
- And more via iconv-lite
|
|
257
|
-
|
|
258
|
-
### 5. Image Processing
|
|
259
|
-
|
|
260
|
-
Built-in image processing for thermal printers:
|
|
261
|
-
- Image loading and conversion
|
|
262
|
-
- Bitmap and raster format support
|
|
263
|
-
- Density control
|
|
264
|
-
|
|
265
|
-
## 📝 Usage Example
|
|
266
|
-
|
|
267
|
-
```javascript
|
|
268
|
-
const { USB, Printer } = require('@risleylima/escpos');
|
|
269
|
-
|
|
270
|
-
(async () => {
|
|
271
|
-
// Connect to USB printer
|
|
272
|
-
await USB.connect(1046, 20497);
|
|
273
|
-
await USB.open();
|
|
274
|
-
|
|
275
|
-
// Create printer instance
|
|
276
|
-
const printer = new Printer(USB);
|
|
277
|
-
|
|
278
|
-
// Print receipt
|
|
279
|
-
printer
|
|
280
|
-
.hardware('init')
|
|
281
|
-
.align('ct')
|
|
282
|
-
.size(2, 2)
|
|
283
|
-
.textln('RECEIPT')
|
|
284
|
-
.size(1, 1)
|
|
285
|
-
.align('lt')
|
|
286
|
-
.textln('Item 1: $10.00')
|
|
287
|
-
.textln('Item 2: $20.00')
|
|
288
|
-
.align('rt')
|
|
289
|
-
.textln('Total: $30.00')
|
|
290
|
-
.cut(true);
|
|
291
|
-
|
|
292
|
-
// Send to printer
|
|
293
|
-
await printer.flush();
|
|
294
|
-
|
|
295
|
-
// Close connection
|
|
296
|
-
await USB.close();
|
|
297
|
-
await USB.disconnect();
|
|
298
|
-
})();
|
|
299
|
-
```
|
|
300
|
-
|
|
301
|
-
## 🔍 Code Quality
|
|
302
|
-
|
|
303
|
-
### Metrics
|
|
304
|
-
|
|
305
|
-
- **Files**: 7 source files
|
|
306
|
-
- **Test Files**: 8 test files
|
|
307
|
-
- **Test Coverage**: 88.09% (excellent)
|
|
308
|
-
- **All Tests Passing**: ✅ 126/126
|
|
309
|
-
|
|
310
|
-
### Architecture Quality
|
|
311
|
-
|
|
312
|
-
- ✅ **Separation of Concerns**: Clear module boundaries
|
|
313
|
-
- ✅ **Single Responsibility**: Each module has a focused purpose
|
|
314
|
-
- ✅ **Event-Driven**: Proper use of EventEmitter pattern
|
|
315
|
-
- ✅ **Promise-Based**: Modern async/await patterns
|
|
316
|
-
- ✅ **Error Handling**: Comprehensive error handling
|
|
317
|
-
- ✅ **Type Safety**: JSDoc comments for better IDE support
|
|
318
|
-
|
|
319
|
-
## 🚀 Performance
|
|
320
|
-
|
|
321
|
-
- **Buffer Management**: Efficient buffer accumulation and flushing
|
|
322
|
-
- **Async Operations**: Non-blocking I/O operations
|
|
323
|
-
- **Event System**: Lightweight event emission
|
|
324
|
-
- **Memory**: Efficient buffer reuse
|
|
325
|
-
|
|
326
|
-
## 🔒 Stability
|
|
327
|
-
|
|
328
|
-
- **Test Coverage**: 88.09% with 126 tests
|
|
329
|
-
- **All Tests Passing**: ✅
|
|
330
|
-
- **Dependencies**: All up to date
|
|
331
|
-
- **Breaking Changes**: None in recent updates
|
|
332
|
-
- **API Compatibility**: Maintained throughout updates
|
|
333
|
-
|
|
334
|
-
## 📚 Documentation
|
|
335
|
-
|
|
336
|
-
Comprehensive documentation available in `docs/`:
|
|
337
|
-
|
|
338
|
-
- `DEPENDENCIES_REVIEW.md`: Dependency status and update history
|
|
339
|
-
- `PUBLIC_API_ANALYSIS.md`: Public API documentation
|
|
340
|
-
- `TESTS_IMPLEMENTED.md`: Test suite documentation
|
|
341
|
-
- `USB_V2_MIGRATION.md`: USB v2 migration guide
|
|
342
|
-
- `USB_V2_REVIEW.md`: USB v2 review and changes
|
|
343
|
-
- `SERIALPORT_V13_MIGRATION_PLAN.md`: SerialPort v13 migration plan
|
|
344
|
-
- `SERIALPORT_V13_MIGRATION_COMPLETE.md`: SerialPort v13 migration completion
|
|
345
|
-
- `SERIALPORT_V13_ANALYSIS.md`: SerialPort v13 analysis
|
|
346
|
-
|
|
347
|
-
## 🎓 Best Practices
|
|
348
|
-
|
|
349
|
-
The library follows Node.js best practices:
|
|
350
|
-
|
|
351
|
-
1. **Error Handling**: Try-catch blocks and error events
|
|
352
|
-
2. **Async/Await**: Modern Promise-based async operations
|
|
353
|
-
3. **EventEmitter**: Proper event-driven architecture
|
|
354
|
-
4. **Modularity**: Clear separation of concerns
|
|
355
|
-
5. **Testing**: Comprehensive test coverage
|
|
356
|
-
6. **Documentation**: JSDoc comments and detailed guides
|
|
357
|
-
|
|
358
|
-
## 🔮 Future Considerations
|
|
359
|
-
|
|
360
|
-
Potential areas for future enhancement:
|
|
361
|
-
|
|
362
|
-
1. **TypeScript**: Consider migrating to TypeScript for better type safety
|
|
363
|
-
2. **Network Adapter**: Add support for network printers (TCP/IP)
|
|
364
|
-
3. **Bluetooth Adapter**: Add support for Bluetooth printers
|
|
365
|
-
4. **More Barcode Types**: Expand barcode format support
|
|
366
|
-
5. **PDF Support**: Direct PDF to ESC/POS conversion
|
|
367
|
-
6. **QR Code**: Native QR code generation
|
|
368
|
-
7. **Printer Status**: Query printer status and paper levels
|
|
369
|
-
|
|
370
|
-
## 📊 Summary
|
|
371
|
-
|
|
372
|
-
**@risleylima/escpos** is a modern, well-architected ESC/POS library for Node.js with:
|
|
373
|
-
|
|
374
|
-
- ✅ **Modern Architecture**: Event-driven, Promise-based
|
|
375
|
-
- ✅ **Comprehensive Testing**: 126 tests, 88% coverage
|
|
376
|
-
- ✅ **Up-to-Date Dependencies**: All dependencies current
|
|
377
|
-
- ✅ **Multi-Adapter Support**: USB and Serial
|
|
378
|
-
- ✅ **Rich Feature Set**: Text, images, barcodes, formatting
|
|
379
|
-
- ✅ **Excellent Documentation**: Comprehensive guides and examples
|
|
380
|
-
- ✅ **Production Ready**: Stable, tested, and maintained
|
|
381
|
-
|
|
382
|
-
The library is ready for production use and provides a solid foundation for thermal printer integration in Node.js applications.
|
|
383
|
-
|