stylus/js/promisify.js

18 lines
391 B
JavaScript
Raw Normal View History

2018-10-04 17:03:40 +00:00
'use strict';
function promisify(fn) {
return (...args) =>
new Promise((resolve, reject) => {
fn(...args, (...result) => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
return;
}
resolve(
result.length === 0 ? undefined :
result.length === 1 ? result[0] : result
);
});
});
}