Pick several lines from file by line number.
npm install pick-lines-from-file
This module can be used for picking several lines from file. The main purpose is to pick one line which is probably important one and also context for it (a bit more lines).
Basic usage example
var linePicker = require'pick-lines-from-file';linePicker__dirname + '/zapovit.txt'lineNumbers3linesAround2fetchif !err//do something with data;
Extended usage example
var linePicker = require'pick-lines-from-file';linePicker__dirname + '/zapovit.txt'lineNumbers7linesAround4fetchif !errvar start = datastartAt;var linesCount = dataendAt - datastartAt;console.log'Total ' + linesCount + 'lines.';for var i = 0 l = datalineslength; i < l; i++console.log'#' + start + i;console.log'|' + datalinesi;;
Providing multiple line numbers
var linePicker = require'pick-lines-from-file';linePicker__dirname + '/zapovit.txt'lineNumbers1 4 3linesAround2fetchif !errfor var i = 0 l = datalength; i < l; i++console.logdatailines;console.logdataistartAt;console.logdataiendAt;;
Data hash contains 3 properties:
If single lineNumber was provided, data hash is returned from function, otherwise array of data is returned.
Feel free to open issues and send PRs, though make sure that you create tests for new functionality and amend ones for fixes and changes.
npm test in order to see test results.
The MIT License (MIT)
Copyright (c) 2014 Semenistyi Mykyta email@example.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.