How to use the check-more-types.number 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 / start-server-and-test / src / utils.js View on Github external
return str.map(s => {
    if (is.url(s)) {
      return s
    }

    if (is.number(s) && is.port(s)) {
      return `http://localhost:${s}`
    }

    if (!is.string(s)) {
      return s
    }

    if (is.port(parseInt(s))) {
      return `http://localhost:${s}`
    }

    if (s[0] === ':') {
      return `http://localhost${s}`
    }
    // for anything else, return original argument
    return s
github bahmutov / liverage / src / index.js View on Github external
const statementCovered = (options) => {
  // console.log('%s s %s covered %d', options.name, options.s, options.counter)
  if (server && cover) {
    la(is.unemptyString(options.s), 'no covered statement', options)
    la(is.unemptyString(options.filename), 'no filename', options)
    const fileCoverage = cover[options.filename]
    if (fileCoverage) {
      const statementInfo = fileCoverage.statementMap[options.s]
      la(statementInfo, 'missing start for statement', options.s)
      const firstLine = statementInfo.start.line
      la(is.number(firstLine), 'not a number of line', statementInfo)
      console.log('line', firstLine, 'counter', options.counter)
      server.statementCovered(options.filename, firstLine, options.counter)
    }
  }
}
github bahmutov / now-pipeline / src / index.js View on Github external
function waitUntilDeploymentReady (id, secondsRemaining) {
    la(is.number(secondsRemaining), 'wrong waiting limit', secondsRemaining)
    const sleepSeconds = 5
    return checkDeploy(id)
      .then(r => {
        console.log(r.state, r.host, 'limit', secondsRemaining, 'seconds')
        if (r.state === 'READY') {
          return r
        }
        if (isDeploying(r.state)) {
          if (secondsRemaining < sleepSeconds) {
            throw new Error('Deploy timed out\n' + JSON.stringify(r))
          }
          return wait(sleepSeconds)
            .then(() => waitUntilDeploymentReady(id, secondsRemaining - sleepSeconds))
        }
        throw new Error('Something went wrong with the deploy\n' + JSON.stringify(r))
      })
github bahmutov / snap-shot / src / index.js View on Github external
startLine = out.startLine
  }

  if (!specName) {
    console.error('Problem finding caller')
    console.trace()

    const relativeName = fs.fromCurrentFolder(file)
    const msg = `Could not determine test for ${relativeName}
      line ${line} column ${column}`
    throw new Error(msg)
  }
  debug(`found spec name "${specName}" for line ${line} column ${column}`)
  la(is.unemptyString(specSource), 'could not get spec source from',
    file, 'line', line, 'column', column, 'named', specName)
  la(is.number(startLine), 'could not determine spec function start line',
    file, 'line', line, 'column', column, 'named', specName)

  if (isDataDriven(arguments)) {
    debug(`data-driven test for ${what.name}`)
    what = dataDriven(what, Array.from(arguments).slice(1))
  }

  const setOrCheckValue = any => {
    const value = strip(any)
    snapShotCore({
      what: value,
      file,
      specName,
      compare: compare,
      ext: SNAP_SHOT_EXTENSION,
      opts
github bahmutov / dont-break / src / top-dependents.js View on Github external
.then(function statsToDownloads(stats) {
      la(check.array(stats) && stats.length === 1, 'expected single stats', stats);
      la(check.number(stats[0].downloads), 'invalid number of downloads', stats);

      var n = stats[0].downloads;
      downloads[name] = n;
      console.log(name, 'has been downloaded', n, 'times');
      return n;
    });
}
github bahmutov / center-code / index.js View on Github external
function padHorizontally(terminal, text, columns) {
  if (check.not.number(columns)) {
    columns = textSize(text).columns;
  }
  la(check.number(columns), 'missing number of columns', text);

  var lines = text.split('\n');
  var blankColumns = Math.floor((terminal.width - columns) / 2);
  var blankPrefix = blanks(blankColumns);
  log('blank prefix "%s" %d columns', blankPrefix, blankPrefix.length);

  var padded = lines.map(function (line) {
    return blankPrefix + line;
  });

  return padded.join('\n');
}
github bahmutov / data-cover / src / utils.js View on Github external
function functionLabel (name, start) {
  if (arguments.length === 1) {
    return functionLabelFromFunctionNode.apply(null, arguments)
  }
  la(is.unemptyString(name), 'missing function name')
  la(is.number(start), 'missing start index')
  return name + ':' + start
}
github bahmutov / liverage / src / covered-lines.js View on Github external
function getLinesForStatement (statementMap, statement) {
  la(is.unemptyString(statement), 'invalid statement index', statement)
  const map = statementMap[statement]
  la(is.object(map), 'cannot find statement map for', statement, 'in', statementMap)
  const startLine = map.start.line
  la(is.number(startLine), 'invalid start', map.start, 'for', statement)
  const endLine = map.end.line
  la(is.number(endLine), 'invalid end', map.end, 'for', statement)
  la(startLine <= endLine, 'start should be before end', map.start, map.end)

  return [startLine]
}
github bahmutov / rambo / src / produce.js View on Github external
function deriveRange (output) {
  if (is.not.array(output)) {
    return
  }
  if (is.empty(output)) {
    return
  }
  if (!output.every(is.number)) {
    return
  }
  const first = output[0]
  const last = R.last(output)
  la(is.number(last), 'invalid last element in list', output)
  const after = last + 1
  return {
    f: R.always(R.range(first, after)),
    name: `R.range(${first}, ${after})`
  }
}
github bahmutov / liverage / src / covered-lines.js View on Github external
function getLinesForStatement (statementMap, statement) {
  la(is.unemptyString(statement), 'invalid statement index', statement)
  const map = statementMap[statement]
  la(is.object(map), 'cannot find statement map for', statement, 'in', statementMap)
  const startLine = map.start.line
  la(is.number(startLine), 'invalid start', map.start, 'for', statement)
  const endLine = map.end.line
  la(is.number(endLine), 'invalid end', map.end, 'for', statement)
  la(startLine <= endLine, 'start should be before end', map.start, map.end)

  return [startLine]
}