A utility to capture lines from a text file between specified start and end markers with optional inclusion of markers and support for multiple captures.
You can install this package via npm:
npm install capture-lines
Here is an example of how to use the captureLines
function:
import { captureLines } from 'capture-lines'
const result = await captureLines({
file: 'path/to/your/file.txt',
startMarker: 'START',
endMarker: 'END',
allowMultipleCaptures: true,
includeMarkers: true,
})
console.log(result)
The captureLines
function takes an options object with the following properties:
- file:
string
- The path to the file to read. - startMarker:
string
- The marker that indicates the start of the capture. - endMarker:
string
- The marker that indicates the end of the capture. - allowMultipleCaptures:
boolean
(optional) - Whether to allow multiple captures within the file. Default isfalse
. - includeMarkers:
boolean
(optional) - Whether to include the start and end markers in the captured output. Default isfalse
.