Skip to content

Instantly share code, notes, and snippets.

@mrbobbybryant
Created April 3, 2016 22:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrbobbybryant/817c13ba0b19f4a2dd75f916cafe1ddb to your computer and use it in GitHub Desktop.
Save mrbobbybryant/817c13ba0b19f4a2dd75f916cafe1ddb to your computer and use it in GitHub Desktop.
Random js things
/**
* 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