1.0.3 • Published 2 years ago

@santimir/line-reader v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

line-reader

version downloads coverage

Splits and Reads lines from a string or string array.

If the argument is an array, it does not further split, just enables the functionality for reading lines.

  • Class keeps track of the current index,
  • Performs string splitting using Regex or string characters
  • A few of the helper methods:
    • readLine, readLines, readTo,
    • getLines,
    • skip, record, rewind, reset

Installation

npm i @santimir/line-reader

Examples

import { LineReader } from "@santimir/line-reader";

const myString = "hello\n world\n new string\n here";
const options = { eol:'\n', index:0 };//eol can also be regex
let lines = new LineReader(myString, options);

const example = lines.readLine() + lines.skip().readLine(); // "hello new string"

Or more complex..

import { readFileSync as rfs } from "fs";
import { LineReader } from "@santimir/line-reader";

const myStuff = rfs("./path/to/file").toString("utf8");

let lines = new LineReader(myStuff);
lines.skip(10) //skip first 10 lines
     .record() //records current index
     .seek(3) //moves to index 3
     .rewind() //back to index 11
     .reset() //index 0
     .readLine() //returns first line

let switch = true;
while(switch){
  if(lines.readLine().startsWith("<body>")){
    switch=false
  }
}

const bodyFirstLine = lines.readLine();
1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.0

2 years ago