Socket
Book a DemoInstallSign in
Socket

ltsv

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ltsv

LTSV parser and formatter

Source
npmnpm
Version
0.7.4
Version published
Weekly downloads
588
37.38%
Maintainers
1
Weekly downloads
 
Created
Source

ltsv.js

Build Status Dependency Status NPM version Bower version

LTSV parser and formatter

playgound

http://sasaplus1.github.io/ltsv.js/

Installation

npm

$ npm install ltsv

bower

$ bower install ltsv

Usage

node.js

var 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'
var fs = require('fs'),
    ltsv = require('ltsv'),
    ltjs = ltsv.createLtsvToJsonStream({
      toObject: 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(ltjs).pipe(process.stdout);
// {"l1":"v1","l2":"v2"}{"l1":"v1","l2":"v2"}{"l1":"v1","l2":"v2"}

Functions

parse(text)

  • text
    • String - LTSV text
  • return
    • Object[] - parsed objects

split to LTSV records.

throw SyntaxError if text has no separator.

parseLine(line)

  • line
    • String - LTSV line
  • return
    • Object - parsed object

split to LTSV record.

throw SyntaxError if line has no separator.

parseStrict(text)

  • text
    • String - LTSV text
  • return
    • Object[] - parsed objects

split to LTSV records and validate label and value of fields.

throw SyntaxError if text has no separator. also throw SyntaxError if text has unexpected character.

parseLineStrict(line)

  • line
    • String - LTSV line
  • return
    • Object - parsed object

split to LTSV record.

throw SyntaxError if line has no separator. also throw SyntaxError if line has unexpected character.

format(data)

  • data
    • Object|Object[] - object or object array
  • return
    • String - LTSV text

convert to LTSV text.

throw TypeError if data is not an object or array.

formatStrict(data)

  • data
    • Object|Object[] - object or object array
  • return
    • String - LTSV text

convert to LTSV text.

throw TypeError if data is not an object or array. also throw SyntaxError if data has unexpected character.

createLtsvToJsonStream([options])

  • options
    • Object - option object
  • return
    • LtsvToJsonStream - LTSV to JSON stream

return LtsvToJsonStream instance. this function cannot use by browser.

options

  • encoding
    • String - StringDecoder's encoding, default is utf8
  • toObject
    • Boolean - convert to Object if true, default is false
  • strict
    • Boolean - strict parse if true, default is false

Test

node.js

$ npm install
$ npm test

browser

$ npm install
$ npm run testem

License

The MIT license. Please see LICENSE file.

FAQs

Package last updated on 17 Sep 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts