@ou-imdt/utils
Version:
Utility library for interactive media development
17 lines (16 loc) • 675 B
JavaScript
import getFetchDetail from './getFetchDetail.js';
import fetchAs from './fetchAs.js';
/**
* Fetches all by calling fetchAs for each item in list, with option of globally mapped types via file extension (e.g. map[ext])
* or locally overriden via url suffix (e.g. '.../test.json?blob'), type defaults to file extension
* @param {array} list - a list of urls
* @param {object} [map] - key/value type mappings, e.g. json: 'blob'
* @returns {Promise}
*/
export default function fetchAll(list, map = {}) {
return Promise.all(list.map(value => {
const { url, as, ext } = getFetchDetail(value);
const type = (as ?? map[ext]);
return fetchAs(url, type);
}));
};