@phystack/thermal-printer 4.3.40-dev
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/CHANGELOG.md +465 -0
- package/README.md +120 -0
- package/dist/index.d.ts +87 -0
- package/dist/index.js +93 -0
- package/dist/index.js.map +1 -0
- package/package.json +33 -0
- package/src/index.ts +146 -0
- package/tsconfig.json +19 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
## 3.92.13 (2024-05-30)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* refactored ga-messaging ([0f1b527](https://github.com/ombori/gridapp/commit/0f1b527e66150611fd31f4cea72f10ee56503198))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## 3.92.12 (2024-05-29)
|
|
18
|
+
|
|
19
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## 3.92.11 (2024-05-26)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Bug Fixes
|
|
29
|
+
|
|
30
|
+
* scanner ([0550883](https://github.com/ombori/gridapp/commit/05508835d802344500028f297f4e0c3f25411aaa))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
## 3.92.10 (2024-05-25)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Bug Fixes
|
|
40
|
+
|
|
41
|
+
* reconnect ([5b8adac](https://github.com/ombori/gridapp/commit/5b8adacae1041fde922222da46b141e9eaee456f))
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
## 3.92.9 (2024-05-25)
|
|
48
|
+
|
|
49
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
## 3.92.8 (2024-05-24)
|
|
56
|
+
|
|
57
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
## 3.92.7 (2024-05-24)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
### Bug Fixes
|
|
67
|
+
|
|
68
|
+
* ver ([a6b8c30](https://github.com/ombori/gridapp/commit/a6b8c307d841d1cd4f0574b754b29d06724002dd))
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## 3.92.6 (2024-05-24)
|
|
75
|
+
|
|
76
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
## 3.92.5 (2024-05-20)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
### Bug Fixes
|
|
86
|
+
|
|
87
|
+
* exit if it can not connect to phyedged timeout 2 ([ad402af](https://github.com/ombori/gridapp/commit/ad402af91d8a75f56578dbe9ad41b98e09ddbb3a))
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
## 3.92.4 (2024-05-20)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
### Bug Fixes
|
|
97
|
+
|
|
98
|
+
* exit if it can not connect to phyedged timeout ([c45ca4a](https://github.com/ombori/gridapp/commit/c45ca4ae63ceba6773ef8d301db5e51f74fbda80))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
## 3.92.3 (2024-05-20)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
### Bug Fixes
|
|
108
|
+
|
|
109
|
+
* throw an error it connection fails ([5f61fc8](https://github.com/ombori/gridapp/commit/5f61fc8c4546a8c202128a023951288fc67e1bb4))
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
## 3.92.2 (2024-05-16)
|
|
116
|
+
|
|
117
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
## 3.92.1 (2024-05-16)
|
|
124
|
+
|
|
125
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
# 3.92.0 (2024-05-15)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
### Features
|
|
135
|
+
|
|
136
|
+
* data matrix data source type ([bc47310](https://github.com/ombori/gridapp/commit/bc47310fec84b9fcf7b22a4d5261f7053f8877bd))
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
## 3.91.13 (2024-05-14)
|
|
143
|
+
|
|
144
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
## 3.91.12 (2024-05-14)
|
|
151
|
+
|
|
152
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
## 3.91.11 (2024-05-14)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
### Bug Fixes
|
|
162
|
+
|
|
163
|
+
* new docker buildx local tag 2 ([4b63c84](https://github.com/ombori/gridapp/commit/4b63c8408ddb0264ced7a026f2658547f4fb2bba))
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
## 3.91.10 (2024-05-14)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
### Bug Fixes
|
|
173
|
+
|
|
174
|
+
* new docker buildx local tag ([084f1a9](https://github.com/ombori/gridapp/commit/084f1a923ae16cd978d7a3a84036cf81ca07748a))
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
## 3.91.9 (2024-05-12)
|
|
181
|
+
|
|
182
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
## 3.91.8 (2024-05-12)
|
|
189
|
+
|
|
190
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
## 3.91.7 (2024-05-11)
|
|
197
|
+
|
|
198
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
## 3.91.6 (2024-05-03)
|
|
205
|
+
|
|
206
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
## 3.91.5 (2024-04-16)
|
|
213
|
+
|
|
214
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
|
|
220
|
+
## 3.91.4 (2024-04-15)
|
|
221
|
+
|
|
222
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
## 3.91.3 (2024-04-15)
|
|
229
|
+
|
|
230
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
231
|
+
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
## 3.91.2 (2024-04-15)
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
### Reverts
|
|
240
|
+
|
|
241
|
+
* format changes ([ac616fe](https://github.com/ombori/gridapp/commit/ac616feeaf79f3a57123cad0c87868b17880c635))
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
## 3.91.1 (2024-04-08)
|
|
248
|
+
|
|
249
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
# 3.91.0 (2024-04-08)
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
### Features
|
|
259
|
+
|
|
260
|
+
* override ai assistants ([1519ed6](https://github.com/ombori/gridapp/commit/1519ed6d3fdfafdc99a521c91e9efd1348dc976b))
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
## 3.90.12 (2024-03-14)
|
|
267
|
+
|
|
268
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
## 3.90.11 (2024-03-14)
|
|
275
|
+
|
|
276
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
## 3.90.10 (2024-03-11)
|
|
283
|
+
|
|
284
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
## 3.90.9 (2024-03-11)
|
|
291
|
+
|
|
292
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
## 3.90.8 (2024-03-11)
|
|
299
|
+
|
|
300
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
## 3.90.7 (2024-03-11)
|
|
307
|
+
|
|
308
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
## 3.90.6 (2024-03-08)
|
|
315
|
+
|
|
316
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
## 3.90.5 (2024-03-07)
|
|
323
|
+
|
|
324
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
325
|
+
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
## 3.90.3 (2024-03-07)
|
|
331
|
+
|
|
332
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
333
|
+
|
|
334
|
+
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
## 3.90.2 (2024-03-07)
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
### Bug Fixes
|
|
342
|
+
|
|
343
|
+
* update yarn.lock ([c68966c](https://github.com/ombori/gridapp/commit/c68966c4aaa68e9e217716723db0e3ed09d559f2))
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
|
|
349
|
+
## 3.90.1 (2024-03-06)
|
|
350
|
+
|
|
351
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
## [3.51.4](https://github.com/ombori/gridapp/compare/v3.51.0...v3.51.4) (2023-07-06)
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
### Bug Fixes
|
|
361
|
+
|
|
362
|
+
* revert node thermal printer dep version for now ([7a5188f](https://github.com/ombori/gridapp/commit/7a5188fbf78165eb1b5a6719288aaff84c3fa215))
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
# [3.51.0](https://github.com/ombori/gridapp/compare/v3.50.0...v3.51.0) (2023-07-05)
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
### Features
|
|
372
|
+
|
|
373
|
+
* printer fix ([10798b6](https://github.com/ombori/gridapp/commit/10798b67addf482bc03b0044cd6882989f6747bf))
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
# [2.57.0](https://github.com/ombori/gridapp/compare/v2.56.1...v2.57.0) (2021-05-04)
|
|
380
|
+
|
|
381
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
|
|
387
|
+
## [2.56.1](https://github.com/ombori/gridapp/compare/v2.56.0...v2.56.1) (2021-05-04)
|
|
388
|
+
|
|
389
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
# [2.56.0](https://github.com/ombori/gridapp/compare/v2.55.5...v2.56.0) (2021-05-04)
|
|
396
|
+
|
|
397
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
## [2.55.5](https://github.com/ombori/gridapp/compare/v2.55.4...v2.55.5) (2021-05-03)
|
|
404
|
+
|
|
405
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
## [2.55.4](https://github.com/ombori/gridapp/compare/v2.55.3...v2.55.4) (2021-05-03)
|
|
412
|
+
|
|
413
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
|
|
419
|
+
## [2.55.3](https://github.com/ombori/gridapp/compare/v2.55.2...v2.55.3) (2021-05-03)
|
|
420
|
+
|
|
421
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
422
|
+
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
|
|
426
|
+
|
|
427
|
+
## [2.55.2](https://github.com/ombori/gridapp/compare/v2.55.1...v2.55.2) (2021-04-30)
|
|
428
|
+
|
|
429
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
|
|
434
|
+
|
|
435
|
+
## [2.55.1](https://github.com/ombori/gridapp/compare/v2.55.0...v2.55.1) (2021-04-30)
|
|
436
|
+
|
|
437
|
+
**Note:** Version bump only for package @ombori/ga-thermal-printer
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
|
|
443
|
+
## [1.7.6](https://github.com/ombori/gridapp/compare/v1.7.5...v1.7.6) (2020-07-24)
|
|
444
|
+
|
|
445
|
+
|
|
446
|
+
### Bug Fixes
|
|
447
|
+
|
|
448
|
+
* websocket ([0579fa8](https://github.com/ombori/gridapp/commit/0579fa850fda2fd565db161490151a2a0e2800b0))
|
|
449
|
+
|
|
450
|
+
|
|
451
|
+
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
# [1.6.0](https://github.com/ombori/gridapp/compare/v1.5.15...v1.6.0) (2020-07-22)
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
### Bug Fixes
|
|
458
|
+
|
|
459
|
+
* lockfiles, thermal printer deps, build ([b5e98d3](https://github.com/ombori/gridapp/commit/b5e98d349084ac1f7dbc752b338bc5f92af3599e))
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
### Features
|
|
463
|
+
|
|
464
|
+
* new printer lib ([f5ab584](https://github.com/ombori/gridapp/commit/f5ab58438fd3d3a1eb62ecf0ded1893b7ac8f9b7))
|
|
465
|
+
* working printer integration ([6486e55](https://github.com/ombori/gridapp/commit/6486e557a0fc68e1353ded8cce4350b200cf9af4))
|
package/README.md
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# @phystack/thermal-printer
|
|
2
|
+
|
|
3
|
+
A Node.js library for interfacing with thermal printers in the Phygrid ecosystem.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
```bash
|
|
7
|
+
npm install @phystack/thermal-printer
|
|
8
|
+
```
|
|
9
|
+
or
|
|
10
|
+
```bash
|
|
11
|
+
yarn add @phystack/thermal-printer
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
## Usage
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { ThermalPrinter } from '@phystack/thermal-printer';
|
|
18
|
+
import { PeripheralInstance } from '@phystack/hub-client';
|
|
19
|
+
// Initialize with a peripheral instance
|
|
20
|
+
const printer = new ThermalPrinter(peripheralInstance);
|
|
21
|
+
// Add text with formatting options
|
|
22
|
+
printer.addText('Hello World!', {
|
|
23
|
+
align: 'center',
|
|
24
|
+
size: { width: 2, height: 2 },
|
|
25
|
+
bold: true
|
|
26
|
+
});
|
|
27
|
+
// Add a QR code
|
|
28
|
+
printer.addQR('https://example.com', {
|
|
29
|
+
size: 8,
|
|
30
|
+
correction: 'H'
|
|
31
|
+
});
|
|
32
|
+
// Add a barcode
|
|
33
|
+
printer.addBarcode('123456789012', 'CODE128', {
|
|
34
|
+
width: 2,
|
|
35
|
+
height: 100
|
|
36
|
+
});
|
|
37
|
+
// Print everything
|
|
38
|
+
await printer.print();
|
|
39
|
+
```
|
|
40
|
+
## API Reference
|
|
41
|
+
|
|
42
|
+
### `ThermalPrinter`
|
|
43
|
+
|
|
44
|
+
#### Constructor
|
|
45
|
+
|
|
46
|
+
typescript
|
|
47
|
+
constructor(peripheral: PeripheralInstance)
|
|
48
|
+
|
|
49
|
+
#### Methods
|
|
50
|
+
|
|
51
|
+
##### `addText(content: string, options?: PrinterOperationOptions)`
|
|
52
|
+
Add text to be printed with optional formatting.
|
|
53
|
+
|
|
54
|
+
Options:
|
|
55
|
+
- `align`: 'left' | 'center' | 'right'
|
|
56
|
+
- `size`: { width: 1 | 2, height: 1 | 2 }
|
|
57
|
+
- `bold`: boolean
|
|
58
|
+
- `underline`: boolean
|
|
59
|
+
|
|
60
|
+
##### `addQR(content: string, options?: QROptions)`
|
|
61
|
+
Add a QR code to be printed.
|
|
62
|
+
|
|
63
|
+
Options:
|
|
64
|
+
- `model`: 1 | 2 | 3
|
|
65
|
+
- `size`: 1 to 8
|
|
66
|
+
- `correction`: 'L' | 'M' | 'Q' | 'H'
|
|
67
|
+
|
|
68
|
+
##### `addBarcode(content: string, type?: BarcodeType, options?: BarcodeOptions)`
|
|
69
|
+
Add a barcode to be printed.
|
|
70
|
+
|
|
71
|
+
Supported types:
|
|
72
|
+
- 'UPC-E'
|
|
73
|
+
- 'UPC-A'
|
|
74
|
+
- 'JAN/EAN8'
|
|
75
|
+
- 'JAN/EAN13'
|
|
76
|
+
- 'Code39'
|
|
77
|
+
- 'ITF'
|
|
78
|
+
- 'CODE128'
|
|
79
|
+
- 'CODE93'
|
|
80
|
+
- 'NW-7'
|
|
81
|
+
|
|
82
|
+
Options:
|
|
83
|
+
- `width`: number
|
|
84
|
+
- `height`: number
|
|
85
|
+
|
|
86
|
+
##### `clear()`
|
|
87
|
+
Clear all pending operations.
|
|
88
|
+
|
|
89
|
+
##### `print()`
|
|
90
|
+
Print all queued operations and clear the queue.
|
|
91
|
+
|
|
92
|
+
##### `build()`
|
|
93
|
+
Generate the final payload without printing.
|
|
94
|
+
|
|
95
|
+
## Example
|
|
96
|
+
```ts
|
|
97
|
+
import { ThermalPrinter } from '@phystack/thermal-printer';
|
|
98
|
+
// Assuming you have a peripheral instance
|
|
99
|
+
const printer = new ThermalPrinter(peripheralInstance);
|
|
100
|
+
// Create a receipt
|
|
101
|
+
printer
|
|
102
|
+
.addText('SALES RECEIPT', {
|
|
103
|
+
align: 'center',
|
|
104
|
+
size: { width: 2, height: 2 },
|
|
105
|
+
bold: true
|
|
106
|
+
})
|
|
107
|
+
.addText('\n')
|
|
108
|
+
.addText('Thank you for your purchase!', {
|
|
109
|
+
align: 'center'
|
|
110
|
+
})
|
|
111
|
+
.addText('\n')
|
|
112
|
+
.addBarcode('123456789012', 'CODE128')
|
|
113
|
+
.addText('\n')
|
|
114
|
+
.addQR('https://example.com');
|
|
115
|
+
// Print it
|
|
116
|
+
await printer.print();
|
|
117
|
+
```
|
|
118
|
+
## Dependencies
|
|
119
|
+
|
|
120
|
+
- @phystack/hub-client
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { PeripheralInstance } from '@phystack/hub-client';
|
|
2
|
+
declare const ALIGNMENTS: {
|
|
3
|
+
readonly left: "left";
|
|
4
|
+
readonly center: "center";
|
|
5
|
+
readonly right: "right";
|
|
6
|
+
};
|
|
7
|
+
export interface PrinterOperationOptions {
|
|
8
|
+
align?: keyof typeof ALIGNMENTS;
|
|
9
|
+
size?: {
|
|
10
|
+
width: 1 | 2;
|
|
11
|
+
height: 1 | 2;
|
|
12
|
+
};
|
|
13
|
+
bold?: boolean;
|
|
14
|
+
underline?: boolean;
|
|
15
|
+
qr?: {
|
|
16
|
+
model?: 1 | 2 | 3;
|
|
17
|
+
size?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
18
|
+
correction?: 'L' | 'M' | 'Q' | 'H';
|
|
19
|
+
};
|
|
20
|
+
barcode?: {
|
|
21
|
+
type: 'UPC-E' | 'UPC-A' | 'JAN/EAN8' | 'JAN/EAN13' | 'Code39' | 'ITF' | 'CODE128' | 'CODE93' | 'NW-7';
|
|
22
|
+
width?: number;
|
|
23
|
+
height?: number;
|
|
24
|
+
};
|
|
25
|
+
image?: {
|
|
26
|
+
width?: number;
|
|
27
|
+
height?: number;
|
|
28
|
+
align?: keyof typeof ALIGNMENTS;
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
export interface PrinterOperation {
|
|
32
|
+
type: 'text' | 'qr' | 'barcode' | 'image' | 'raw';
|
|
33
|
+
content: string | Buffer;
|
|
34
|
+
options?: PrinterOperationOptions;
|
|
35
|
+
}
|
|
36
|
+
export interface PrinterPayload {
|
|
37
|
+
operations: Array<{
|
|
38
|
+
type: string;
|
|
39
|
+
content: string | Buffer;
|
|
40
|
+
options?: any;
|
|
41
|
+
}>;
|
|
42
|
+
}
|
|
43
|
+
export declare class ThermalPrinter {
|
|
44
|
+
private operations;
|
|
45
|
+
private peripheral;
|
|
46
|
+
constructor(peripheral: PeripheralInstance);
|
|
47
|
+
/**
|
|
48
|
+
* Add text to be printed
|
|
49
|
+
*/
|
|
50
|
+
addText(content: string, options?: PrinterOperationOptions): this;
|
|
51
|
+
/**
|
|
52
|
+
* Add a QR code to be printed
|
|
53
|
+
*/
|
|
54
|
+
addQR(content: string, options?: PrinterOperationOptions['qr']): this;
|
|
55
|
+
/**
|
|
56
|
+
* Add a barcode to be printed
|
|
57
|
+
*/
|
|
58
|
+
addBarcode(content: string, type?: 'UPC-E' | 'UPC-A' | 'JAN/EAN8' | 'JAN/EAN13' | 'Code39' | 'ITF' | 'CODE128' | 'CODE93' | 'NW-7', options?: {
|
|
59
|
+
width?: number;
|
|
60
|
+
height?: number;
|
|
61
|
+
}): this;
|
|
62
|
+
/**
|
|
63
|
+
* Add image to be printed
|
|
64
|
+
*/
|
|
65
|
+
addImage(content: string | Buffer, options?: {
|
|
66
|
+
width?: number;
|
|
67
|
+
height?: number;
|
|
68
|
+
align?: keyof typeof ALIGNMENTS;
|
|
69
|
+
}): this;
|
|
70
|
+
/**
|
|
71
|
+
* Add raw data to be printed
|
|
72
|
+
*/
|
|
73
|
+
addRawData(content: string | Buffer): this;
|
|
74
|
+
/**
|
|
75
|
+
* Generate the final payload
|
|
76
|
+
*/
|
|
77
|
+
build(): PrinterPayload;
|
|
78
|
+
/**
|
|
79
|
+
* Clear all operations
|
|
80
|
+
*/
|
|
81
|
+
clear(): this;
|
|
82
|
+
/**
|
|
83
|
+
* Print the operations
|
|
84
|
+
*/
|
|
85
|
+
print(): Promise<void>;
|
|
86
|
+
}
|
|
87
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ThermalPrinter = void 0;
|
|
4
|
+
const ALIGNMENTS = {
|
|
5
|
+
'left': 'left',
|
|
6
|
+
'center': 'center',
|
|
7
|
+
'right': 'right'
|
|
8
|
+
};
|
|
9
|
+
class ThermalPrinter {
|
|
10
|
+
constructor(peripheral) {
|
|
11
|
+
this.operations = [];
|
|
12
|
+
this.peripheral = peripheral;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Add text to be printed
|
|
16
|
+
*/
|
|
17
|
+
addText(content, options) {
|
|
18
|
+
this.operations.push({
|
|
19
|
+
type: 'text',
|
|
20
|
+
content,
|
|
21
|
+
options,
|
|
22
|
+
});
|
|
23
|
+
return this;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Add a QR code to be printed
|
|
27
|
+
*/
|
|
28
|
+
addQR(content, options) {
|
|
29
|
+
this.operations.push({
|
|
30
|
+
type: 'qr',
|
|
31
|
+
content,
|
|
32
|
+
options: { qr: options },
|
|
33
|
+
});
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Add a barcode to be printed
|
|
38
|
+
*/
|
|
39
|
+
addBarcode(content, type = 'CODE128', options) {
|
|
40
|
+
this.operations.push({
|
|
41
|
+
type: 'barcode',
|
|
42
|
+
content,
|
|
43
|
+
options: { barcode: { type, ...options } },
|
|
44
|
+
});
|
|
45
|
+
return this;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Add image to be printed
|
|
49
|
+
*/
|
|
50
|
+
addImage(content, options) {
|
|
51
|
+
this.operations.push({
|
|
52
|
+
type: 'image',
|
|
53
|
+
content,
|
|
54
|
+
options: { image: { ...options } },
|
|
55
|
+
});
|
|
56
|
+
return this;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Add raw data to be printed
|
|
60
|
+
*/
|
|
61
|
+
addRawData(content) {
|
|
62
|
+
this.operations.push({
|
|
63
|
+
type: 'raw',
|
|
64
|
+
content
|
|
65
|
+
});
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Generate the final payload
|
|
70
|
+
*/
|
|
71
|
+
build() {
|
|
72
|
+
return {
|
|
73
|
+
operations: this.operations,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Clear all operations
|
|
78
|
+
*/
|
|
79
|
+
clear() {
|
|
80
|
+
this.operations = [];
|
|
81
|
+
return this;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Print the operations
|
|
85
|
+
*/
|
|
86
|
+
print() {
|
|
87
|
+
const operations = this.build();
|
|
88
|
+
this.clear();
|
|
89
|
+
return Promise.resolve(this.peripheral.emit('PRINT', operations));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.ThermalPrinter = ThermalPrinter;
|
|
93
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAEA,MAAM,UAAU,GAAG;IACjB,MAAM,EAAE,MAAM;IACd,QAAQ,EAAE,QAAQ;IAClB,OAAO,EAAE,OAAO;CACR,CAAC;AAyCX,MAAa,cAAc;IAIzB,YAAY,UAA8B;QAHlC,eAAU,GAAuB,EAAE,CAAC;QAI1C,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;IAC/B,CAAC;IAED;;OAEG;IACH,OAAO,CAAC,OAAe,EAAE,OAAiC;QACxD,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YACnB,IAAI,EAAE,MAAM;YACZ,OAAO;YACP,OAAO;SACR,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAe,EAAE,OAAuC;QAC5D,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YACnB,IAAI,EAAE,IAAI;YACV,OAAO;YACP,OAAO,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE;SACzB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,UAAU,CACR,OAAe,EACf,OAAwG,SAAS,EACjH,OAA6C;QAE7C,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YACnB,IAAI,EAAE,SAAS;YACf,OAAO;YACP,OAAO,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,EAAE;SAC3C,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IAEH,QAAQ,CAAC,OAAwB,EAAE,OAA8E;QAC/G,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YACnB,IAAI,EAAE,OAAO;YACb,OAAO;YACP,OAAO,EAAC,EAAE,KAAK,EAAE,EAAE,GAAG,OAAO,EAAE,EAAE;SAClC,CAAC,CAAA;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IAEH,UAAU,CAAC,OAAwB;QACjC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;YACnB,IAAI,EAAE,KAAK;YACX,OAAO;SACR,CAAC,CAAA;QACF,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO;YACL,UAAU,EAAE,IAAI,CAAC,UAAU;SAC5B,CAAC;IACJ,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,UAAU,GAAG,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;OAEG;IACH,KAAK;QACH,MAAM,UAAU,GAAG,IAAI,CAAC,KAAK,EAAE,CAAC;QAChC,IAAI,CAAC,KAAK,EAAE,CAAC;QACb,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC,CAAC;IACpE,CAAC;CACF;AAlGD,wCAkGC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@phystack/thermal-printer",
|
|
3
|
+
"version": "4.3.40-dev",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"publishConfig": {
|
|
7
|
+
"access": "public"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"start": "tsnd --respawn src/index.ts",
|
|
11
|
+
"build": "rimraf dist && tsc"
|
|
12
|
+
},
|
|
13
|
+
"babel": {
|
|
14
|
+
"presets": [
|
|
15
|
+
"@babel/preset-env",
|
|
16
|
+
"@babel/preset-react"
|
|
17
|
+
],
|
|
18
|
+
"plugins": [
|
|
19
|
+
"@babel/plugin-proposal-class-properties"
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@phystack/hub-client": "4.3.40-dev"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/node": "^14.0.13",
|
|
27
|
+
"@types/testing-library__dom": "^7.5.0",
|
|
28
|
+
"@types/testing-library__jest-dom": "^5.9.1",
|
|
29
|
+
"ts-node-dev": "^1.0.0-pre.49",
|
|
30
|
+
"typescript": "^5.4.5"
|
|
31
|
+
},
|
|
32
|
+
"gitHead": "53c505b3ecad47ebd4f38819c07b0ec1227214a6"
|
|
33
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { PeripheralInstance } from '@phystack/hub-client';
|
|
2
|
+
|
|
3
|
+
const ALIGNMENTS = {
|
|
4
|
+
'left': 'left',
|
|
5
|
+
'center': 'center',
|
|
6
|
+
'right': 'right'
|
|
7
|
+
} as const;
|
|
8
|
+
|
|
9
|
+
export interface PrinterOperationOptions {
|
|
10
|
+
align?: keyof typeof ALIGNMENTS;
|
|
11
|
+
size?: {
|
|
12
|
+
width: 1 | 2;
|
|
13
|
+
height: 1 | 2;
|
|
14
|
+
};
|
|
15
|
+
bold?: boolean;
|
|
16
|
+
underline?: boolean;
|
|
17
|
+
qr?: {
|
|
18
|
+
model?: 1 | 2 | 3;
|
|
19
|
+
size?: 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8;
|
|
20
|
+
correction?: 'L' | 'M' | 'Q' | 'H';
|
|
21
|
+
};
|
|
22
|
+
barcode?: {
|
|
23
|
+
type: 'UPC-E' | 'UPC-A' | 'JAN/EAN8' | 'JAN/EAN13' | 'Code39' | 'ITF' | 'CODE128' | 'CODE93' | 'NW-7';
|
|
24
|
+
width?: number;
|
|
25
|
+
height?: number;
|
|
26
|
+
};
|
|
27
|
+
image?: {
|
|
28
|
+
width?: number;
|
|
29
|
+
height?: number;
|
|
30
|
+
align?: keyof typeof ALIGNMENTS;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export interface PrinterOperation {
|
|
35
|
+
type: 'text' | 'qr' | 'barcode' | 'image' | 'raw';
|
|
36
|
+
content: string | Buffer;
|
|
37
|
+
options?: PrinterOperationOptions;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface PrinterPayload {
|
|
41
|
+
operations: Array<{
|
|
42
|
+
type: string;
|
|
43
|
+
content: string | Buffer;
|
|
44
|
+
options?: any;
|
|
45
|
+
}>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export class ThermalPrinter {
|
|
49
|
+
private operations: PrinterOperation[] = [];
|
|
50
|
+
private peripheral: PeripheralInstance;
|
|
51
|
+
|
|
52
|
+
constructor(peripheral: PeripheralInstance) {
|
|
53
|
+
this.peripheral = peripheral;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Add text to be printed
|
|
58
|
+
*/
|
|
59
|
+
addText(content: string, options?: PrinterOperationOptions): this {
|
|
60
|
+
this.operations.push({
|
|
61
|
+
type: 'text',
|
|
62
|
+
content,
|
|
63
|
+
options,
|
|
64
|
+
});
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Add a QR code to be printed
|
|
70
|
+
*/
|
|
71
|
+
addQR(content: string, options?: PrinterOperationOptions['qr']): this {
|
|
72
|
+
this.operations.push({
|
|
73
|
+
type: 'qr',
|
|
74
|
+
content,
|
|
75
|
+
options: { qr: options },
|
|
76
|
+
});
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Add a barcode to be printed
|
|
82
|
+
*/
|
|
83
|
+
addBarcode(
|
|
84
|
+
content: string,
|
|
85
|
+
type: 'UPC-E' | 'UPC-A' | 'JAN/EAN8' | 'JAN/EAN13' | 'Code39' | 'ITF' | 'CODE128' | 'CODE93' | 'NW-7' = 'CODE128',
|
|
86
|
+
options?: { width?: number; height?: number }
|
|
87
|
+
): this {
|
|
88
|
+
this.operations.push({
|
|
89
|
+
type: 'barcode',
|
|
90
|
+
content,
|
|
91
|
+
options: { barcode: { type, ...options } },
|
|
92
|
+
});
|
|
93
|
+
return this;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Add image to be printed
|
|
98
|
+
*/
|
|
99
|
+
|
|
100
|
+
addImage(content: string | Buffer, options?: { width?: number; height?: number,align?: keyof typeof ALIGNMENTS; }): this {
|
|
101
|
+
this.operations.push({
|
|
102
|
+
type: 'image',
|
|
103
|
+
content,
|
|
104
|
+
options:{ image: { ...options } },
|
|
105
|
+
})
|
|
106
|
+
return this;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Add raw data to be printed
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
addRawData(content: string | Buffer): this{
|
|
114
|
+
this.operations.push({
|
|
115
|
+
type: 'raw',
|
|
116
|
+
content
|
|
117
|
+
})
|
|
118
|
+
return this;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Generate the final payload
|
|
123
|
+
*/
|
|
124
|
+
build(): PrinterPayload {
|
|
125
|
+
return {
|
|
126
|
+
operations: this.operations,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Clear all operations
|
|
132
|
+
*/
|
|
133
|
+
clear(): this {
|
|
134
|
+
this.operations = [];
|
|
135
|
+
return this;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Print the operations
|
|
140
|
+
*/
|
|
141
|
+
print(): Promise<void> {
|
|
142
|
+
const operations = this.build();
|
|
143
|
+
this.clear();
|
|
144
|
+
return Promise.resolve(this.peripheral.emit('PRINT', operations));
|
|
145
|
+
}
|
|
146
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"module": "commonjs",
|
|
4
|
+
"esModuleInterop": true,
|
|
5
|
+
"allowSyntheticDefaultImports": true,
|
|
6
|
+
"target": "es2018",
|
|
7
|
+
"noImplicitAny": true,
|
|
8
|
+
"moduleResolution": "node",
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"outDir": "dist",
|
|
11
|
+
"baseUrl": ".",
|
|
12
|
+
"declaration": true,
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"paths": {
|
|
15
|
+
"*": ["node_modules/*", "src/types/*"]
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*"]
|
|
19
|
+
}
|