1.0.0 • Published 9 years ago

linesert v1.0.0

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

Linesert Build Status

Easily insert line(s) at a specific line number of a file.

Features

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.

Getting Started

  • Install with NPM - npm install --save linesert

Usage

var linesert = require( "linesert" );

// file.txt
//=> 1.
//=> 3.

linesert( "file.txt" ).beforeLine( 2 ).insert( "2.", function( err, result ) {
  //=> 1.
  //=> 2.
  //=> 3.
});

API

linesert( path )

NameTypeArgumentDescription
pathstring<required>the path of the file to be modified.

linesert.beforeLine( number )

NameTypeArgumentDescription
numbernumber<required>the line number to insert the new lines before.

linesert.afterLine( number )

NameTypeArgumentDescription
numbernumber<required>the line number to insert the new lines after.

linesert.insert( text, callback )

NameTypeArgumentDescription
textstring|array<required>a string or array of strings to insert.
callbackfunction<required>callback that returns the results of the update.

callback( error, results )

NameTypeArgumentDescription
errorerror<required>any errors that may have occured.
resultsstring<required>the output of the updated file.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.

License

Copyright (c) 2015 Jason Bellamy
Licensed under the MIT license.