<commit_before>var npm = require('npm');
var moment = require('moment');
var RSS = require('rss');

function Package(name, versions) {
	this.name = name; // The name of the package
	this.versions = versions; // Versions and their pubdate as returned by NPM
	this.expires = moment().add(Package.TTL); // When the versions information is considered stale
}

Package.TTL = moment.duration({hours: 1});

var packages = {};

function FeedItem(name, previous, current, pubdate) {
	this.name = name;
	this.previous = previous;
	this.current = current;
	this.pubdate = pubdate;
}

// Create a bunch of Feed items from the passed package
function packageToFeedItems(pkg) {
	
	var previous = null;
	
	return Object.keys(pkg.versions).map(function(version) {
		
		var item = new FeedItem(pkg.name, previous, version, pkg.versions[version]);
		
		previous = version;
		
		return item;
	});
}

// Create the feed XML from the FeedItems
function buildFeedXml(items, name, depNames, limit) {
	
	limit = limit || 32;
	
	items.sort(function(a, b) {
		if(a.pubdate < b.pubdate) {
			return 1;
		} else if(a.pubdate === b.pubdate) {
			return 0;
		} else {
			return -1;
		}
	});
	
	items = items.slice(0, limit);
	
	var rssFeed = new RSS({
		title: 'Recently updated dependencies for ' + name,
		description: 'Version updates for ' + depNames.join(', '),
		site_url: 'https://david-dm.org/'
	});
	
	for(var i = 0, len = items.length; i < len; ++i) {
		rssFeed.item({
			title: items[i].name,
			description: items[i].previous + ' to ' + items[i].current,
			url: 'https://npmjs.org/package/' + items[i].name,
			date: items[i].pubdate
		});
	}
	
	return rssFeed.xml();
}

/**
 * Get a Package for a given package name guaranteed to be less old than Package.TTL
 * 
 * Must be executed in `npm.load()` callback.
 * 
 * @param pkgName
 * @param callback
 */
function getPackage(pkgName, callback) {
	
	var pkg = packages[pkgName];
	
	if(pkg && pkg.expires > new Date()) {
		callback(null, pkg);
		return;
	}<commit_msg>Move version information into title<commit_after>var npm = require('npm');
var moment = require('moment');
var RSS = require('rss');

function Package(name, versions) {
	this.name = name; // The name of the package
	this.versions = versions; // Versions and their pubdate as returned by NPM
	this.expires = moment().add(Package.TTL); // When the versions information is considered stale
}

Package.TTL = moment.duration({hours: 1});

var packages = {};

function FeedItem(name, previous, current, pubdate) {
	this.name = name;
	this.previous = previous;
	this.current = current;
	this.pubdate = pubdate;
}

// Create a bunch of Feed items from the passed package
function packageToFeedItems(pkg) {
	
	var previous = null;
	
	return Object.keys(pkg.versions).map(function(version) {
		
		var item = new FeedItem(pkg.name, previous, version, pkg.versions[version]);
		
		previous = version;
		
		return item;
	});
}

// Create the feed XML from the FeedItems
function buildFeedXml(items, name, depNames, limit) {
	
	limit = limit || 32;
	
	items.sort(function(a, b) {
		if(a.pubdate < b.pubdate) {
			return 1;
		} else if(a.pubdate === b.pubdate) {
			return 0;
		} else {
			return -1;
		}
	});
	
	items = items.slice(0, limit);
	
	var rssFeed = new RSS({
		title: 'Recently updated dependencies for ' + name,
		description: 'Version updates for ' + depNames.join(', '),
		site_url: 'https://david-dm.org/'
	});
	
	for(var i = 0, len = items.length; i < len; ++i) {
		rssFeed.item({
			title: items[i].name + ' ' + items[i].previous + ' to ' + items[i].current,
			url: 'https://npmjs.org/package/' + items[i].name,
			date: items[i].pubdate
		});
	}
	
	return rssFeed.xml();
}

/**
 * Get a Package for a given package name guaranteed to be less old than Package.TTL
 * 
 * Must be executed in `npm.load()` callback.
 * 
 * @param pkgName
 * @param callback
 */
function getPackage(pkgName, callback) {
	
	var pkg = packages[pkgName];
	
	if(pkg && pkg.expires > new Date()) {
		callback(null, pkg);
		return;
	}
{'fraction_non_alphanumeric': 0.1475941161805036, 'fraction_numerical': 0.0039890301670406384, 'mean_word_length': 3.5129358830146233, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '7328301', 'n_tokens_mistral': 1474, 'n_tokens_neox': 1304, 'n_words': 389}