src/utility.js
function readStylesheets(files, outputBanner) {
    return Promise.all(files.map((filename) => {
        if (isURL(filename)) {
            return new Promise((resolve, reject) => {
                request({
                    url: filename,
                    headers: { 'User-Agent': 'UnCSS' }
                }, (err, response, body) => {
                    if (err) {
                        return reject(err);
                    }
                    return resolve(body);
                });
            });
        } else if (fs.existsSync(filename)) {
            return new Promise((resolve, reject) => {
                fs.readFile(filename, 'utf-8', (err, contents) => {
                    if (err) {
                        return reject(err);
                    }
                    return resolve(contents);
                });
            });
        }
        throw new Error(`UnCSS: could not open ${path.join(process.cwd(), filename)}`);
    })).then((res) => {
        // res is an array of the content of each file in files (in the same order)
        if (outputBanner) {
            for (let i = 0, len = files.length; i < len; i++) {
                // We append a small banner to keep track of which file we are currently processing
                // super helpful for debugging
                const banner = `/*** uncss> filename: ${files[i].replace(/\\/g, '/')} ***/\n`;
                res[i] = banner + res[i];
            }
        }
        return res;
    });
}
function readStylesheets(files, outputBanner) {
    return Promise.all(files.map((filename) => {
        if (isURL(filename)) {
            return new Promise((resolve, reject) => {
                request({
                    url: filename,
                    headers: { 'User-Agent': 'UnCSS' }
                }, (err, response, body) => {
                    if (err) {
                        return reject(err);
                    }
                    return resolve(body);
                });
            });
        } else if (fs.existsSync(filename)) {
            return new Promise((resolve, reject) => {
                fs.readFile(filename, 'utf-8', (err, contents) => {
                    if (err) {
                        return reject(err);
                    }
                    return resolve(contents);
                });
            });
        }
        throw new Error(`UnCSS: could not open ${path.join(process.cwd(), filename)}`);
    })).then((res) => {
        // res is an array of the content of each file in files (in the same order)
        if (outputBanner) {
            for (let i = 0, len = files.length; i < len; i++) {
                // We append a small banner to keep track of which file we are currently processing
                // super helpful for debugging
                const banner = `/*** uncss> filename: ${files[i].replace(/\\/g, '/')} ***/\n`;
                res[i] = banner + res[i];
            }
        }
        return res;
    });
}
Given an array of filenames, return an array of the files' contents,
only if the filename matches a regex
@param  {Array}   files  An array of the filenames to read
@return {Promise}