linesert
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/linesert package

1.0.0 • Public • Published

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 )

Name Type Argument Description
path string <required> the path of the file to be modified.

linesert.beforeLine( number )

Name Type Argument Description
number number <required> the line number to insert the new lines before.

linesert.afterLine( number )

Name Type Argument Description
number number <required> the line number to insert the new lines after.

linesert.insert( text, callback )

Name Type Argument Description
text string|array <required> a string or array of strings to insert.
callback function <required> callback that returns the results of the update.

callback( error, results )

Name Type Argument Description
error error <required> any errors that may have occured.
results string <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.

Package Sidebar

Install

npm i linesert

Weekly Downloads

10

Version

1.0.0

License

MIT

Last publish

Collaborators

  • jasonbellamy