promise-fn
Wrap a function to be able to call it with promises as arguments, i.e. use promises as if they where non-promise values
Installation
Install promise-fn
using npm:
npm install --save promise-fn
Usage
Module usage
const fn = ; // Create a logging function which can log data from promises as well as non-promise values:const log = ;// Create a JSON parser which can parse strings from promises as well as non-promise values:const parse = ; const getAsyncData = ;const getSyncData = '{"hi": "there"}'; ;// data: { hello: 'world' } { hi: 'there' }// will be printed to the console in about 1 second
Related packages
promise-fnapply
- A Function.apply that can deal with promise argumentspromise-fncall
- A Function.call that can deal with promise argumentspromise-if
- The if statement (or unary operator) for promisespromise-or
- The OR (||) operator for promisespromise-and
- The AND (&&) operator for promisespromise-not
- The NOT (!) operator for promisespromise-all
- A Promise.all but for Objects as well as Arrayspromise-get
- Get a property from the object a promise resolves to, using a dot path
API
promiseFn(fn, thisArg)
Name | Type | Description |
---|---|---|
fn | Function |
Function to wrap |
thisArg | Any |
The value to be passed as this when calling fn |
Returns: Function
, the function to call instead of the original function.
License
MIT © Joakim Carlstein