How to use the check-more-types.maybe function in check-more-types

To help you get started, we’ve selected a few check-more-types examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bahmutov / changed-log / bin / changed-log.js View on Github external
var options = {
  name: process.argv[2],
  from: process.argv[3],
  to: process.argv[4]
}

options.auth = _.some(process.argv, function (word) {
  return word === '--auth'
})
debug('options', options)

// TODO implement semver in check-more-types
var isValidCliOptions = check.schema.bind(null, {
  name: check.unemptyString,
  from: check.maybe.unemptyString,
  to: check.maybe.unemptyString
})
if (!isValidCliOptions(options)) {
  log('%s@%s    [options]',
    pkg.name, pkg.version)
  log('options:\n  --auth  - login with github credentials for increased rate limit')
  /* eslint no-process-exit:0 */
  process.exit(-1)
}

if (!options.to) {
  debug('"to" version is not set, assuming latest')
  options.to = 'latest'
}

var changedLog = require('../src/changed-log')
changedLog(options)
github bahmutov / pre-git / bin / commit-wizard.js View on Github external
const preGit = require('pre-git');
const git = require('ggit');
const chalk = require('chalk');
const log = require('debug')('pre-git');
la(check.fn(log), 'missing debug log', log);

/* jshint -W079 */
const Promise = require('bluebird');

const label = 'pre-commit';

const config = pkg.config &&
  pkg.config['pre-git'];

const wizard = preGit.wizard();
la(check.maybe.object(wizard),
  'could not get commit message wizard', wizard);

function getPreCommitCommands(config) {
  if (!config) {
    return;
  }
  const preCommit = config[label];
  if (check.unemptyString(preCommit)) {
    return [preCommit];
  }
  return preCommit;
}

function hasPreCommitCommands(config) {
  return check.unemptyArray(getPreCommitCommands(config));
}
github bahmutov / now-pipeline / bin / now-pipeline.js View on Github external
function updateAliasIfNecessary (aliasName, deploy) {
    la(is.maybe.string(aliasName), 'alias name should be a string', aliasName)

    return nowPipeline.deployments(pkg.name)
    .then(deploys => {
      return R.filter(R.prop('alias'))(deploys)
    })
    .then(deployed => {
      console.log('found %d deploy(s) with aliases', deployed.length)
      debug(deployed)

      if (!deployed.length) {
        console.log('there is no existing alias')
        if (!aliasName) {
          console.log('will skip updating alias to', deploy.url)
          return
        }
        console.log('setting new alias to %s', aliasName)
github bahmutov / grunty / src / fake-gruntfile-code.js View on Github external
require('lazy-ass');
var check = require('check-more-types');

function isValidSource(x) {
  if (check.not.defined(x)) {
    return true;
  }
  return check.unemptyString(x) ||
    check.array(x);
}

var optionsSchema = {
  plugin: check.unemptyString,
  target: check.maybe.unemptyString,
  src: isValidSource,
  dest: check.maybe.unemptyString
};
var isValidOptions = check.schema.bind(null, optionsSchema);

function isMultiTask(options) {
  return check.object(options) &&
    check.unemptyString(options.target) &&
    check.has(options, 'src') &&
    check.has(options, 'dest') &&
    check.maybe.object(options.config);
}

module.exports = function fakeGruntfileInit(options) {
  la(check.object(options), 'missing grunty options', options);
  la(isValidOptions(options), 'invalid options', options);
github bahmutov / ban-sensitive-files / src / ban.js View on Github external
function isBannedFilename (filename, logger) {
  la(check.maybe.unemptyString(filename) ||
    check.array(filename), 'expected single or list of filenames', filename)
  logger = logger || console.error.bind(console)

  const filenames = check.array(filename) ? filename : [filename]

  return testers.some(singleTester.bind(null, filenames, logger))
}
github bahmutov / available-versions / src / available.js View on Github external
var validVersions = versions.filter(function (ver) {
        return cleanVersion(ver, name, silent)
      })

      if (query.version) {
        debug('have query version')
        la(check.string(query.version), 'missing version string, have', query.version)
        validVersions = validVersions.filter(function (ver) {
          var later = semver.gt(ver, query.version)
          return later
        })
      }

      var timestamps = getTimestamps(info, validVersions)
      la(check.maybe.array(timestamps),
        'expected list of timestamps', timestamps)

      la(check.maybe.object(info['dist-tags']),
        'expected object with dist tags', info['dist-tags'])

      result.name = name
      result.versions = validVersions
      result.timestamps = timestamps
      result['dist-tags'] = info['dist-tags']

      return deferred.resolve(result)
    } catch (error) {
      console.error(error)
      deferred.reject(new Error('Could not fetch versions for ' + name))
    }
  }
github bahmutov / available-versions / src / available.js View on Github external
})

      if (query.version) {
        debug('have query version')
        la(check.string(query.version), 'missing version string, have', query.version)
        validVersions = validVersions.filter(function (ver) {
          var later = semver.gt(ver, query.version)
          return later
        })
      }

      var timestamps = getTimestamps(info, validVersions)
      la(check.maybe.array(timestamps),
        'expected list of timestamps', timestamps)

      la(check.maybe.object(info['dist-tags']),
        'expected object with dist tags', info['dist-tags'])

      result.name = name
      result.versions = validVersions
      result.timestamps = timestamps
      result['dist-tags'] = info['dist-tags']

      return deferred.resolve(result)
    } catch (error) {
      console.error(error)
      deferred.reject(new Error('Could not fetch versions for ' + name))
    }
  }
  return deferred.promise
github bahmutov / next-ver / src / pick-version.js View on Github external
function pickVersion (packageVersion, tagVersion) {
  debug('picking latest version between %s and tag %s',
    packageVersion, tagVersion)

  la(is.unemptyString(packageVersion),
    'missing package version', packageVersion)
  la(is.maybe.unemptyString(tagVersion), 'missing tag', tagVersion)
  if (!tagVersion) {
    debug('missing tag version, returning package version', packageVersion)
    return packageVersion
  }
  if (!semver.valid(tagVersion)) {
    debug('tag version %s is not semver', tagVersion)
    return packageVersion
  }

  const latest = semver.gt(packageVersion, tagVersion)
    ? packageVersion : tagVersion
  debug('picked latest version %s', latest)
  const cleaned = semver.clean(latest)
  debug('cleaned latest version %s', cleaned)
  return cleaned
}
github bahmutov / available-versions / src / human-format-spec.js View on Github external
function checkProps (release) {
    la(is.semver(release.version), 'missing version', release)
    la(is.maybe.unemptyString(release.age), 'missing age', release)
    la(is.maybe.unemptyString(release['dist-tag']), 'wrong dist tag', release)
  }
github bahmutov / next-ver / src / compute-next-version.js View on Github external
function printChange (feat) {
  debug('semantic change "%s"', feat)
  la(is.maybe.string(feat), 'expected change to be a string', feat)
}