npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

eleventy-plugin-responsive-picture

v1.0.0

Published

A plugin that provides shortcodes for converting images to responsive <picture> elements

Readme

A plugin that provides shortcodes for converting images to responsive <picture> elements.

Installation

# npm
npm i eleventy-plugin-responsive-picture

# yarn
yarn add eleventy-plugin-responsive-picture

Usage

Register the plugin in you .eleventy.js file:

const eleventyResponsivePicturePlugin = require("eleventy-plugin-responsive-picture");

module.exports = (eleventyConfig) => {
  eleventyConfig.addPlugin(eleventyResponsivePicturePlugin, { ...options });
});

In your layout, wrap an <img> tag with {% responsive %}.

For example:

{% responsive %}
<img src="/profile-picture.jpg">
{% endresponsive %}

The <img> will be wrapped with a <picture> element as specified in the configuration options

Options

ratios

Required. Type: number[]

An array of pixel density ratios for the srcset of each <source>. They are applied in the order supplied.

Example:

{
  ratio: [2, 1];
}

sources

Required. Type: { size: number, media?: string, type?: string }[]

A list of <source>s to generate, with the following properties:

  • media (string) an optional media query, e.g. (min-width: 1024px)
  • size (number) image size in pixels for the corresponding media query, e.g. 824
  • type (string) an optional mime type, e.g. image/jpeg

The order of sources is unchanged by the plugin.

resize()

Required. Type: (src: string, size: number, type: string) => string

A function that will return a URL for a resized version of the image.

Example:

{
  resize: (src, size) => `${src}?w=${size}`;
}

fallback()

Optional. Type: (src: string) => string.

A function that returns the URL of the image to use in the "fallback" <img> element. This allows you to serve a resized image by default, rather than a full-size image.

Example:

{
  resize: (src) => `${src}?w=1000`;
}

Example

Plugin registration

eleventyConfig.addPlugin(eleventyNavigationPlugin, {
  ratios: [2, 1],
  sources: [
    { media: "(min-width: 1024px)", size: 824 },
    { media: "(min-width: 768px)", size: 696 },
    { media: "(min-width: 420px)", size: 568 },
    { size: 348 },
  ],
  fallback: (src) => `${src}?w=1000`,
  resize: (src, width) => `${src}?w=${size}`,
});

Template use

{% responsive %}
<img src="./image.jpg" alt="My super cool image" />
{% endresponsive %}

Output:

<picture>
  <source
    media="(min-width: 1024px)"
    srcset="./image.jpg?w=1648 2x, ./image.jpg?w=824 1x"
  />
  <source
    media="(min-width: 768px)"
    srcset="./image.jpg?w=1392 2x, ./image.jpg?w=696 1x"
  />
  <source
    media="(min-width: 420px)"
    srcset="./image.jpg?w=1136 2x, ./image.jpg?w=568 1x"
  />
  <source srcset="./image.jpg?w=696 2x, ./image.jpg?w=348 1x" />
  <img src="./image.jpg?w=1000" alt="My super cool image" />
</picture>

Actual output does not include line breaks

License

This software is released under the MIT License.