How to use the nopt.typeDefs function in nopt

To help you get started, we’ve selected a few nopt 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 babobski / Beautify-js / content / js / lib / cli.js View on Github external
var debug = process.env.DEBUG_JSBEAUTIFY || process.env.JSBEAUTIFY_DEBUG ? function() {
  console.error.apply(console, arguments);
} : function() {};

var fs = require('fs'),
  cc = require('config-chain'),
  beautify = require('../index'),
  mkdirp = require('mkdirp'),
  nopt = require('nopt');

nopt.invalidHandler = function(key, val) {
  throw new Error(key + " was invalid with value \"" + val + "\"");
};

nopt.typeDefs.brace_style = {
  type: "brace_style",
  validate: function(data, key, val) {
    data[key] = val;
    // TODO: expand-strict is obsolete, now identical to expand.  Remove in future version
    // TODO: collapse-preserve-inline is obselete, now identical to collapse,preserve-inline = true. Remove in future version
    var validVals = ["collapse", "collapse-preserve-inline", "expand", "end-expand", "expand-strict", "none", "preserve-inline"];
    var valSplit = val.split(/[^a-zA-Z0-9_\-]+/); //Split will always return at least one parameter
    for (var i = 0; i < valSplit.length; i++) {
      if (validVals.indexOf(valSplit[i]) === -1) {
        return false;
      }
    }
    return true;
  }
};
var path = require('path'),
github beautify-web / js-beautify / js / lib / cli.js View on Github external
var debug = process.env.DEBUG_JSBEAUTIFY || process.env.JSBEAUTIFY_DEBUG ? function() {
    console.error.apply(console, arguments);
} : function() {};

var fs = require('fs'),
    cc = require('config-chain'),
    beautify = require('../index'),
    mkdirp = require('mkdirp'),
    nopt = require('nopt'),
    glob = require('glob');

nopt.invalidHandler = function(key, val) {
    throw new Error(key + " was invalid with value \"" + val + "\"");
};

nopt.typeDefs.brace_style = {
    type: "brace_style",
    validate: function(data, key, val) {
        data[key] = val;
        // TODO: expand-strict is obsolete, now identical to expand.  Remove in future version
        // TODO: collapse-preserve-inline is obselete, now identical to collapse,preserve-inline = true. Remove in future version
        var validVals = ["collapse", "collapse-preserve-inline", "expand", "end-expand", "expand-strict", "none", "preserve-inline"];
        var valSplit = val.split(/[^a-zA-Z0-9_\-]+/); //Split will always return at least one parameter
        for (var i = 0; i < valSplit.length; i++) {
            if (validVals.indexOf(valSplit[i]) === -1) {
                return false;
            }
        }
        return true;
    }
};
var path = require('path'),
github sx1989827 / DOClever / node_modules / js-beautify / js / lib / cli.js View on Github external
*/

var debug = process.env.DEBUG_JSBEAUTIFY || process.env.JSBEAUTIFY_DEBUG ? function() {
    console.error.apply(console, arguments);
} : function() {};

var fs = require('fs'),
    cc = require('config-chain'),
    beautify = require('../index'),
    mkdirp = require('mkdirp'),
    nopt = require('nopt');
nopt.invalidHandler = function(key, val, types) {
    throw new Error(key + " was invalid with value \"" + val + "\"");
}
nopt.typeDefs.brace_style = {
    type: "brace_style",
    validate: function(data, key, val) {
        data[key] = val;
        // TODO: expand-strict is obsolete, now identical to expand.  Remove in future version
        // TODO: collapse-preserve-inline is obselete, now identical to collapse,preserve-inline = true. Remove in future version
        var validVals = ["collapse", "collapse-preserve-inline", "expand", "end-expand", "expand-strict", "none", "preserve-inline"];
        var valSplit = val.split(/[^a-zA-Z0-9_\-]+/); //Split will always return at least one parameter
        for (var i = 0; i < valSplit.length; i++) {
            if (validVals.indexOf(valSplit[i]) === -1) {
                return false;
            }
        }
        return true;
    }
};
var path = require('path'),
github feedhenry / fh-fhc / lib / utils / config-defs.js View on Github external
// defaults, types, and shorthands.

var path = require("path");
var url = require("url");
var Stream = require("stream").Stream;
var semver = require("semver");
var stableFamily = semver.parse(process.version);
var os = require("os");
var nopt = require("nopt");
var log = require("./log");

nopt.typeDefs.semver = { type: semver, validate: validateSemver };

function validateSemver(data, k, val) {
  if (!semver.valid(val)) {
    return false;
  }
  data[k] = semver.valid(val);
}

nopt.invalidHandler = function(k, val) {
  log.warn(k + "=" + JSON.stringify(val), "invalid config");
};

if (!stableFamily || (+stableFamily[2] % 2)) {
  stableFamily = null;
} else {
  stableFamily = stableFamily[1] + "." + stableFamily[2];
github npm / npmconf / config-defs.js View on Github external
}

function validateTag (data, k, val) {
  val = ('' + val).trim()
  if (!val || semver.validRange(val)) return false
  data[k] = val
}

function validateStream (data, k, val) {
  if (!(val instanceof Stream)) return false
  data[k] = val
}

nopt.typeDefs.semver = { type: semver, validate: validateSemver }
nopt.typeDefs.Octal = { type: Octal, validate: validateOctal }
nopt.typeDefs.Stream = { type: Stream, validate: validateStream }

// Don't let --tag=1.2.3 ever be a thing
var tag = {}
nopt.typeDefs.tag = { type: tag, validate: validateTag }

nopt.invalidHandler = function (k, val, type) {
  log.warn("invalid config", k + "=" + JSON.stringify(val))

  if (Array.isArray(type)) {
    if (type.indexOf(url) !== -1) type = url
    else if (type.indexOf(path) !== -1) type = path
  }

  switch (type) {
    case tag:
      log.warn("invalid config", "Tag must not be a SemVer range")
github davidhealey / waistline / node_modules / npm / lib / config / defaults.js View on Github external
function Umask () {}
function validateUmask (data, k, val) {
  return umask.validate(data, k, val)
}

function validateSemver (data, k, val) {
  if (!semver.valid(val)) return false
  data[k] = semver.valid(val)
}

function validateStream (data, k, val) {
  if (!(val instanceof Stream)) return false
  data[k] = val
}

nopt.typeDefs.semver = { type: semver, validate: validateSemver }
nopt.typeDefs.Stream = { type: Stream, validate: validateStream }
nopt.typeDefs.Umask = { type: Umask, validate: validateUmask }

nopt.invalidHandler = function (k, val, type) {
  log.warn("invalid config", k + "=" + JSON.stringify(val))

  if (Array.isArray(type)) {
    if (type.indexOf(url) !== -1) type = url
    else if (type.indexOf(path) !== -1) type = path
  }

  switch (type) {
    case Umask:
      log.warn("invalid config", "Must be umask, octal number in range 0000..0777")
      break
    case url:
github graalvm / graaljs / deps / npm / lib / config / defaults.js View on Github external
return umask.validate(data, k, val)
}

function validateSemver (data, k, val) {
  if (!semver.valid(val)) return false
  data[k] = semver.valid(val)
}

function validateStream (data, k, val) {
  if (!(val instanceof Stream)) return false
  data[k] = val
}

nopt.typeDefs.semver = { type: semver, validate: validateSemver }
nopt.typeDefs.Stream = { type: Stream, validate: validateStream }
nopt.typeDefs.Umask = { type: Umask, validate: validateUmask }

nopt.invalidHandler = function (k, val, type) {
  log.warn('invalid config', k + '=' + JSON.stringify(val))

  if (Array.isArray(type)) {
    if (type.indexOf(url) !== -1) type = url
    else if (type.indexOf(path) !== -1) type = path
  }

  switch (type) {
    case Umask:
      log.warn('invalid config', 'Must be umask, octal number in range 0000..0777')
      break
    case url:
      log.warn('invalid config', "Must be a full url with 'http://'")
      break
github louis-tru / ngui / node / deps / npm / lib / config / defaults.js View on Github external
function Umask () {}
function validateUmask (data, k, val) {
  return umask.validate(data, k, val)
}

function validateSemver (data, k, val) {
  if (!semver.valid(val)) return false
  data[k] = semver.valid(val)
}

function validateStream (data, k, val) {
  if (!(val instanceof Stream)) return false
  data[k] = val
}

nopt.typeDefs.semver = { type: semver, validate: validateSemver }
nopt.typeDefs.Stream = { type: Stream, validate: validateStream }
nopt.typeDefs.Umask = { type: Umask, validate: validateUmask }

nopt.invalidHandler = function (k, val, type) {
  log.warn('invalid config', k + '=' + JSON.stringify(val))

  if (Array.isArray(type)) {
    if (type.indexOf(url) !== -1) type = url
    else if (type.indexOf(path) !== -1) type = path
  }

  switch (type) {
    case Umask:
      log.warn('invalid config', 'Must be umask, octal number in range 0000..0777')
      break
    case url:
github nullivex / nodist / bin / node_modules / npm / node_modules / npmconf / config-defs.js View on Github external
data[k] = "0" + parseInt(val, 8).toString(8)
  }
}

function validateSemver (data, k, val) {
  if (!semver.valid(val)) return false
  data[k] = semver.valid(val)
}

function validateStream (data, k, val) {
  if (!(val instanceof Stream)) return false
  data[k] = val
}

nopt.typeDefs.semver = { type: semver, validate: validateSemver }
nopt.typeDefs.Octal = { type: Octal, validate: validateOctal }
nopt.typeDefs.Stream = { type: Stream, validate: validateStream }

nopt.invalidHandler = function (k, val, type, data) {
  log.warn("invalid config", k + "=" + JSON.stringify(val))

  if (Array.isArray(type)) {
    if (type.indexOf(url) !== -1) type = url
    else if (type.indexOf(path) !== -1) type = path
  }

  switch (type) {
    case Octal:
      log.warn("invalid config", "Must be octal number, starting with 0")
      break
    case url:
      log.warn("invalid config", "Must be a full url with 'http://'")
github graalvm / graaljs / deps / npm / lib / config / defaults.js View on Github external
function validateUmask (data, k, val) {
  return umask.validate(data, k, val)
}

function validateSemver (data, k, val) {
  if (!semver.valid(val)) return false
  data[k] = semver.valid(val)
}

function validateStream (data, k, val) {
  if (!(val instanceof Stream)) return false
  data[k] = val
}

nopt.typeDefs.semver = { type: semver, validate: validateSemver }
nopt.typeDefs.Stream = { type: Stream, validate: validateStream }
nopt.typeDefs.Umask = { type: Umask, validate: validateUmask }

nopt.invalidHandler = function (k, val, type) {
  log.warn('invalid config', k + '=' + JSON.stringify(val))

  if (Array.isArray(type)) {
    if (type.indexOf(url) !== -1) type = url
    else if (type.indexOf(path) !== -1) type = path
  }

  switch (type) {
    case Umask:
      log.warn('invalid config', 'Must be umask, octal number in range 0000..0777')
      break
    case url:
      log.warn('invalid config', "Must be a full url with 'http://'")

nopt

Option parsing for Node, supporting types, shorthands, etc. Used by npm.

ISC
Latest version published 4 months ago

Package Health Score

92 / 100
Full package analysis