Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const makePolyfill = ({ uaString, cache }) => (
getPolyfillString({ uaString, minify: cache, features, unknown: "polyfill" })
.then(polyfill => {
const polyfillHeaders = {
...headers,
"Cache-Control": cache ? "max-age=31536000" : "no-cache",
"Content-Type": "application/javascript;charset=utf-8"
};
return {
status: 200,
statusDescription: "OK",
headers: Object.keys(polyfillHeaders).reduce(
(accum, key) => ({ ...accum, [key]: [{ key, value: polyfillHeaders[key] }] }), {}
),
body: polyfill
};
})
app.get(["/v3/polyfill.js", "/v3/polyfill.min.js"], async (request, response) => {
const params = getPolyfillParameters(request);
switch (params.version) {
case latestVersion: {
const bundle = await polyfillio.getPolyfillString(params);
await respondWithBundle(response, params, bundle);
break;
}
case "3.41.0": {
const bundle = await polyfillio_3_41_0.getPolyfillString(params);
await respondWithBundle(response, params, bundle);
break;
}
case "3.40.0": {
const bundle = await polyfillio_3_40_0.getPolyfillString(params);
await respondWithBundle(response, params, bundle);
break;
}
case "3.39.0": {
const bundle = await polyfillio_3_39_0.getPolyfillString(params);
await respondWithBundle(response, params, bundle);
return Promise.all(UAs.map(browser => {
const opts = {
features: PolyfillSet.fromQueryParam('default').get(),
uaString: browser.family+'/'+browser.ver,
};
return Promise.all([
polyfillservice.getPolyfillString(Object.assign({minify: true}, opts)),
polyfillservice.getPolyfillString(Object.assign({minify: false}, opts))
]).then(spread((minsrc, rawsrc) => {
const item = {
family: browser.family,
ver: browser.ver,
minsrc: minsrc,
rawbytes: rawsrc.length,
minbytes: minsrc.length
};
return new Promise(resolve => {
zlib.gzip(item.minsrc, (err, gzipsrc) => {
if (!err) {
item.gzipbytes = gzipsrc.length;
}
resolve(item);
});
});