segmenter
To segment a set of chunks from strings or streams
Last updated 7 years ago by touv .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install segmenter 
SYNC missed versions from official npm registry.

Segmenter for NodeJS

Build Status

To segment a set of chunks from strings or streams It's a collection of javascript tools (parse/stringify) for CSV strings. It can work row by row. Unlike many other similar modules, it works correctly with fields containing newlines (including on the first line)

Contributors

Installation

With npm do:

$ npm install segmenter

Examples

With string

	var Segmenter = require('segmenter'),
	seg = new Segmenter({ delimiter: "." });

    seg.fecth('a.b.c.');

Output:

[ 'a', 'b', 'c' ]

With buffer

	var seg = new Segmenter(),
		readStream = require('fs').createReadStream('dataset.txt'),
		res = [];

	readStream.on('data', function (chunk) {
		res = res.concat(seg.fetch(chunk));
    });
    readStream.on('end', function () {
		console.log('Array of lines', lines);
	});

Output:

[ 'Line 1', 'Line 2', 'etc.', ... ]

Tests

Use mocha to run the tests.

$ npm install mocha
$ mocha test

API Documentation

new Segmenter(Object options) : Object

Create the object.

Options are :

  • delimiter - String : Char or String that separe the segments. Default : \n

fetch(String chunk) : Array

Fetch segments in a String.

fetch(Buffer chunk, [String encoding]) : Array

Fetch segments in a Buffer.

Also

License

MIT/X11

Current Tags

  • 1.0.1                                ...           latest (7 years ago)

2 Versions

  • 1.0.1                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (2)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |