Given an object with methods and a list of method names, return a new object with promisified bound versions of those methods.
This module exports one function with two modes:
obj
can be anything. If it's false-y, prFunc
will be false
.
oneMethodName
can be:
- false-y, then
prFunc
will befalse
. - a string or number, then a method of that name is looked up in
obj
, bound toobj
, promisified and returned asprFunc
.
obj
can be anything. If it's false-y, prFuncs
will be false
.
prFuncs
will be a dictionary object if you provide proper methodNames
,
i.e. either
- an array, then keys in
prFuncs
will refer to the same-named method inobj
, no magic. - a dictionary object, mapping desired method names (keys in
prFuncs
) to the callback methods' name (key inobj
). Special values:true
: Use same method name.null
,false
: Ignore this entry.
methodNames
that point to something that doesn't look like a function,
will be ignored.
from test/usage.mjs:
import nodeFs from 'fs';
import pifyMtds from 'promisify-selected-methods';
const readLinkPr = pifyMtds(nodeFs, 'readlink');
const promising = {
...pifyMtds(nodeFs, ['chmod', 'stat']),
...pifyMtds(nodeFs, {
readFile: true, // keep original name
readDir: 'readdir', // rename to camelCase
ignored: null,
alsoIgnored: false,
}),
};
const expectedMethodNames = ['chmod',
'readDir', 'readFile', 'stat'];
- Needs more/better tests and docs.
ISC