Easily insert line(s) at a specific line number of a file.
Linesert allows you to easily insert lines at a specific line number of a file.
- Insert a single line or an array of lines.
- Insert lines before a specific line number.
- Insert lines after a specific line number.
- Install with NPM -
npm install --save linesert
var linesert = require( "linesert" );
// file.txt
//=> 1.
//=> 3.
linesert( "file.txt" ).beforeLine( 2 ).insert( "2.", function( err, result ) {
//=> 1.
//=> 2.
//=> 3.
});
Name | Type | Argument | Description |
---|---|---|---|
path | string |
<required> |
the path of the file to be modified. |
Name | Type | Argument | Description |
---|---|---|---|
number | number |
<required> |
the line number to insert the new lines before. |
Name | Type | Argument | Description |
---|---|---|---|
number | number |
<required> |
the line number to insert the new lines after. |
Name | Type | Argument | Description |
---|---|---|---|
text | `string | array` | <required> |
callback | function |
<required> |
callback that returns the results of the update. |
Name | Type | Argument | Description |
---|---|---|---|
error | error |
<required> |
any errors that may have occured. |
results | string |
<required> |
the output of the updated file. |
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.
Copyright (c) 2015 Jason Bellamy
Licensed under the MIT license.