1
0
mirror of https://github.com/S2-/minifyfromhtml.git synced 2025-08-02 20:00:05 +02:00
Files
minifyfromhtml/node_modules/try-to-catch/lib/try-to-catch.js
2019-04-15 10:35:12 +02:00

22 lines
387 B
JavaScript

'use strict';
const success = (a) => [null, a];
const fail = (a) => [a];
const noArg = (f, a) => () => f(...a);
module.exports = (fn, ...args) => {
check(fn);
return Promise.resolve()
.then(noArg(fn, args))
.then(success)
.catch(fail);
};
function check(fn) {
if (typeof fn !== 'function')
throw Error('fn should be a function!');
}