Created
April 3, 2016 22:35
-
-
Save mrbobbybryant/817c13ba0b19f4a2dd75f916cafe1ddb to your computer and use it in GitHub Desktop.
Random js things
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Function converts the user provided query object into an encoded query string. | |
* @param {Object} argsObj The user provided query object from query method. | |
* @return {String} The query string portion of the endpoint url. | |
*/ | |
const buildQuery = (argsObj) => { | |
let queryString = []; | |
for (var property in argsObj) { | |
if (argsObj.hasOwnProperty(property)) { | |
queryString.push( | |
`${property}=${argsObj[property]}` | |
); | |
} | |
} | |
return queryString.join("&"); | |
} | |
const getFeaturedImage = (post) => { | |
if ( typeof post['_embedded']['https://api.w.org/featuredmedia'] !== 'undefined' ) { | |
let image = post['_embedded']['https://api.w.org/featuredmedia'][0]; | |
return post.featuredImage = image; | |
} | |
} | |
const getTaxonomyData = (post, type) => { | |
let pointer = embeddedTaxonomyIndex[type]; | |
if ( typeof post['_embedded']['https://api.w.org/term'][pointer] !== 'undefined' ) { | |
post[`${type}Data`] = post['_embedded']['https://api.w.org/term'][pointer]; | |
return post[`${type}Data`] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment