1.2.1 • Published 5 years ago

montor v1.2.1

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

montor

montor allows you to monitor any Writable or Duplex - or any other interface that supports the _write functionality found in those - instance.

setup

setting up montor is as easy as installing it through npm and requiring it within your nodejs project

npm i montor
const montor = require("montor");

and that's all you need to setup montor for use in your projects.

start(stream: Writable | Duplex, callback: Function, options?: {}): void

the montor.start function takes in three arguments

  • stream - the instance we will be monitoring
  • callback - the callback function
  • options (optional)- options to control the writes

the callback function can receive three arguments

  • chunk - the data sent through write
  • encoding - the encoding for the given chunk
  • next (if next is false) - callback to continue to next write, see stream

the options object can have

  • default (optional, default true) - whether to continue normal writes
  • before (optional, default true) - whether to call the callback before or after the normal write (no effect if default is false)
  • next (optional, default true) - whether to automatically call next (if false, next is passed as the third argument to callback)

here is an example of how the montor.start function is used, along with what the output from the callback looks like

// this is our normal output
console.error("hello"); // > hello

// now we start monitoring and only get the monitored write
montor.start(process.stderr, chunk => console.log("monitored: " + chunk), {default: false});
console.error("hello"); // > monitored: hello

stop(stream: Writable | Duplex): void

the montor.stop function takes in only one argument

  • stream - this instance to stop monitoring

here we can see how the montor.stop function is used and how regular writes are brought back

// we start monitoring and only get the monitored write
montor.start(process.stderr, chunk => console.log("monitored: " + chunk), false);
console.error("hello"); // > monitored: hello

// then we stop monitoring and go back to regular writes
montor.stop(process.stderr);
console.error("hello"); // > hello

licence

MIT

1.2.0

5 years ago

1.2.1

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.1.4-minified

5 years ago

1.1.4-unminified

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.4-unminifed

5 years ago

1.1.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago