src/index.js
function _getPostings (options, markup) {
	let
		$ = cheerio.load(markup),
		// hostname = options.hostname,
		posting = {},
		postings = [],
		secure = options.secure;

	$('div.content')
		.find('.result-row')
		.each((i, element) => {
			let
				// introducing fix for #11 - Craigslist markup changed
				details = $(element)
					.find('.result-title')
					.attr('href')
					.split(/\//g)
					.filter((term) => term.length)
					.map((term) => term.split(RE_HTML)[0]),
				// fix for #6 and #24
				detailsUrl = url.parse($(element)
					.find('.result-title')
					.attr('href'));

			// ensure hostname and protocol are properly set
			detailsUrl.hostname = detailsUrl.hostname || options.hostname;
			detailsUrl.protocol = secure ? PROTOCOL_SECURE : PROTOCOL_INSECURE;

			posting = {
				category : details[DEFAULT_CATEGORY_DETAILS_INDEX],
				coordinates : {
					lat : $(element).attr('data-latitude'),
					lon : $(element).attr('data-longitude')
				},
				date : ($(element)
					.find('time')
					.attr('datetime') || '')
						.trim(),
				hasPic : RE_TAGS_MAP
					.test($(element)
						.find('.result-tags')
						.text() || ''),
				location : ($(element)
					.find('.result-hood')
					.text() || '')
					.trim(),
				pid : ($(element)
					.attr('data-pid') || '')
						.trim(),
				price : ($(element)
					.find('.result-meta .result-price')
					.text() || '')
						.replace(/^\&\#x0024\;/g, '')
						.trim(), // sanitize
				title : ($(element)
					.find('.result-title')
					.text() || '')
						.trim(),
				url : detailsUrl.format()
			};

			// make sure lat / lon is valid
			if (typeof posting.coordinates.lat === 'undefined' ||
				typeof posting.coordinates.lon === 'undefined') {
				delete posting.coordinates;
			}

			postings.push(posting);
		});

	return postings;
}
function _getPostings (options, markup) {
	let
		$ = cheerio.load(markup),
		// hostname = options.hostname,
		posting = {},
		postings = [],
		secure = options.secure;

	$('div.content')
		.find('.result-row')
		.each((i, element) => {
			let
				// introducing fix for #11 - Craigslist markup changed
				details = $(element)
					.find('.result-title')
					.attr('href')
					.split(/\//g)
					.filter((term) => term.length)
					.map((term) => term.split(RE_HTML)[0]),
				// fix for #6 and #24
				detailsUrl = url.parse($(element)
					.find('.result-title')
					.attr('href'));

			// ensure hostname and protocol are properly set
			detailsUrl.hostname = detailsUrl.hostname || options.hostname;
			detailsUrl.protocol = secure ? PROTOCOL_SECURE : PROTOCOL_INSECURE;

			posting = {
				category : details[DEFAULT_CATEGORY_DETAILS_INDEX],
				coordinates : {
					lat : $(element).attr('data-latitude'),
					lon : $(element).attr('data-longitude')
				},
				date : ($(element)
					.find('time')
					.attr('datetime') || '')
						.trim(),
				hasPic : RE_TAGS_MAP
					.test($(element)
						.find('.result-tags')
						.text() || ''),
				location : ($(element)
					.find('.result-hood')
					.text() || '')
					.trim(),
				pid : ($(element)
					.attr('data-pid') || '')
						.trim(),
				price : ($(element)
					.find('.result-meta .result-price')
					.text() || '')
						.replace(/^\&\#x0024\;/g, '')
						.trim(), // sanitize
				title : ($(element)
					.find('.result-title')
					.text() || '')
						.trim(),
				url : detailsUrl.format()
			};

			// make sure lat / lon is valid
			if (typeof posting.coordinates.lat === 'undefined' ||
				typeof posting.coordinates.lon === 'undefined') {
				delete posting.coordinates;
			}

			postings.push(posting);
		});

	return postings;
}
function _getPostings ( options , markup ) { let $ = cheerio . load ( markup ) , // hostname = options.hostname, posting = { } , postings = [ ] , secure = options . secure ; $ ( 'div.content' ) . find ( '.result-row' ) . each ( ( i , element ) => { let // introducing fix for #11 - Craigslist markup changed details = $ ( element ) . find ( '.result-title' ) . attr ( 'href' ) . split ( / \/ / g ) . filter ( ( term ) => term . length ) . map ( ( term ) => term . split ( RE_HTML ) [ 0 ] ) , // fix for #6 and #24 detailsUrl = url . parse ( $ ( element ) . find ( '.result-title' ) . attr ( 'href' ) ) ; // ensure hostname and protocol are properly set detailsUrl . hostname = detailsUrl . hostname || options . hostname ; detailsUrl . protocol = secure ? PROTOCOL_SECURE : PROTOCOL_INSECURE ; posting = { category : details [ DEFAULT_CATEGORY_DETAILS_INDEX ] , coordinates : { lat : $ ( element ) . attr ( 'data-latitude' ) , lon : $ ( element ) . attr ( 'data-longitude' ) } , date : ( $ ( element ) . find ( 'time' ) . attr ( 'datetime' ) || '' ) . trim ( ) , hasPic : RE_TAGS_MAP . test ( $ ( element ) . find ( '.result-tags' ) . text ( ) || '' ) , location : ( $ ( element ) . find ( '.result-hood' ) . text ( ) || '' ) . trim ( ) , pid : ( $ ( element ) . attr ( 'data-pid' ) || '' ) . trim ( ) , price : ( $ ( element ) . find ( '.result-meta .result-price' ) . text ( ) || '' ) . replace ( / ^\&\#x0024\; / g , '' ) . trim ( ) , // sanitize title : ( $ ( element ) . find ( '.result-title' ) . text ( ) || '' ) . trim ( ) , url : detailsUrl . format ( ) } ; // make sure lat / lon is valid if ( typeof posting . coordinates . lat === 'undefined' || typeof posting . coordinates . lon === 'undefined' ) { delete posting . coordinates ; } postings . push ( posting ) ; } ) ; return postings ; }
Accepts string of HTML and parses that string to find all pertinent postings.

@param {object} options - Request options used for the request to craigslist
@param {string} markup - Markup from the request to Craigslist
@returns {Array} postings - The processed and normalized array of postings
Accepts string of HTML and parses that string to find all pertinent postings .