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 🙏

© 2024 – Pkg Stats / Ryan Hefner

basic-imageloader

v1.0.1

Published

Simple tool that lets you wait until images are fully loaded

Downloads

8

Readme

basic-imageloader

 

basic-imageloader requires support for Promise to run. It does not come with a polyfill, supply your own if you want to support legacy environments!  

Arguments

  • {string | Array} url(s) to load
  • {boolean} strict mode

Usage

Takes an image URL or an array of URLs and returns a Promise that resolves when the images are loaded

BasicImageloader(['image.jpg', 'image2.jpg']).then(() = > console.log('all images loaded!'));

The Promise resolves to the loaded image or an array of the loaded images, so you can work with them afterwards (see Strict Mode for caveats)

BasicImageloader('image1.jpg').then(image =>
  image.height > image.width
    ? enablePortaitMode()
    : enableLandscapeMode();
);
// or with arrays
BasicImageloader(['img1.jpg', 'img2.jpg']).then(images => {
  for (let image of images) {
    console.log(image.width);
  }
});

And since these are Promises, you can of course also use async/await! :)

async function loadAndLogImage(img) {
  const loadedImage = await BasicImageloader(img);
  console.log(loadedImage);
}

Strict Mode

The function takes a boolean as second argument, which enables or disables strict mode for error handling. By default this is off, which means the Promise will resolve no matter what and if you are loading multiple images and one fails, it will still wait for the others to load before resolving.

Careful! In this case, you can't rely on the array the Promise resolves to to only contain images - it will also contain error events where images failed to load!

If you pass true as second argument the Promise immediately rejects if an image fails to load - even if other images are still loading. This way you can implement your own error handling and safely assume that the resulting array only contains valid images.