Skip to content

Instantly share code, notes, and snippets.

@gladchinda
Last active May 13, 2019 17:32
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 gladchinda/2f8735f62e7f61e351b09bb50f7983e6 to your computer and use it in GitHub Desktop.
Save gladchinda/2f8735f62e7f61e351b09bb50f7983e6 to your computer and use it in GitHub Desktop.
function squareImages({ width = 1, height = width } = {}) {
return width / height === 1;
}
function collectionToCSV(keys = []) {
return (collection = []) => {
const headers = keys.map(key => `"${key}"`).join(',');
const extractKeyValues = record => keys.map(key => `"${record[key]}"`).join(',');
return collection.reduce((csv, record) => {
return (`${csv}\n${extractKeyValues(record)}`).trim();
}, headers);
}
}
const exportFields = [ 'id', 'author', 'filename', 'format', 'width', 'height' ];
fetch('https://picsum.photos/list')
.then(response => response.json())
.then(data => data.filter(squareImages))
.then(collectionToCSV(exportFields))
.then(console.log, console.error);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment