<commit_before>// npm view [pkg [pkg ...]]

module.exports = view
view.usage = "npm view pkg[@version] [<field>[.subfield]...]"

view.completion = function (args, index, cb) {
  var registry = require("./utils/registry")
    , getCompletions = require("./utils/completion/get-completions")
    , remotePkgs = require("./utils/completion/remote-packages")
    , name = args[0] || ""
    , key = args[1] || ""

  if (index < 3) remotePkgs(args, index, true, false, false, cb)
  else if (index == 3) {
    var pieces = name.split("@")
    registry.get(pieces[0], pieces[1], 3600, function (er, d) {
      var cur = d.versions ? d.versions[d["dist-tags"].latest] : d
        , path = key.split(".")
        , options
      if (path.length > 1) {
        for (var i = 0; i < path.length; i++) {
          if (!cur) return cb()
          if (!cur[path[i]]) break
          else cur = cur[path[i]]
        }
        options = Object.keys(cur).map(function (e) {
          return path.slice(0, path.length - 1).join(".") + "." + e
        })
      } else options = Object.keys(cur).concat(["ctime","mtime","maintainers"])
      cb(null, getCompletions(key, options))
    })
  }
}

var registry = require("./utils/registry")
  , ini = require("./utils/ini-parser")
  , log = require("./utils/log")
  , sys = require("./utils/sys")
  , output = require("./utils/output")
  , npm = require("../npm")
  , semver = require("./utils/semver")
  , readJson = require("./utils/read-json")

function view (args, cb) {
  if (!args.length) return cb("Usage: "+view.usage)
  var pkg = args.shift()
    , nv = pkg.split("@")
    , name = nv.shift()
    , version = nv.join("@") || npm.config.get("tag")
  // get the data about this package
  registry.get(name, null, 600, function (er, data) {
    if (er) return cb(er)
    if (data["dist-tags"].hasOwnProperty(version)) {
      version = data["dist-tags"][version]
    }
    var results = []
      , error = null
    if (!args.length) args = [""]
    Object.keys(data.versions).forEach(function (v) {
      data.versions[v] = readJson.processJson(data.versions[v])
      if (semver.satisfies(v, version)) args.forEach(function (args) {
        results.push(showFields(data, data.versions[v], args))
      })
    })
    results = results.reduce(reducer, {})
    if (error) cb(error, results)
    else printData(results, cb)
  })
}
function reducer (l, r) {
  if (r) Object.keys(r).forEach(function (v) {
    l[v] = l[v] || {}
    Object.keys(r[v]).forEach(function (t) {
      l[v][t] = r[v][t]
    })
  })
  return l
}
// return whatever was printed
function showFields (data, version, fields) {
  var o = {}
  ;[data,version].forEach(function (s) {
    Object.keys(s).forEach(function (k) {
      o[k] = s[k]
    })
  })
  return search(o, fields.split("."), version._id, fields)
}<commit_msg>Add a silent flag to view<commit_after>// npm view [pkg [pkg ...]]

module.exports = view
view.usage = "npm view pkg[@version] [<field>[.subfield]...]"

view.completion = function (args, index, cb) {
  var registry = require("./utils/registry")
    , getCompletions = require("./utils/completion/get-completions")
    , remotePkgs = require("./utils/completion/remote-packages")
    , name = args[0] || ""
    , key = args[1] || ""

  if (index < 3) remotePkgs(args, index, true, false, false, cb)
  else if (index == 3) {
    var pieces = name.split("@")
    registry.get(pieces[0], pieces[1], 3600, function (er, d) {
      var cur = d.versions ? d.versions[d["dist-tags"].latest] : d
        , path = key.split(".")
        , options
      if (path.length > 1) {
        for (var i = 0; i < path.length; i++) {
          if (!cur) return cb()
          if (!cur[path[i]]) break
          else cur = cur[path[i]]
        }
        options = Object.keys(cur).map(function (e) {
          return path.slice(0, path.length - 1).join(".") + "." + e
        })
      } else options = Object.keys(cur).concat(["ctime","mtime","maintainers"])
      cb(null, getCompletions(key, options))
    })
  }
}

var registry = require("./utils/registry")
  , ini = require("./utils/ini-parser")
  , log = require("./utils/log")
  , sys = require("./utils/sys")
  , output = require("./utils/output")
  , npm = require("../npm")
  , semver = require("./utils/semver")
  , readJson = require("./utils/read-json")

function view (args, silent, cb) {
  if (typeof cb !== "function") cb = silent, silent = false
  if (!args.length) return cb("Usage: "+view.usage)
  var pkg = args.shift()
    , nv = pkg.split("@")
    , name = nv.shift()
    , version = nv.join("@") || npm.config.get("tag")
  // get the data about this package
  registry.get(name, null, 600, function (er, data) {
    if (er) return cb(er)
    if (data["dist-tags"].hasOwnProperty(version)) {
      version = data["dist-tags"][version]
    }
    var results = []
      , error = null
    if (!args.length) args = [""]
    Object.keys(data.versions).forEach(function (v) {
      data.versions[v] = readJson.processJson(data.versions[v])
      if (semver.satisfies(v, version)) args.forEach(function (args) {
        results.push(showFields(data, data.versions[v], args))
      })
    })
    results = results.reduce(reducer, {})
    if (error || silent) cb(error, results)
    else printData(results, cb)
  })
}
function reducer (l, r) {
  if (r) Object.keys(r).forEach(function (v) {
    l[v] = l[v] || {}
    Object.keys(r[v]).forEach(function (t) {
      l[v][t] = r[v][t]
    })
  })
  return l
}
// return whatever was printed
function showFields (data, version, fields) {
  var o = {}
  ;[data,version].forEach(function (s) {
    Object.keys(s).forEach(function (k) {
      o[k] = s[k]
    })
  })
  return search(o, fields.split("."), version._id, fields)
}
{'fraction_non_alphanumeric': 0.1968270571827057, 'fraction_numerical': 0.005927475592747559, 'mean_word_length': 2.784300791556728, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7094402', 'n_tokens_mistral': 2027, 'n_tokens_neox': 1969, 'n_words': 443}