ltsv
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

ltsv.js

test npm version Try ltsv on RunKit renovate

LTSV parser, formatter, validator and TransformStream

Installation

npm

$ npm install ltsv

Usage

node.js

const ltsv = require('ltsv');

browser

<script src="ltsv.min.js"></script>

Example

ltsv.parse(
  'label1:value1\tlabel2:value2\n' +
  'label1:value1\tlabel2:value2\n' +
  'label1:value1\tlabel2:value2'
);
// [ { label1: 'value1', label2: 'value2' },
//   { label1: 'value1', label2: 'value2' },
//   { label1: 'value1', label2: 'value2' } ]
 
ltsv.parseLine('label1:value1\tlabel2:value2');
// { label1: 'value1', label2: 'value2' }
ltsv.parseLine('label1:value1\tlabel2:value2\n');
// { label1: 'value1', label2: 'value2' }
ltsv.parseLine('label1:value1\tlabel2:value2\r\n');
// { label1: 'value1', label2: 'value2' }
 
ltsv.format([
  { label1: 'value1', label2: 'value2' },
  { label1: 'value1', label2: 'value2' },
  { label1: 'value1', label2: 'value2' }
]);
// 'label1:value1\tlabel2:value2\nlabel1:value1\tlabel2:value2\nlabel1:value1\tlabel2:value2'
 
ltsv.format({ label1: 'value1', label2: 'value2' });
// 'label1:value1\tlabel2:value2'
const fs = require('fs');
 
const ltsv = require('ltsv');
 
const stream = ltsv.createLtsvToJsonStream({
  encoding: 'utf8',
  objectMode: false,
  strict: false
});
 
// access.log:
// l1:v1\tl2:v2\n
// l1:v1\tl2:v2\n
// l1:v1\tl2:v2\n
fs.createReadStream('./access.log').pipe(stream).pipe(process.stdout);
// {"l1":"v1","l2":"v2"}{"l1":"v1","l2":"v2"}{"l1":"v1","l2":"v2"}

Functions

see docs or https://sasaplus1.github.io/ltsv.js

License

The MIT license.

Dependencies (0)

    Dev Dependencies (25)

    Package Sidebar

    Install

    npm i ltsv

    Weekly Downloads

    410

    Version

    2.0.0

    License

    MIT

    Unpacked Size

    106 kB

    Total Files

    34

    Last publish

    Collaborators

    • sasaplus1