How to use the check-more-types.schema 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 / next-update / src / revert.js View on Github external
const debug = require('debug')('next-update')
const is = require('check-more-types')
const la = require('lazy-ass')
var getDependenciesToCheck = require('./dependencies')
var installModule = require('./module-install')
var q = require('q')

const isRevertInfo = is.schema({
  name: is.unemptyString,
  version: is.unemptyString
})

// returns promise
function revert (moduleName) {
  if (moduleName) {
    console.log('reverting module', JSON.stringify(moduleName))
  }

  var toCheck = getDependenciesToCheck({}, moduleName)
  debug('need to check')
  debug(toCheck)

  var installPromises = toCheck.map(function (info) {
    la(isRevertInfo(info), 'invalid revert info', info)
github bahmutov / changed-log / src / changed-log.js View on Github external
from: options.fromTag.sha,
    to: options.toTag.sha
  }

  function setReport (report) {
    report.options.name = options.name
    report.options.from = options.from
    report.options.to = options.to
    return report
  }

  return findCommits(findOptions)
    .then(setReport, failedToFindComments)
}

var isLatest = check.schema({
  from: check.equal('latest')
})

function changedAfterLatest (options/*, reportOptions */) {
  debug('Returning comments from commits after latest tag')
  return packageRepo(options.name)
    .then(_.partial(findCommitIds, options))
    .tap(debug)
}

function changedLogReport (options, reportOptions) {
  // TODO validate options
  options = options || {}
  reportOptions = reportOptions || {}

  if (isLatest(options)) {
github bahmutov / snap-shot-core / src / file-system.js View on Github external
// gleb.bahmutov@gmail.com
const snapshotsFolder = fromCurrentFolder(snapshotsFolderName)
debug('process cwd: %s', cwd)
debug('snapshots folder: %s', snapshotsFolder)

/**
 * Changes from relative path to absolute filename with respect to the
 * _original working directory_. Always use this function instead of
 * `path.resolve(filename)` because `path.resolve` will be affected
 * by the _current_ working directory at the moment of resolution, and
 * we want to form snapshot filenames wrt to the original starting
 * working directory.
 */
const resolveToCwd = path.resolve.bind(null, cwd)

const isSaveOptions = is.schema({
  sortSnapshots: is.bool
})

const isLoadOptions = is.schema({
  useRelativePath: is.bool
})

function getSnapshotsFolder (specFile, opts = { useRelativePath: false }) {
  if (!opts.useRelativePath) {
    // all snapshots go into the same folder
    return snapshotsFolder
  }

  const relativeDir = fromCurrentFolder(path.dirname(specFile))
  verbose('relative path to spec file %s is %s', specFile, relativeDir)
github bahmutov / snap-shot-core / src / file-system.js View on Github external
/**
 * Changes from relative path to absolute filename with respect to the
 * _original working directory_. Always use this function instead of
 * `path.resolve(filename)` because `path.resolve` will be affected
 * by the _current_ working directory at the moment of resolution, and
 * we want to form snapshot filenames wrt to the original starting
 * working directory.
 */
const resolveToCwd = path.resolve.bind(null, cwd)

const isSaveOptions = is.schema({
  sortSnapshots: is.bool
})

const isLoadOptions = is.schema({
  useRelativePath: is.bool
})

function getSnapshotsFolder (specFile, opts = { useRelativePath: false }) {
  if (!opts.useRelativePath) {
    // all snapshots go into the same folder
    return snapshotsFolder
  }

  const relativeDir = fromCurrentFolder(path.dirname(specFile))
  verbose('relative path to spec file %s is %s', specFile, relativeDir)

  // return path.join(resolveToCwd(relativeDir), '__snapshots__')
  const folder = joinSnapshotsFolder(relativeDir)
  verbose('snapshot folder %s', folder)
github bahmutov / conventional-commit-message / src / valid-message-spec.js View on Github external
it('satisfies api', () => {
    la(check.schema(schema, api), api)
  })
})
github bahmutov / changed-log / src / get-commits-from-tags.js View on Github external
function getFromToTags (question) {
  if (isLatest(question)) {
    return getLatestTag(question)
  }

  var tagSchema = {
    from: check.unemptyString,
    to: check.unemptyString
  }
  la(check.schema(tagSchema, question), question)

  return getTags(_.pick(question, 'user', 'repo'))
    .then(function (allTags) {
      la(check.array(allTags), 'missing tags', allTags)
      var fromTagIndex = _.findIndex(allTags, 'name', question.from)
      if (fromTagIndex === -1) {
        const msg = 'Cannot find "from" tag ' + question.from
        const fullMsg = msg + '\navailable tags ' +
          justTagNames(allTags).join(', ')
        return Promise.reject(new Error(fullMsg))
      }

      la(fromTagIndex !== -1, 'cannot find tag', question.from, 'all tags', allTags)

      var toTagIndex = question.to === 'latest' ? 0
        : _.findIndex(allTags, 'name', question.to)
github bahmutov / changed-log / src / get-commits-between.js View on Github external
function getCommitsBetween (options) {
  utils.verifyRepoOptions(options)
  var schema = {
    from: check.commitId,
    to: check.commitId
  }
  la(check.schema(schema, options), 'invalid from and to commits', options)

  return getCommitsFrom(options.user, options.repo, options.to, options.from)
    .then(function (commits) {
      la(check.array(commits), 'could not get list of commits', options)
      debug('found %d commits finishing with the latest commit %s',
        commits.length, utils.shortenSha(options.to))

      return R.map(function (commit) {
        return {
          sha: commit.sha,
          message: commit.commit.message
        }
      }, commits)
    }).then(function (commits) {
      var fromIndex = _.findIndex(commits, 'sha', options.from)
      debug('from commit %s is at index %d', options.from, fromIndex)
github bahmutov / changed-log / src / get-comments-between-commits.js View on Github external
var R = require('ramda')
var _ = require('lodash')
var debug = require('debug')('between')

var getCommitsBetween = require('./get-commits-between')
la(check.fn(getCommitsBetween), 'missing function get commits between', getCommitsBetween)

var Report = require('./report')
var areValidOptions = check.schema.bind(null, {
  user: check.unemptyString,
  repo: check.unemptyString,
  from: check.commitId,
  to: check.commitId
})

var afterCommitOptions = check.schema({
  user: check.unemptyString,
  repo: check.unemptyString,
  from: check.commitId,
  to: check.not.defined
})

function getCommentsAfter (options) {
  debug('finding comments after %s/%s %s', options.user, options.repo, options.from)

  var report = new Report(options)
  return getCommitsBetween(options)
    .then(R.always(report))
}

function getCommentsBetweenCommits (options) {
  if (afterCommitOptions(options)) {
github bahmutov / snap-shot-core / src / file-system.js View on Github external
const snapshotsFolder = getSnapshotsFolder(specFile, opts)
  debug('for spec file %s', specFile)
  debug('making folder "%s" for snapshot if does not exist', snapshotsFolder)

  mkdirp.sync(snapshotsFolder)
  const filename = fileForSpec(specFile, ext, opts)
  const specRelativeName = fromCurrentFolder(specFile)
  debug('saving snapshots into %s for %s', filename, specRelativeName)
  debug('snapshots are')
  debug(snapshots)
  debug('saveSnapshots options %o', opts)

  return maybeSortAndSave(snapshots, filename, opts)
}

const isValidCompareResult = is.schema({
  orElse: is.fn
})

/**
 * Throws error if two values are different.
 *
 * value - what the test computed right now
 * expected - existing value loaded from snapshot
 */
function raiseIfDifferent (options) {
  options = options || {}

  const value = options.value
  const expected = options.expected
  const specName = options.specName
  const compare = options.compare