Parses lines from text, preserving line numbers, offsets and line endings.
$ npm install linez
var linez = ;
By default, linez uses
/\r?\n/g as the regular expression to detect newline character sequences and split lines. This regular expression is tuned for performance and only covers the most common newline types (i.e.,
\r\n). If you have need for more newline character sequences, you can configure linez with the
Setting this property will automatically create a piped regular expression for you and use it in any future
linez() calls. You can make up your own newlines if you want. Linez doesn't care one way or the other.
This would be converted into
/(foo|bar)/g. Newlines are just strings. They can be anything. There are, however, some known newline character sequences. Should you need them, refer to the following table:
||U+000D, U+000A||Carriage Return + Line Feed|
Byte Order Marks
Also referred to as BOM signatures, these are the bytes at the beginning of a file that indicating the encoding in which the file is written. Currently, linez only reads BOMs to detect the encoding and does not take into account the contents of the file.
If linez detects an unsupported BOM, an error will be thrown, indicating that decoding the detected charset is not supported.
By default, the document will attempt to be decoded as utf8. This is the default behavior of the Node API's conversion from buffers into strings.
Configures linez to use the supplied options. Currently, only the newlines property is available, where you can specify any number of newline character sequences.
Resets the configuration to the default settings, using
/\r?\n/g as the newlines regular expression.
constructorpublic lines: Line;
toString() method converts the document's lines into a string, discarding information about line numbers and offsets.
linez(file: string|Buffer): Document
Parses text into a
The specs show some great usage examples.
;lines.offset; // 4lines.number; // 2lines.text; // barlines.ending; // \n
Note: You can also pass-in a Buffer.
Released under the MIT license.