How to use oust - 4 common examples

To help you get started, we’ve selected a few oust 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 addyosmani / critical / lib / core.js View on Github external
return htmlfile => {
        // Consider opts.css and map to array if it isn't one
        if (opts.css) {
            const css = Array.isArray(opts.css) ? opts.css : [opts.css];
            return Bluebird.map(css, stylesheet => file.assertLocal(stylesheet, opts)).then(stylesheets => {
                htmlfile.stylesheets = stylesheets;
                return htmlfile;
            });
        }

        // Oust extracts a list of your stylesheets
        let stylesheets = flatten([
            oust.raw(htmlfile.contents.toString(), 'stylesheets'),
            oust.raw(htmlfile.contents.toString(), 'preload')
        ]).filter(link => link.$el.attr('media') !== 'print' && Boolean(link.value)).map(link => link.value);

        stylesheets = uniq(stylesheets).map(file.resourcePath(htmlfile, opts));
        debug('appendStylesheets', stylesheets);

        if (stylesheets.length === 0) {
            return Promise.reject(new Error('No usable stylesheets found in html source. Try to specify the stylesheets manually.'));
        }

        return Bluebird.map(stylesheets, stylesheet => file.assertLocal(stylesheet, opts)).then(stylesheets => {
            htmlfile.stylesheets = stylesheets;
            return htmlfile;
        });
    };
}
github addyosmani / critical / lib / core.js View on Github external
return htmlfile => {
        // Consider opts.css and map to array if it isn't one
        if (opts.css) {
            const css = Array.isArray(opts.css) ? opts.css : [opts.css];
            return Bluebird.map(css, stylesheet => file.assertLocal(stylesheet, opts)).then(stylesheets => {
                htmlfile.stylesheets = stylesheets;
                return htmlfile;
            });
        }

        // Oust extracts a list of your stylesheets
        let stylesheets = flatten([
            oust.raw(htmlfile.contents.toString(), 'stylesheets'),
            oust.raw(htmlfile.contents.toString(), 'preload')
        ]).filter(link => link.$el.attr('media') !== 'print' && Boolean(link.value)).map(link => link.value);

        stylesheets = uniq(stylesheets).map(file.resourcePath(htmlfile, opts));
        debug('appendStylesheets', stylesheets);

        if (stylesheets.length === 0) {
            return Promise.reject(new Error('No usable stylesheets found in html source. Try to specify the stylesheets manually.'));
        }

        return Bluebird.map(stylesheets, stylesheet => file.assertLocal(stylesheet, opts)).then(stylesheets => {
            htmlfile.stylesheets = stylesheets;
            return htmlfile;
        });
    };
}
github addyosmani / critical / src / file.js View on Github external
function getStylesheetHrefs(file) {
  if (!isVinyl(file)) {
    throw new Error('Parameter file needs to be a vinyl object');
  }

  const stylesheets = oust.raw(file.contents.toString(), 'stylesheets');
  const preloads = oust.raw(file.contents.toString(), 'preload');

  return [...stylesheets, ...preloads]
    .filter(link => link.$el.attr('media') !== 'print' && Boolean(link.value))
    .map(link => link.value);
}
github addyosmani / critical / src / file.js View on Github external
function getStylesheetHrefs(file) {
  if (!isVinyl(file)) {
    throw new Error('Parameter file needs to be a vinyl object');
  }

  const stylesheets = oust.raw(file.contents.toString(), 'stylesheets');
  const preloads = oust.raw(file.contents.toString(), 'preload');

  return [...stylesheets, ...preloads]
    .filter(link => link.$el.attr('media') !== 'print' && Boolean(link.value))
    .map(link => link.value);
}

oust

Extract URLs to stylesheets, scripts, links, images or HTML imports from HTML

Apache-2.0
Latest version published 2 years ago

Package Health Score

61 / 100
Full package analysis

Popular oust functions