node-lazy icon indicating copy to clipboard operation
node-lazy copied to clipboard

delimit(chars)

Open ralouphie opened this issue 11 years ago • 2 comments

Added delimit(chars) function to accept any characters to delimit the stream with.

Changed lines property to use delimit('\r\n').

This is useful when you want to break the stream up using different characters, for example the null character '\0'.

ralouphie avatar Feb 23 '13 07:02 ralouphie

This PR was submitted 5 months ago and still no action? This makes me NOT want to contribute to this project. Hey @alphus, this is a great idea and a great PR. If you took it a step further, you could include all the other newline characters. Here, this might help:

var newlines = {
    // Carriage Return followed by Line Feed
    crlf: '\r\n',

    // Line Feed, U+000A
    lf: '\n',

    // Carriage Return, U+000D
    cr: '\r',

    // Vertical Tab
    vt: '\u000B',

    // Form Feed
    ff: '\u000C',

    // Next Line
    nel: '\u0085',

    // Line Separator
    ls: '\u2028',

    // Paragraph Separator
    ps: '\u2029'
};

jednano avatar Aug 03 '13 05:08 jednano

@alphus, are null characters considered a newline character or just an end-of-string character? Is there a difference? It seems a bit hazy to me.

BTW, this should help also, a regex I wrote to test or otherwise split by newline characters:

var newlineCharacters = Object.keys(newlines).map(function(key) {
    var value = newlines[key];
    reverseMap[value] = key;
    return value;
});

var newlineCharacterPat = new RegExp(
    '(' + newlineCharacters.join('|') + ')', 'g');

jednano avatar Aug 03 '13 05:08 jednano