UNPKG

find-node-modules

Version:

Return an array of all parent node_modules directories

23 lines (18 loc) 630 B
const {isString, isNil, isBoolean} = require('lodash'); const getError = require('./get-error'); const isNonEmptyString = value => isString(value) && value.trim(); const VALIDATORS = { npmPublish: isBoolean, tarballDir: isNonEmptyString, pkgRoot: isNonEmptyString, }; module.exports = ({npmPublish, tarballDir, pkgRoot}) => { const errors = Object.entries({npmPublish, tarballDir, pkgRoot}).reduce( (errors, [option, value]) => !isNil(value) && !VALIDATORS[option](value) ? [...errors, getError(`EINVALID${option.toUpperCase()}`, {[option]: value})] : errors, [] ); return errors; };