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 🙏

© 2026 – Pkg Stats / Ryan Hefner

can-interchange

v0.0.2

Published

A clone of Foundation's interchange component using CanJS's can.view.attr.

Readme

Match Media Polyfill and Friends

I tried using simple media queries like so:

<p interchange-item="(max-width: 480px)">
    <img src="https://c1.staticflickr.com/3/2502/3730369443_dd0f2cfa44_m.jpg">
</p>

This works fine except when you want to have a group of items. In some cases, you don't want to render the innerHTML until the media query evaluates to true. Like in this example:

    <p interchange-item="(max-width: 480px)">
        <img src="https://c1.staticflickr.com/3/2502/3730369443_dd0f2cfa44_m.jpg">
    </p>
    <p interchange-item="(max-width: 1024px) and (min-width: 481px)">
        <img src="https://c1.staticflickr.com/3/2502/3730369443_dd0f2cfa44_z.jpg">
    </p>
    <p interchange-item="(only screen)">
        <img src="https://c1.staticflickr.com/3/2502/3730369443_7e6ec0ae75_o.jpg">
    </p>

The last item is our default. We don't want that item to render if the other two render. Furthermore, we don't want the any of the items to render until their query evaluates to true. This will prevent unnecessary loading of the image asset.

This is what I have now, which fixes my default issue:

<div interchange-parent>
    <p interchange-item="(max-width: 480px)">
        <img src="https://c1.staticflickr.com/3/2502/3730369443_dd0f2cfa44_m.jpg">
    </p>
    <p interchange-item="(max-width: 1024px) and (min-width: 481px)">
        <img src="https://c1.staticflickr.com/3/2502/3730369443_dd0f2cfa44_z.jpg">
    </p>
    <p interchange-default>
        <img src="https://c1.staticflickr.com/3/2502/3730369443_7e6ec0ae75_o.jpg">
    </p>
</div>

But I still have the problem of rendering the content before it is ready. This leads me to two ideas:

Idea 1:

<div interchange-parent>
    <p interchange-item="(max-width: 480px)" interchange-src="https://c1.staticflickr.com/3/2502/3730369443_dd0f2cfa44_m.jpg"></p>
    <p interchange-item="(max-width: 1024px) and (min-width: 481px)" interchange-src="https://c1.staticflickr.com/3/2502/3730369443_dd0f2cfa44_z.jpg"></p>
    <p interchange-default interchange-src="https://c1.staticflickr.com/3/2502/3730369443_7e6ec0ae75_o.jpg"></p>
</div>

Doing this will create an img element on the fly when the query evaluates to true.

Idea 2:

<div interchange-parent>
    <img interchange-item="(max-width: 480px)|https://c1.staticflickr.com/3/2502/3730369443_dd0f2cfa44_m.jpg">
    <img interchange-item="(max-width: 1024px) and (min-width: 481px)|https://c1.staticflickr.com/3/2502/3730369443_dd0f2cfa44_z.jpg">
    <img interchange-default="https://c1.staticflickr.com/3/2502/3730369443_7e6ec0ae75_o.jpg">
</div>

This uses the same api as Foundation. The can.view.attr knows what element the interchange is attaching to and will handle it properly. So, if, for example, one used a div instead of an img and the url ended in a valid image extension, than the image would be loaded as a background image property instead.

I would prefer to use what I have now. But instead of using jQuery's hide/show, I would wrap remove the innerHTML and move it to shadow dom, where I can toggle it's visiblity using a block helper with Stache. The end result would look kinda like:

<p interchange-item="(max-width: 480px)" style="{{#if visible}}display:block;{{else}}display:none;{{/if}}">
    {{! This would be false by default, then, when query evals to true, this becomes true for life.}}
    {{! This way, the innerHTML loads only when actually needed}}
    {{#matchedOnce}}
    <img src="https://c1.staticflickr.com/3/2502/3730369443_dd0f2cfa44_m.jpg">
    {{/matchedOnce}}
</p>

So, I tried this and there's a huge problem, the image tag renders on load just before I strip it out. This defeats the purpose since we don't want the browser to load the image source.

Documents used for research

  • http://foundation.zurb.com/sites/docs/v/5.5.3/components/interchange.html
  • https://developer.mozilla.org/en-US/docs/Web/CSS/Media_Queries/Using_media_queries
  • https://developer.mozilla.org/en-US/docs/Web/API/MediaQueryList