How to use the polyfill-library.listAllPolyfills function in polyfill-library

To help you get started, we’ve selected a few polyfill-library examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Financial-Times / polyfill-service-url-builder / src / index.js View on Github external
async function generatePolyfillURL(features = []) {
    const polyfillUrl = 'https://cdn.polyfill.io/v3/polyfill.min.js';
    const aliases = await polyfillLibrary.listAliases();
    const polyfills = await polyfillLibrary.listAllPolyfills();
    const featuresInPolyfillLibrary = new Set;

    for (const feature of features) {
        if (polyfills.includes(feature)) {
            featuresInPolyfillLibrary.add(feature);
        } else if (feature in aliases) {
            featuresInPolyfillLibrary.add(feature);
        } else if (feature.includes('.prototype')) {
            const featureConstructor = feature.split('.prototype')[0];
            if (polyfills.includes(featureConstructor)) {
                featuresInPolyfillLibrary.add(featureConstructor);
            } else if (featureConstructor in aliases) {
                featuresInPolyfillLibrary.add(featureConstructor);
            }
        }
    }