@@ -139,12 +139,12 @@ Printer.prototype.underline = function(dots){
139
139
140
140
Printer . prototype . small = function ( onOff ) {
141
141
var commands = [ 27 , 33 , ( onOff === true ? 1 : 0 ) ] ;
142
- return this . writeCommands ( commands ) ;
142
+ return this . writeCommands ( commands ) ;
143
143
} ;
144
144
145
145
Printer . prototype . upsideDown = function ( onOff ) {
146
146
var commands = [ 27 , 123 , ( onOff === true ? 1 : 0 ) ] ;
147
- return this . writeCommands ( commands ) ;
147
+ return this . writeCommands ( commands ) ;
148
148
} ;
149
149
150
150
Printer . prototype . inverse = function ( onOff ) {
@@ -249,138 +249,132 @@ Printer.prototype.printImage = function(path) {
249
249
// 1: Above the barcode
250
250
// 2: Below the barcode
251
251
// 3: Both above and below the barcode
252
- Printer . prototype . barcodeTextPosition = function ( pos ) {
253
- var error ;
254
-
255
- if ( pos > 3 || pos < 0 ) {
256
- throw new Error ( 'Position must be 0, 1, 2 or 3' ) ;
257
- }
258
-
259
- var commands = [ 29 , 72 , pos ] ;
260
- return this . writeCommands ( commands ) ;
252
+ Printer . prototype . barcodeTextPosition = function ( pos ) {
253
+ if ( pos > 3 || pos < 0 ) {
254
+ throw new Error ( 'Position must be 0, 1, 2 or 3' ) ;
255
+ }
256
+ var commands = [ 29 , 72 , pos ] ;
257
+ return this . writeCommands ( commands ) ;
261
258
} ;
262
259
263
260
// Set barcode height
264
261
// 0 < h < 255 (default = 50)
265
- Printer . prototype . barcodeHeight = function ( h ) {
266
- if ( h > 255 || h < 0 ) {
267
- throw new Error ( 'Height must be 0 < height > 255' ) ;
268
- }
269
-
270
- var commands = [ 29 , 104 , h ] ;
271
- return this . writeCommands ( commands ) ;
262
+ Printer . prototype . barcodeHeight = function ( h ) {
263
+ if ( h > 255 || h < 0 ) {
264
+ throw new Error ( 'Height must be 0 < height > 255' ) ;
265
+ }
266
+ var commands = [ 29 , 104 , h ] ;
267
+ return this . writeCommands ( commands ) ;
272
268
} ;
273
269
274
270
Printer . BARCODE_CHARSETS = {
275
- NUMS : function ( n ) { return n >= 48 && n <= 57 ; } ,
276
- ASCII : function ( n ) { return n >= 0 && n <= 127 ; }
271
+ NUMS : function ( n ) { return n >= 48 && n <= 57 ; } ,
272
+ ASCII : function ( n ) { return n >= 0 && n <= 127 ; }
277
273
} ;
278
274
279
275
// These are all valid barcode types.
280
276
// Pass this object to printer.barcode() as type:
281
- // printer.barcode(Printer.BARCODE_TYPES.UPCA, " data" );
277
+ // printer.barcode(Printer.BARCODE_TYPES.UPCA, ' data' );
282
278
Printer . BARCODE_TYPES = {
283
- UPCA : {
284
- code : 65 ,
285
- size : function ( n ) { return n == 11 || n == 12 ; } ,
286
- chars : Printer . BARCODE_CHARSETS . NUMS
287
- } ,
288
- UPCE : {
289
- code : 66 ,
290
- size : function ( n ) { return n == 11 || n == 12 ; } ,
291
- chars : Printer . BARCODE_CHARSETS . NUMS
292
- } ,
293
- EAN13 : {
294
- code : 67 ,
295
- size : function ( n ) { return n == 12 || n == 13 ; } ,
296
- chars : Printer . BARCODE_CHARSETS . NUMS
297
- } ,
298
- EAN8 : {
299
- code : 68 ,
300
- size : function ( n ) { return n == 7 || n == 8 ; } ,
301
- chars : Printer . BARCODE_CHARSETS . NUMS
302
- } ,
303
- CODE39 : {
304
- code : 69 ,
305
- size : function ( n ) { return n > 1 ; } ,
306
- chars : function ( n ) {
307
- // " $%+-./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
308
- return (
309
- n == 32 ||
310
- n == 36 ||
311
- n == 37 ||
312
- n == 43 ||
313
- ( n >= 45 && n <= 57 ) ||
314
- ( n >= 65 && n <= 90 )
315
- ) ;
316
- }
317
- } ,
318
- I25 : {
319
- code : 70 ,
320
- size : function ( n ) { return n > 1 && n % 2 === 0 ; } ,
321
- chars : Printer . BARCODE_CHARSETS . NUMS
322
- } ,
323
- CODEBAR : {
324
- code : 71 ,
325
- size : function ( n ) { return n > 1 ; } ,
326
- chars : function ( n ) {
327
- // "$+-./0123456789:ABCD"
328
- return (
329
- n == 36 ||
330
- n == 43 ||
331
- ( n >= 45 && n <= 58 ) ||
332
- ( n >= 65 && n <= 68 )
333
- ) ;
334
- }
335
- } ,
336
- CODE93 : {
337
- code : 72 ,
338
- size : function ( n ) { return n > 1 ; } ,
339
- chars : Printer . BARCODE_CHARSETS . ASCII
340
- } ,
341
- CODE128 : {
342
- code : 73 ,
343
- size : function ( n ) { return n > 1 ; } ,
344
- chars : Printer . BARCODE_CHARSETS . ASCII
345
- } ,
346
- CODE11 : {
347
- code : 74 ,
348
- size : function ( n ) { return n > 1 ; } ,
349
- chars : Printer . BARCODE_CHARSETS . NUMS
350
- } ,
351
- MSI : {
352
- code : 75 ,
353
- size : function ( n ) { return n > 1 ; } ,
354
- chars : Printer . BARCODE_CHARSETS . NUMS
355
- }
279
+ UPCA : {
280
+ code : 65 ,
281
+ size : function ( n ) { return n === 11 || n = == 12 ; } ,
282
+ chars : Printer . BARCODE_CHARSETS . NUMS
283
+ } ,
284
+ UPCE : {
285
+ code : 66 ,
286
+ size : function ( n ) { return n === 11 || n = == 12 ; } ,
287
+ chars : Printer . BARCODE_CHARSETS . NUMS
288
+ } ,
289
+ EAN13 : {
290
+ code : 67 ,
291
+ size : function ( n ) { return n === 12 || n = == 13 ; } ,
292
+ chars : Printer . BARCODE_CHARSETS . NUMS
293
+ } ,
294
+ EAN8 : {
295
+ code : 68 ,
296
+ size : function ( n ) { return n === 7 || n = == 8 ; } ,
297
+ chars : Printer . BARCODE_CHARSETS . NUMS
298
+ } ,
299
+ CODE39 : {
300
+ code : 69 ,
301
+ size : function ( n ) { return n > 1 ; } ,
302
+ chars : function ( n ) {
303
+ // " $%+-./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
304
+ return (
305
+ n = == 32 ||
306
+ n = == 36 ||
307
+ n = == 37 ||
308
+ n = == 43 ||
309
+ ( n >= 45 && n <= 57 ) ||
310
+ ( n >= 65 && n <= 90 )
311
+ ) ;
312
+ }
313
+ } ,
314
+ I25 : {
315
+ code : 70 ,
316
+ size : function ( n ) { return n > 1 && n % 2 === 0 ; } ,
317
+ chars : Printer . BARCODE_CHARSETS . NUMS
318
+ } ,
319
+ CODEBAR : {
320
+ code : 71 ,
321
+ size : function ( n ) { return n > 1 ; } ,
322
+ chars : function ( n ) {
323
+ // "$+-./0123456789:ABCD"
324
+ return (
325
+ n = == 36 ||
326
+ n = == 43 ||
327
+ ( n >= 45 && n <= 58 ) ||
328
+ ( n >= 65 && n <= 68 )
329
+ ) ;
330
+ }
331
+ } ,
332
+ CODE93 : {
333
+ code : 72 ,
334
+ size : function ( n ) { return n > 1 ; } ,
335
+ chars : Printer . BARCODE_CHARSETS . ASCII
336
+ } ,
337
+ CODE128 : {
338
+ code : 73 ,
339
+ size : function ( n ) { return n > 1 ; } ,
340
+ chars : Printer . BARCODE_CHARSETS . ASCII
341
+ } ,
342
+ CODE11 : {
343
+ code : 74 ,
344
+ size : function ( n ) { return n > 1 ; } ,
345
+ chars : Printer . BARCODE_CHARSETS . NUMS
346
+ } ,
347
+ MSI : {
348
+ code : 75 ,
349
+ size : function ( n ) { return n > 1 ; } ,
350
+ chars : Printer . BARCODE_CHARSETS . NUMS
351
+ }
356
352
} ;
357
353
358
- Printer . prototype . barcode = function ( type , data ) {
354
+ Printer . prototype . barcode = function ( type , data ) {
359
355
var error ;
360
- var commands = [ 29 , 107 ] ;
361
- commands . push ( type . code ) ;
362
- commands . push ( data . length ) ;
363
-
364
- // Validate size
365
- if ( ! type . size ( data . length ) ) {
366
- error = new Error ( 'Data length does not match specification for this type of barcode' ) ;
367
- error . name = "invalid_data_size" ;
368
- throw error ;
369
- }
370
-
371
- for ( var i = 0 ; i < data . length ; i ++ ) {
372
- var code = data . charCodeAt ( i ) ;
373
- if ( ! type . chars ( code ) ) {
374
- error = new Error ( 'Character ' + code + ' is not valid for this type of barcode' ) ;
375
- error . name = "invalid_character" ;
376
- error . char = code ;
377
- throw error ;
378
- }
379
-
380
- commands . push ( code ) ;
381
- }
382
-
383
- return this . writeCommands ( commands ) ;
356
+ var commands = [ 29 , 107 ] ;
357
+ commands . push ( type . code ) ;
358
+ commands . push ( data . length ) ;
359
+
360
+ // Validate size
361
+ if ( ! type . size ( data . length ) ) {
362
+ error = new Error ( 'Data length does not match specification for this type of barcode' ) ;
363
+ error . name = "invalid_data_size" ;
364
+ throw error ;
365
+ }
366
+ // validate that the chars to be printed are supported for this type of barcode
367
+ for ( var i = 0 ; i < data . length ; i ++ ) {
368
+ var code = data . charCodeAt ( i ) ;
369
+ if ( ! type . chars ( code ) ) {
370
+ error = new Error ( 'Character ' + code + ' is not valid for this type of barcode' ) ;
371
+ error . name = "invalid_character" ;
372
+ error . char = code ;
373
+ throw error ;
374
+ }
375
+ commands . push ( code ) ;
376
+ }
377
+ return this . writeCommands ( commands ) ;
384
378
} ;
385
379
386
380
module . exports = Printer ;
0 commit comments