README
npos
A ESC/POS library for node
Installation
$ npm install --save npos
Parser
Parse ESC/POS binary buffer.
parse
var npos = require('npos');
var parser = npos.parser();
var buffer = fs.readFileSync('sample.bin');
parser.parse(buffer).then(function (ast) {
console.log(ast);
});
The ast
form parse
is like:
{
raw: <Buffer ...>,
error: <error>,
tree: [
{
code: 27, // command code in decimal
hex: '1B', // command code in hex
ascii: 'ESC', // command code in ascii name
offset: 0, // data offset from buffer
length: 2, // data length
fn: '@', // command fn charater
},
....
],
entries: [ // decoded entries
{
type: 'raster',
nodes: [ // nodes handled by codec from ast
...
],
data: <Object> // data decoded by codec
},
...
]
}
rules
rules
is used to parse esc/pos binary to ast tree.
Example rules:
var npos = require('npos');
var rules = {};
rules[npos.ESC] = { // 'ESC' commands
'!': 1, // 'ESC !' command. Swallow one parameter byte
'