1.4.0 • Published 5 years ago

filesurgeon v1.4.0

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

FileSurgeon

NPM downloads Build Status license github-issues stars forks

Manipulate text files the easy way

Installation

npm install --save filesurgeon

Usage

const Filesurgeon = require("filesurgeon");

await Filesurgeon.edit('/tmp/somefile.txt')
  .replace('old', 'new')
  .save();

Examples:

Set lines in an existing file:

const Filesurgeon = require("filesurgeon");

await Filesurgeon.edit('/tmp/somefile.txt')
  .set(1, 'first')
  .set(2, 'second')
  .set(3, 'third')
  .save();

Transforms lines:

const Filesurgeon = require("filesurgeon");

await Filesurgeon.edit('/tmp/somefile.txt')
  .map((line) => line.trim())
  .map((line) => line.toLowerCase())
  .save();

Filter lines:

await Filesurgeon.edit('/tmp/somefile.txt')
  .filter((line) => {
    return /^[a-d]/.test(line);
  })
  .save();

Consume files:

const Filesurgeon = require("filesurgeon");

const contents =  await Filesurgeon.asArray('/tmp/somefile.txt');
console.log(contents);

Creates a new file and append lines:

const Filesurgeon = require("filesurgeon");

await Filesurgeon.newFile('/tmp/somefile.txt')
  .append('first')
  .append('second')
  .append('third')
  .save();

Documentation

For more examples and API details, see API documentation

Test

npm test

To generate a test coverage report:

npm run coverage
1.4.0

5 years ago

1.3.0

5 years ago

1.2.0

5 years ago

1.1.0

6 years ago

1.0.0

6 years ago