Skip to content

Commit 8e28af9

Browse files
committed
fix: factorise the verification code in a function
1 parent 1e21691 commit 8e28af9

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

lib/verify-config.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
const {isString, isUndefined, isBoolean} = require('lodash');
22
const getError = require('./get-error');
33

4-
module.exports = ({npmPublish, tarballDir, pkgRoot}) => {
5-
const errors = [];
6-
if (!isUndefined(npmPublish) && !isBoolean(npmPublish)) {
7-
errors.push(getError('EINVALIDNPMPUBLISH', {npmPublish}));
8-
}
4+
const isNonEmptyString = value => isString(value) && value.trim();
95

10-
if (!isUndefined(tarballDir) && !isString(tarballDir)) {
11-
errors.push(getError('EINVALIDTARBALLDIR', {tarballDir}));
12-
}
6+
const VALIDATORS = {
7+
npmPublish: isBoolean,
8+
tarballDir: isNonEmptyString,
9+
pkgRoot: isNonEmptyString,
10+
};
1311

14-
if (!isUndefined(pkgRoot) && !isString(pkgRoot)) {
15-
errors.push(getError('EINVALIDPKGROOT', {pkgRoot}));
16-
}
12+
module.exports = options => {
13+
const errors = Object.entries(options).reduce(
14+
(errors, [option, value]) =>
15+
!isUndefined(value) && value !== false && !VALIDATORS[option](value)
16+
? [...errors, getError(`EINVALID${option.toUpperCase()}`, {[option]: value})]
17+
: errors,
18+
[]
19+
);
1720

1821
return errors;
1922
};

0 commit comments

Comments
 (0)