const promisify = fn=>(
(...args)=>(
new Promise(
(resolve,reject)=>fn.apply(null,[
...args,
(err,res)=> (err!=null?reject(err):resolve(res))
])
)
)
);
const testSuccess = (arg,cb) => { cb(null,arg) };
const testFailed = (arg,cb) => { cb(new Error(arg)) };
(async()=>{
let fn = promisify(testSuccess);
let res = await fn('Успех');
console.log(res);
})();
(async()=>{
let fn = promisify(testFailed);
let res = await fn('Ошибка');
console.log(res);
})();
<img src="https://partner.ru?ref=123" width="1" height="1" />