Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

To segment a set of chunks from strings or streams

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore
Octocat-spinner-32 .travis.yml
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.md
Octocat-spinner-32 index.js
Octocat-spinner-32 package.json
README.md

Segmenter for NodeJS

Build Status

To segment a set of chunks from strings or streams

Contributors

Installation

With npm do:

$ npm install segmenter

Examples

With string

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

    seg.fetch('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

Bitdeli Badge

Something went wrong with that request. Please try again.