ltsv 
LTSV parser and formatter
Installation
$ npm install ltsv
Usage
var ltsv = require('ltsv');
ltsv.parse([
'label1:value1\tlabel2:value2',
'label1:value1\tlabel2:value2',
'label1:value1\tlabel2:value2'
].join('\n'));
ltsv.parseLine('label1:value1\tlabel2:value2');
ltsv.parseLine('label1:value1\tlabel2:value2\n');
ltsv.parseLine('label1:value1\tlabel2:value2\r\n');
ltsv.format([
{ label1: 'value1', label2: 'value2' },
{ label1: 'value1', label2: 'value2' },
{ label1: 'value1', label2: 'value2' }
]);
ltsv.formatLine({ label1: 'value1', label2: 'value2' });
var fs = require('fs'),
ltsv = require('ltsv'),
ltjs = ltsv.createLtsvToJsonStream({
toObject: false,
strict: false
});
fs.createReadStream('./access.log').pipe(ltjs).pipe(process.stdout);
Functions
parse(ltsv)
throw SyntaxError if ltsv records has no separator (":").
parseLine(record)
throw SyntaxError if record has no separator (":").
parseStrict(ltsv)
throw SyntaxError if ltsv records has no separator (":").
throw SyntaxError if labels don't match for /^[0-9A-Za-z_.-]+$/.
throw SyntaxError if values don't match for /^[\x01-\x08\x0B\x0C\x0E-\xFF]*$/.
parseLineStrict(record)
throw SyntaxError if record has no separator (":").
throw SyntaxError if labels don't match for /^[0-9A-Za-z_.-]+$/.
throw SyntaxError if values don't match for /^[\x01-\x08\x0B\x0C\x0E-\xFF]*$/.
format(ltsvArray)
throw TypeError if ltsvArray is not Array types.
throw TypeError if ltsvArray objects are not Object types.
formatLine(recordObj)
throw TypeError if recordObj is not Object types.
formatStrict(ltsvArray)
throw TypeError if ltsvArray is not Array types.
throw TypeError if ltsvArray objects are not Object types.
throw SyntaxError if labels don't match for /^[0-9A-Za-z_.-]+$/.
throw SyntaxError if values don't match for /^[\x01-\x08\x0B\x0C\x0E-\xFF]*$/.
formatLineStrict(recordObj)
throw TypeError if recordObj is not Object types.
throw SyntaxError if labels don't match for /^[0-9A-Za-z_.-]+$/.
throw SyntaxError if values don't match for /^[\x01-\x08\x0B\x0C\x0E-\xFF]*$/.
createLtsvToJsonStream(options)
options
toObject boolean - send object in data event
send object in data event if true.
default value is false.
strict boolean - strict parse
use parseLineStrict() if true.
default value is false.
Test
$ npm install
$ npm test
License
The MIT License. Please see LICENSE file.