Skip to content

➗ Read a file, splitting it's contents into an Array (for Node)

License

Notifications You must be signed in to change notification settings

busterc/readfile-split

Repository files navigation

readfile-split NPM version Build Status Dependency Status

Read a file into an array

Install

$ npm install --save readfile-split

Usage

var readfileSplit = require('readfile-split');

// readfileSplit(filename[, options], callback)

// options with defaults
var options = {
  // fs.readFile specific options
  encoding: null,
  flag: 'r',

  // readfileSplit specific options
  emptyLines: true,
  trimLines: true,
  withSeperator: false,
  seperator: /\r?\n/
};

readfileSplit('/somewhere/somefile', options, console.log);
// > null [ 'Hello,', '', 'Don\'t worry.', 'Be happy.', '', 'Goodbye!', '' ]

options.emptyLines = false;
readfileSplit('/somewhere/somefile', options, console.log);
// > null [ 'Hello,', 'Don\'t worry.', 'Be happy.', 'Goodbye!' ]

options.seperator = '.';
readfileSplit('/somewhere/somefile', options, console.log);
// > null [ 'Hello,\n\nDon\'t worry', 'Be happy', 'Goodbye!' ]

options.withSeperator = true;
readfileSplit('/somewhere/somefile', options, console.log);
// > null [ 'Hello,\n\nDon\'t worry.', 'Be happy.', 'Goodbye!' ]

// etc.

License

ISC © Buster Collings

About

➗ Read a file, splitting it's contents into an Array (for Node)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published