Last active
May 13, 2019 17:32
-
-
Save gladchinda/2f8735f62e7f61e351b09bb50f7983e6 to your computer and use it in GitHub Desktop.
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 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