billboard-top-100.js
function getChart(chartName, date, cb) {
	// check if chart was specified
	if (typeof chartName === 'function') {
		// if chartName not specified, default to hot-100 chart for current week, 
		// and set callback method accordingly
		cb = chartName;
		chartName = 'hot-100';
		date = '';
	}
	// check if date was specified
	if (typeof date === 'function') {
		// if date not specified, default to specified chart for current week, 
		// and set callback method accordingly
		cb = date;
		date = '';
	}
	var chart = {};
	/**
	 * A song
	 * @typedef {Object} Song
	 * @property {string} title - The title of the song
	 * @property {string} artist - The song's artist
	 */

	/**
	 * Array of songs
	 */
	chart.songs = [];
	// build request URL string for specified chart and date
	var requestURL = BILLBOARD_CHARTS_URL + chartName + '/' + date;
	request(requestURL, function completedRequest(error, response, html) {
		if (error) {
			cb(error, null);
			return;
		}
		var $ = cheerio.load(html);
		// get chart week
		chart.week = yyyymmddDateFromMonthDayYearDate($('.chart-detail-header__date-selector-button')[0].children[0].data.replace(/\n/g, ''));
		// get previous and next charts
		chart.previousWeek = getNeighboringChart($('.dropdown__date-selector-option '), NeighboringWeek.Previous);
		chart.nextWeek = getNeighboringChart($('.dropdown__date-selector-option '), NeighboringWeek.Next);
		// push remaining ranked songs into chart.songs array
		$('.chart-list-item').each(function(index, item) {
			var rank = index + 1;
			chart.songs.push({
				"rank": rank,
				"title": getTitleFromChartItem(item),
				"artist": getArtistFromChartItem(item),
				"cover": getCoverFromChartItem(item, rank),
				"position" : {
					"positionLastWeek": getPositionLastWeekFromChartItem(item),
					"peakPosition": getPeakPositionFromChartItem(item),
					"weeksOnChart": getWeeksOnChartFromChartItem(item)
				}
			});
		});
		// callback with chart if chart.songs array was populated
		if (chart.songs.length > 1){
			cb(null, chart);
			return;
		} else {
			cb("Songs not found.", null);
			return;
		}
	});

}
function getChart(chartName, date, cb) {
	// check if chart was specified
	if (typeof chartName === 'function') {
		// if chartName not specified, default to hot-100 chart for current week, 
		// and set callback method accordingly
		cb = chartName;
		chartName = 'hot-100';
		date = '';
	}
	// check if date was specified
	if (typeof date === 'function') {
		// if date not specified, default to specified chart for current week, 
		// and set callback method accordingly
		cb = date;
		date = '';
	}
	var chart = {};
	/**
	 * A song
	 * @typedef {Object} Song
	 * @property {string} title - The title of the song
	 * @property {string} artist - The song's artist
	 */

	/**
	 * Array of songs
	 */
	chart.songs = [];
	// build request URL string for specified chart and date
	var requestURL = BILLBOARD_CHARTS_URL + chartName + '/' + date;
	request(requestURL, function completedRequest(error, response, html) {
		if (error) {
			cb(error, null);
			return;
		}
		var $ = cheerio.load(html);
		// get chart week
		chart.week = yyyymmddDateFromMonthDayYearDate($('.chart-detail-header__date-selector-button')[0].children[0].data.replace(/\n/g, ''));
		// get previous and next charts
		chart.previousWeek = getNeighboringChart($('.dropdown__date-selector-option '), NeighboringWeek.Previous);
		chart.nextWeek = getNeighboringChart($('.dropdown__date-selector-option '), NeighboringWeek.Next);
		// push remaining ranked songs into chart.songs array
		$('.chart-list-item').each(function(index, item) {
			var rank = index + 1;
			chart.songs.push({
				"rank": rank,
				"title": getTitleFromChartItem(item),
				"artist": getArtistFromChartItem(item),
				"cover": getCoverFromChartItem(item, rank),
				"position" : {
					"positionLastWeek": getPositionLastWeekFromChartItem(item),
					"peakPosition": getPeakPositionFromChartItem(item),
					"weeksOnChart": getWeeksOnChartFromChartItem(item)
				}
			});
		});
		// callback with chart if chart.songs array was populated
		if (chart.songs.length > 1){
			cb(null, chart);
			return;
		} else {
			cb("Songs not found.", null);
			return;
		}
	});

}
function getChart ( chartName , date , cb ) { // check if chart was specified if ( typeof chartName === 'function' ) { // if chartName not specified, default to hot-100 chart for current week,  // and set callback method accordingly cb = chartName ; chartName = 'hot-100' ; date = '' ; } // check if date was specified if ( typeof date === 'function' ) { // if date not specified, default to specified chart for current week,  // and set callback method accordingly cb = date ; date = '' ; } var chart = { } ; /**
	 * A song
	 * @typedef {Object} Song
	 * @property {string} title - The title of the song
	 * @property {string} artist - The song's artist
	 */ /**
	 * Array of songs
	 */ chart . songs = [ ] ; // build request URL string for specified chart and date var requestURL = BILLBOARD_CHARTS_URL + chartName + '/' + date ; request ( requestURL , function completedRequest ( error , response , html ) { if ( error ) { cb ( error , null ) ; return ; } var $ = cheerio . load ( html ) ; // get chart week chart . week = yyyymmddDateFromMonthDayYearDate ( $ ( '.chart-detail-header__date-selector-button' ) [ 0 ] . children [ 0 ] . data . replace ( / \n / g , '' ) ) ; // get previous and next charts chart . previousWeek = getNeighboringChart ( $ ( '.dropdown__date-selector-option ' ) , NeighboringWeek . Previous ) ; chart . nextWeek = getNeighboringChart ( $ ( '.dropdown__date-selector-option ' ) , NeighboringWeek . Next ) ; // push remaining ranked songs into chart.songs array $ ( '.chart-list-item' ) . each ( function ( index , item ) { var rank = index + 1 ; chart . songs . push ( { "rank" : rank , "title" : getTitleFromChartItem ( item ) , "artist" : getArtistFromChartItem ( item ) , "cover" : getCoverFromChartItem ( item , rank ) , "position" : { "positionLastWeek" : getPositionLastWeekFromChartItem ( item ) , "peakPosition" : getPeakPositionFromChartItem ( item ) , "weeksOnChart" : getWeeksOnChartFromChartItem ( item ) } } ) ; } ) ; // callback with chart if chart.songs array was populated if ( chart . songs . length > 1 ) { cb ( null , chart ) ; return ; } else { cb ( "Songs not found." , null ) ; return ; } } ) ; }
Gets information for specified chart and date

@param {string} chartName - The specified chart
@param {string} date - Date represented as string in format 'YYYY-MM-DD'
@param {function} cb - The specified callback method

@example

getChart('hot-100', '2016-08-27', function(err, chart) {...})
Gets information for specified chart and date