Skip to content

Much like `useware` but with the ability to bind context to each of the functions using `bind-context` package.

License

Notifications You must be signed in to change notification settings

tunnckoCore/useware-context

Repository files navigation

Much like useware, but with the ability to bind given context to each function.

code climate standard code style travis build status coverage status dependency status

Install

npm i useware-context --save

Usage

For more use-cases see the tests

const usewareContext = require('useware-context')

Pass different kind of values and get only functions. They also are bounded with ctx (if given) and if it is first argument, or using .call / .apply as usual.

Params

  • ctx {Object=}: If first argument is object, it's considered as context.
  • args {*}: Any number of arguments, only functions are filtered.
  • returns {Array}: Flattened array containing only functions.

Example

var useware = require('useware-context')

function pluginOne () {
  return this.foo
}

function pluginTwo () {
  return this.bar
}

// pass context as first argument
var fns = useware({
  foo: 'baz',
  bar: 'qux'
}, [1, 2, [pluginOne, 3]], 'arg', pluginTwo)

console.log(fns) // => [ [Function: pluginOne], [Function: pluginTwo] ]
console.log(fns[0]()) // => 'baz'
console.log(fns[1]()) // => 'qux'

Related

  • arr-filter: Faster alternative to javascript's native filter method. | homepage
  • arr-map: Faster, node.js focused alternative to JavaScript's native array map. | homepage
  • async-control: Ultimate asynchronous control flow goodness with built-in hook system and compose,… more | homepage
  • bind-context: Bind context to a function and preserves her name. Can be… more | homepage
  • plugins: Run a value through a plugin stack. | homepage
  • use: Easily add plugin support to your node.js application. | homepage
  • useware: Accept Arguments object or multiple arguments that can be any value,… more | homepage
  • vez: Middleware composition at new level. Ultimate alternative to ware, plugins, koa-composemore | homepage
  • ware: Easily create your own middleware layer. | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

tunnckoCore.tk keybase tunnckoCore tunnckoCore npm tunnckoCore twitter tunnckoCore github

About

Much like `useware` but with the ability to bind context to each of the functions using `bind-context` package.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published