Skip to content
Permalink
Browse files
Improve readability, avoid repetition (#55)
  • Loading branch information
fregante authored and sindresorhus committed May 2, 2018
1 parent e64328e commit 6ffaeed44698f127766ca99779acc0b4208fd22d
Showing 1 changed file with 15 additions and 21 deletions.
@@ -9,41 +9,35 @@ const processFn = (fn, opts) => function () {
}

return new P((resolve, reject) => {
if (opts.errorFirst) {
args.push(function (err, result) {
if (opts.multiArgs) {
const results = new Array(arguments.length - 1);
if (opts.multiArgs) {
args.push(function (err) {
const results = new Array(arguments.length - 1);

for (let i = 1; i < arguments.length; i++) {
results[i - 1] = arguments[i];
}
for (let i = 0; i < arguments.length; i++) {
results[i] = arguments[i];
}

if (opts.errorFirst) {
if (err) {
results.unshift(err);
reject(results);
} else {
results.shift();
resolve(results);
}
} else if (err) {
reject(err);
} else {
resolve(result);
resolve(results);
}
});
} else {
args.push(function (result) {
if (opts.multiArgs) {
const results = new Array(arguments.length - 1);

for (let i = 0; i < arguments.length; i++) {
results[i] = arguments[i];
}

resolve(results);
} else if (opts.errorFirst) {
args.push((err, result) => {
if (err) {
reject(err);
} else {
resolve(result);
}
});
} else {
args.push(resolve);
}

fn.apply(this, args);

0 comments on commit 6ffaeed

Please sign in to comment.