Socket
Socket
Sign inDemoInstall

read-input

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    read-input

Easily read from stdin or files.


Version published
Weekly downloads
49K
increased by9.87%
Maintainers
1
Install size
7.96 kB
Created
Weekly downloads
 

Changelog

Source

v0.1.0

August 5, 2014

  • Initial release.

Readme

Source

read-input

Easily read from stdin or files.

read()

read(files, fn)

Reads from files. If no files are given, read from stdin. The err argument will always be null, as errors will be part of res.

var read = require('read-input');
var fnames = process.argv.slice(2); //=> ['readme.txt']

read(fnames, function (err, res) {
  res.data    //=> '...'
  res.error   //=> undefined | Error()
  res.stdin   //=> true | false
  res.files   //=> [...]
});

You can also iterate through res.files.

read(fnames, function (err, res) {
  res.files.forEach(function (f) {
    f.data    //=> ...
    f.error   //=> undefined | Error(...)
    f.stdin   //=> true | false
    f.name    //=> 'readme.txt'
  }
});

If files is a blank array (or null), data will be read from stdin. The resulting data will have a similar schema.

read([], function (err, res) {
  ...
});

read.stdin()

read.stdin(fn)

Read data from standard input. The err argument will always be null.

read.stdin(function (err, data) {
  console.log(data); // string
});

res

The results value is an object passed to the callback of read().

  • data (String) a concatenation of all data in all the files.
  • error (Error) The first error in all files. undefined if successful.
  • stdin (Boolean) is true if the file is read from stdin
  • files (Array) A list of files.

Each of the items in files has a similar list of values:

  • data (String) File data
  • error (Error) error, if applicable
  • stdin (Boolean) is true if the file is read from stdin
  • name (String) File name

See read() for an example.

Thanks

read-input © 2014+, Rico Sta. Cruz. Released under the MIT License.
Authored and maintained by Rico Sta. Cruz with help from contributors.

ricostacruz.com  ·  GitHub @rstacruz  ·  Twitter @rstacruz

Keywords

FAQs

Last updated on 05 Aug 2014

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc