reapply

Require a module and apply the export if it is a function.

Usage no npm install needed!

<script type="module">
  import reapply from 'https://cdn.skypack.dev/reapply';
</script>

README

reapply

Require a module and apply the export if it is a function.

Build Status Code Climate js-standard-style

npm install reapply --save
npm stats

npm NPM downloads Dependency Status

API Example

require
var reapply = require('reapply')
reapply/2
reapply(['%s world', 'hello'], 'format')
//=> hello world
reapply/1
modules.forEach(reapply([app]))

for the above example, consider that a developer may want to bootstrap an application by applying many "middleware" functions to a given app object. Each module exports a function that takes an app parameter like module.exports = function (app) { app.use(…) }.

Features

  • Supports partial application.
  • Supports function application with parameters.

API

reapply(parameters, moduleId)

arguments
  • parameters: (Array) parameters to pass to applied function.
  • moduleId: (String) module id to pass to require.
returns
  • (*) returns result of function application.

Alternatives

  • If you find yourself wanting to map over a list with reapply you might be interested in reapply-list.

Contributing

SEE: contributing.md

Licenses

GitHub license