File tree Expand file tree Collapse file tree 1 file changed +14
-11
lines changed
Expand file tree Collapse file tree 1 file changed +14
-11
lines changed Original file line number Diff line number Diff line change 11const { isString, isUndefined, isBoolean} = require ( 'lodash' ) ;
22const 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} ;
You can’t perform that action at this time.
0 commit comments