<commit_before>/*!
 * cnpmjs.org - controllers/web/package.js
 *
 * Copyright(c) cnpmjs.org and other contributors.
 * MIT Licensed
 *
 * Authors:
 *  dead_horse <<EMAIL>> (http://deadhorse.me)
 */

'use strict';

/**
 * Module dependencies.
 */

var moment = require('moment');
var eventproxy = require('eventproxy');
var semver = require('semver');
var marked = require('marked');
var gravatar = require('gravatar');
var humanize = require('humanize-number');
var Module = require('../../proxy/module');
var down = require('../download');
var sync = require('../sync');
var Log = require('../../proxy/module_log');

exports.display = function (req, res, next) {
  var params = req.params;
  var name = params.name;
  var tag = params.version;
  var ep = eventproxy.create();
  ep.fail(next);

  if (tag) {
    var version = semver.valid(tag);
    if (version) {
      Module.get(name, version, ep.done('pkg'));
    } else {
      Module.getByTag(name, tag, ep.done('pkg'));
    }
  } else {
    Module.getByTag(name, 'latest', ep.done('pkg'));
  }

  down.total(name, ep.done('download'));

  ep.all('pkg', 'download', function (pkg, download) {
    if (!pkg || !pkg.package) {
      return next();
    }

    pkg.package.fromNow = moment(pkg.publish_time).fromNow();
    pkg = pkg.package;
    pkg.readme = marked(pkg.readme || '');
    if (pkg.maintainers) {
      for (var i = 0; i < pkg.maintainers.length; i++) {
        var maintainer = pkg.maintainers[i];
        if (maintainer.email) {
          maintainer.gravatar = gravatar.url(maintainer.email, {s: '50', d: 'retro'}, false);
        }
      }
    }

    if (pkg.contributors) {
      for (var i = 0; i < pkg.contributors.length; i++) {
        var contributor = pkg.contributors[i];
        if (contributor.email) {
          contributor.gravatar = gravatar.url(contributor.email, {s: '50', d: 'retro'}, false);
        }
      }
    }

    setLicense(pkg);

    for (var k in download) {
      download[k] = humanize(download[k]);
    }

    res.render('package', {<commit_msg>contributors maybe a object<commit_after>/*!
 * cnpmjs.org - controllers/web/package.js
 *
 * Copyright(c) cnpmjs.org and other contributors.
 * MIT Licensed
 *
 * Authors:
 *  dead_horse <<EMAIL>> (http://deadhorse.me)
 */

'use strict';

/**
 * Module dependencies.
 */

var moment = require('moment');
var eventproxy = require('eventproxy');
var semver = require('semver');
var marked = require('marked');
var gravatar = require('gravatar');
var humanize = require('humanize-number');
var Module = require('../../proxy/module');
var down = require('../download');
var sync = require('../sync');
var Log = require('../../proxy/module_log');

exports.display = function (req, res, next) {
  var params = req.params;
  var name = params.name;
  var tag = params.version;
  var ep = eventproxy.create();
  ep.fail(next);

  if (tag) {
    var version = semver.valid(tag);
    if (version) {
      Module.get(name, version, ep.done('pkg'));
    } else {
      Module.getByTag(name, tag, ep.done('pkg'));
    }
  } else {
    Module.getByTag(name, 'latest', ep.done('pkg'));
  }

  down.total(name, ep.done('download'));

  ep.all('pkg', 'download', function (pkg, download) {
    if (!pkg || !pkg.package) {
      return next();
    }

    pkg.package.fromNow = moment(pkg.publish_time).fromNow();
    pkg = pkg.package;
    pkg.readme = marked(pkg.readme || '');
    if (pkg.maintainers) {
      for (var i = 0; i < pkg.maintainers.length; i++) {
        var maintainer = pkg.maintainers[i];
        if (maintainer.email) {
          maintainer.gravatar = gravatar.url(maintainer.email, {s: '50', d: 'retro'}, false);
        }
      }
    }

    if (pkg.contributors) {
      // registry.cnpmjs.org/compressible
      if (!Array.isArray(pkg.contributors)) {
        pkg.contributors = [pkg.contributors];
      }
      for (var i = 0; i < pkg.contributors.length; i++) {
        var contributor = pkg.contributors[i];
        if (contributor.email) {
          contributor.gravatar = gravatar.url(contributor.email, {s: '50', d: 'retro'}, false);
        }
      }
    }

    setLicense(pkg);

    for (var k in download) {
      download[k] = humanize(download[k]);
    }

    res.render('package', {
{'fraction_non_alphanumeric': 0.17950530035335688, 'fraction_numerical': 0.0028268551236749115, 'mean_word_length': 2.832129963898917, 'pattern_counts': {'":': 0, '<': 11, '<?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': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1521826', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1386, 'n_words': 314}