How to use the srcset.stringify function in srcset

To help you get started, we’ve selected a few srcset 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 lowwebtech / low-web-extension / src / scripts / main.js View on Github external
function cleanSrcset( srcset, width ){
  const parsed = srcsetUtil.parse(srcset);
  
  let cleanedSrcset
  if( true ){
    cleanedSrcset = getSmallestSrcset( parsed, width )
  }else{
    cleanedSrcset = noRetinaSrcset( parsed )
  }

  if( cleanedSrcset ){
    return srcsetUtil.stringify(cleanedSrcset)
  }else{
    return false
  }
}
  // chrome.tabs.onUpdated.addListener(
github apostrophecms / sanitize-html / src / index.js View on Github external
if (a === 'srcset') {
              try {
                parsed = srcset.parse(value);
                each(parsed, function(value) {
                  if (naughtyHref('srcset', value.url)) {
                    value.evil = true;
                  }
                });
                parsed = filter(parsed, function(v) {
                  return !v.evil;
                });
                if (!parsed.length) {
                  delete frame.attribs[a];
                  return;
                } else {
                  value = srcset.stringify(filter(parsed, function(v) {
                    return !v.evil;
                  }));
                  frame.attribs[a] = value;
                }
              } catch (e) {
                // Unparseable srcset
                delete frame.attribs[a];
                return;
              }
            }
            if (a === 'class') {
              value = filterClasses(value, allowedClassesMap[name]);
              if (!value.length) {
                delete frame.attribs[a];
                return;
              }
github lowwebtech / low-web-extension / src / scripts / content_script / image / srcset.js View on Github external
function cleanSrcset(srcset, width) {
  const parsed = srcsetUtil.parse(srcset);
  let cleanedSrcset;
  switch (parseInt(store.getters.image_srcset)) {
    case 1:
      cleanedSrcset = noRetina(parsed);
      break;
    case 2:
      cleanedSrcset = smallest(parsed, width);
      break;
    case 3:
      cleanedSrcset = smart(parsed, width);
      break;
  }
  if (cleanedSrcset) {
    return srcsetUtil.stringify(cleanedSrcset);
  } else {
    return false;
  }
}
github website-scraper / node-website-scraper / lib / resource-handler / path-containers / html-img-srcset-tag.js View on Github external
updateText (pathsToUpdate) {
		const imgSrcsetParts = this.imgSrcsetParts;
		pathsToUpdate.forEach(function updatePath (path) {
			const srcsToUpdate = _.filter(imgSrcsetParts, {url: path.oldPath});
			srcsToUpdate.forEach((srcToUpdate) => {
				srcToUpdate.url = path.newPath;
			});
		});
		return srcset.stringify(imgSrcsetParts);
	}
}
github danburzo / percollate / src / enhancements.js View on Github external
function absoluteSrcset(str) {
		return srcset.stringify(
			srcset.parse(str).map(item => ({
				...item,
				url: new URL(item.url, doc.baseURI).href
			}))
		);
	}
github interactivethings / catalog / packages / core / src / specimens / Image.js View on Github external
className={css(styles.image)}
            srcSet={srcset.stringify(imageSrcset)}
            src={fallbackSrc}
          />
          {overlay && (
            <div>
              <img src="{fallbackOverlay}" srcset="{srcset.stringify(overlaySrcset)}">
            </div>
          )}
        
        {(title || description) &amp;&amp; (
          <div>
            {title &amp;&amp; <div>{title}</div>}
            {description &amp;&amp; (
              <div>
                {renderMarkdown({ text: description })}
              </div>
            )}
          </div>
        )}

srcset

Parse and stringify the HTML `<img>` srcset attribute

MIT
Latest version published 11 months ago

Package Health Score

71 / 100
Full package analysis

Popular srcset functions