<commit_before>var fmt = require('util').format,
    url = require('url'),
    isUrl = require('is-url'),
    gh = require('github-url-to-object'),
    normalizeLicenseData = require('normalize-license-data'),
    marky = require('marky-markdown'),
    presentUser = require("./user"),
    presentCollaborator = require("./collaborator");

module.exports = function (package) {

  delete package.maintainers

  package.scoped = package.name.charAt(0) === "@"
  package.encodedName = package.name.replace("/", "%2F")

  if (package.versions && package.versions.indexOf(package.version) === -1) {
    return Error('invalid package: '+ package.name);
  }

  package.license = normalizeLicenseData(package.license);
  if (!package.license) {
    delete package.license;
  }

  package.versionsCount = package.versions && Object.keys(package.versions).length;
  package.singleVersion = package.versionsCount === 1;

  if (package.publisher) {
    package.publisher = presentUser(package.publisher);
  }

  /* here's the potential situation: let's say I'm a hacker and I make a
  package that does Something Evil™ then I add you as a collaborators `npm
  adduser zeke evil-package` and then I publish the package and then I remove
  myself from the package so it looks like YOU are the one who made the
  package well, that's nasty so we blocked that from showing because
  hypothetically your friends would be like, hey! this evil-package from zeke
  looks awesome, let me use it! and then I get all their bank account numbers
  and get super duper rich and become a VC and create LinkedIn for Cats */

  package.lastPublisherIsACollaborator = Boolean(package.publisher)
    && Boolean(package.publisher.name)
    && Boolean(typeof package.collaborators === "object")
    && Boolean(package.collaborators[package.publisher.name])

  package.showCollaborators = package.collaborators
    && Object.keys(package.collaborators).length > 1
    && package.lastPublisherIsACollaborator;

  if (package.collaborators) {
    Object.keys(package.collaborators).forEach(function(name){
      var collaborator = package.collaborators[name];
      collaborator = presentCollaborator(collaborator);
    })
  }

  if (package.dependents) {
    package.dependents = processDependents(package.dependents, '/browse/depended/', package.name);
  }

  if (package.dependencies) {
    package.dependencies = processDependencies(package.dependencies);
  }

  // homepage: convert array to string
  if (package.homepage && Array.isArray(package.homepage)) {
    package.homepage = package.homepage[0];
  }

  // homepage: disallow non-URLs
  if (package.homepage && !isUrl(package.homepage)) {
    delete package.homepage;
  }

  // homepage: discard if github repo URL
  if (package.homepage && url.parse(package.homepage).hostname.match(/^(www\.)?github\.com/i)) {
    delete package.homepage;<commit_msg>show collaborators sidebar even if there’s only one collaborator. fixes #827<commit_after>var fmt = require('util').format,
    url = require('url'),
    isUrl = require('is-url'),
    gh = require('github-url-to-object'),
    normalizeLicenseData = require('normalize-license-data'),
    marky = require('marky-markdown'),
    presentUser = require("./user"),
    presentCollaborator = require("./collaborator");

module.exports = function (package) {

  delete package.maintainers

  package.scoped = package.name.charAt(0) === "@"
  package.encodedName = package.name.replace("/", "%2F")

  if (package.versions && package.versions.indexOf(package.version) === -1) {
    return Error('invalid package: '+ package.name);
  }

  package.license = normalizeLicenseData(package.license);
  if (!package.license) {
    delete package.license;
  }

  package.versionsCount = package.versions && Object.keys(package.versions).length;
  package.singleVersion = package.versionsCount === 1;

  if (package.publisher) {
    package.publisher = presentUser(package.publisher);
  }

  /* here's the potential situation: let's say I'm a hacker and I make a
  package that does Something Evil™ then I add you as a collaborators `npm
  adduser zeke evil-package` and then I publish the package and then I remove
  myself from the package so it looks like YOU are the one who made the
  package well, that's nasty so we blocked that from showing because
  hypothetically your friends would be like, hey! this evil-package from zeke
  looks awesome, let me use it! and then I get all their bank account numbers
  and get super duper rich and become a VC and create LinkedIn for Cats */

  package.lastPublisherIsACollaborator = Boolean(package.publisher)
    && Boolean(package.publisher.name)
    && Boolean(typeof package.collaborators === "object")
    && Boolean(package.collaborators[package.publisher.name])

  package.showCollaborators = package.collaborators
    && Object.keys(package.collaborators).length
    && package.lastPublisherIsACollaborator;

  if (package.collaborators) {
    Object.keys(package.collaborators).forEach(function(name){
      var collaborator = package.collaborators[name];
      collaborator = presentCollaborator(collaborator);
    })
  }

  if (package.dependents) {
    package.dependents = processDependents(package.dependents, '/browse/depended/', package.name);
  }

  if (package.dependencies) {
    package.dependencies = processDependencies(package.dependencies);
  }

  // homepage: convert array to string
  if (package.homepage && Array.isArray(package.homepage)) {
    package.homepage = package.homepage[0];
  }

  // homepage: disallow non-URLs
  if (package.homepage && !isUrl(package.homepage)) {
    delete package.homepage;
  }

  // homepage: discard if github repo URL
  if (package.homepage && url.parse(package.homepage).hostname.match(/^(www\.)?github\.com/i)) {
    delete package.homepage;
{'fraction_non_alphanumeric': 0.11930548392642255, 'fraction_numerical': 0.0024067388688327317, 'mean_word_length': 4.0945709281961475, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4379447', 'n_tokens_mistral': 1742, 'n_tokens_neox': 1649, 'n_words': 438}