replaceable-function

1.0.1 • Public • Published

replaceable-function

a function you can replace.

Installation

npm install replaceable-function

Example

var handler = Replaceable(start)
stream.on('data', handler)

function start(data) {
  // handle connection initialisation
  
  handler.replace(handle)
}

function handle(data) {
  // handle the data
  if (data.last)
    handler.replace(end)
  else
    
}

function end(data) {
  // handle the goodbye
  
  handler.replace(null)
}

API

Replaceable(fn)

Returns a function that delegates to its internal function. If the passed value isn't a function, it'll be replaced by function() { throw new TypeError('not a function') }.

Replaceable.quiet(fn)

Returns a function that delegates to its internal function. If the passed value isn't a function, it'll be replaced by function() {}.

replaceable.replace(fn)

replaces the internal function.

Dependents (0)

Package Sidebar

Install

npm i replaceable-function

Weekly Downloads

4

Version

1.0.1

License

ISC

Last publish

Collaborators

  • nathan7