Skip to content

Commit 138db9e

Browse files
committed
Some indent correction
1 parent 53ec93b commit 138db9e

File tree

3 files changed

+155
-120
lines changed

3 files changed

+155
-120
lines changed

demo/barcode.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
var SerialPort = require('serialport').SerialPort,
2+
serialPort = new SerialPort('/dev/ttyUSB0', {
3+
baudrate: 19200
4+
}),
5+
Printer = require('../src/printer'),
6+
twitter = require('ntwitter');
7+
8+
serialPort.on('open',function() {
9+
var printer = new Printer(serialPort);
10+
printer.on('ready', function() {
11+
printer
12+
.barcodeTextPosition(2)
13+
.barcodeHeight(255)
14+
.printLine('UPCA')
15+
.barcode(Printer.BARCODE_TYPES.UPCA, '012345678911')
16+
.printLine('UPCE')
17+
.barcode(Printer.BARCODE_TYPES.UPCE, '012345678911')
18+
.printLine('EAN13')
19+
.barcode(Printer.BARCODE_TYPES.EAN13, '012345678911')
20+
.printLine('EAN8')
21+
.barcode(Printer.BARCODE_TYPES.EAN8, '01234567')
22+
.printLine('CODE39')
23+
.barcode(Printer.BARCODE_TYPES.CODE39, '012345678911')
24+
.printLine('I25')
25+
.barcode(Printer.BARCODE_TYPES.I25, '012345')
26+
.printLine('CODEBAR')
27+
.barcode(Printer.BARCODE_TYPES.CODEBAR, '012345678911')
28+
.printLine('CODE93')
29+
.barcode(Printer.BARCODE_TYPES.CODE93, '012345678911')
30+
.printLine('CODE128')
31+
.barcode(Printer.BARCODE_TYPES.CODE128, '012345678911')
32+
.printLine('CODE11')
33+
.barcode(Printer.BARCODE_TYPES.CODE11, '012345678911')
34+
.printLine('MSI')
35+
.barcode(Printer.BARCODE_TYPES.MSI, '012345678911')
36+
.print(function() {
37+
console.log('done');
38+
process.exit();
39+
});
40+
});
41+
});

demo/tweetPrint.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var twitterClient = new twitter({
2323
serialPort.on('open',function() {
2424
var printer = new Printer(serialPort);
2525
printer.on('ready', function() {
26-
twitterClient.stream('statuses/filter', {track: ['#nodejs']}, function(stream) {
26+
twitterClient.stream('statuses/filter', {track: ['#fun']}, function(stream) {
2727
stream.on('data', function (data) {
2828
printer.printLine(data.text).lineFeed(3).print(function() {
2929
console.log(data);

src/printer.js

+113-119
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ Printer.prototype.underline = function(dots){
139139

140140
Printer.prototype.small = function(onOff){
141141
var commands = [27, 33, (onOff === true ? 1 : 0)];
142-
return this.writeCommands(commands);
142+
return this.writeCommands(commands);
143143
};
144144

145145
Printer.prototype.upsideDown = function(onOff){
146146
var commands = [27, 123, (onOff === true ? 1 : 0)];
147-
return this.writeCommands(commands);
147+
return this.writeCommands(commands);
148148
};
149149

150150
Printer.prototype.inverse = function (onOff) {
@@ -249,138 +249,132 @@ Printer.prototype.printImage = function(path) {
249249
// 1: Above the barcode
250250
// 2: Below the barcode
251251
// 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);
261258
};
262259

263260
// Set barcode height
264261
// 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);
272268
};
273269

274270
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; }
277273
};
278274

279275
// These are all valid barcode types.
280276
// Pass this object to printer.barcode() as type:
281-
// printer.barcode(Printer.BARCODE_TYPES.UPCA, "data");
277+
// printer.barcode(Printer.BARCODE_TYPES.UPCA, 'data');
282278
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+
}
356352
};
357353

358-
Printer.prototype.barcode = function(type, data){
354+
Printer.prototype.barcode = function(type, data) {
359355
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);
384378
};
385379

386380
module.exports = Printer;

0 commit comments

Comments
 (0)