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

croissant

v0.2.0

Published

A multimedia resource loader with error handling and cancellation.

Downloads

124

Readme

croissant

A multimedia resource loader with error handling and cancellation.

It is designed to load videos and images for widely browsers support (desktop and mobile) and with fallback capabilities (user can provides multiple mimetypes and image fallback).

This library only make sense if you want to programmatically use Image and Video and be sure they are loaded and ready to be drawn on Canvas or used in WebGL for instance.

(if you don't have programmatical use-case you should simply use <img/> and <video/>).

API example

var croissant = require("croissant");

var loader = croissant.loader({
  "video/webm": "cats.webm",
  "video/mp4": "cats.mp4",
  "image/png": "cats.fallback.png"
}, function (resource) {
  // resource can be:
  // { image: imageElement }
  // { video: videoElement }
  console.log("Loaded!", resource);
}, function (e) {
  // e is an Error or an Event
  console.log("Failed:", e);
});

// cancellation(); // Interrupt the loading when called

Decorators

There is currently 2 decorators:

  • timeout(loadFn, duration): creates a loader that interrupt loadFn if still not resolved after a duration (in milliseconds).
  • fallbackBlack(loadFn): creates an always successful loader that provides a black image in case loadFn failed (1 pixel black image).

Example

var croissant = require("croissant");

var loaderThatTimeoutAndFallback =
  croissant.fallbackBlack(
    croissant.timeout(
      croissant.loader,
      60000));

// Usage
var cancellation =
  loaderThatTimeoutAndFallback({
    "video/webm": "cats.webm",
    "video/mp4": "cats.mp4",
    "image/png": "cats.fallback.png"
  }, function (resource) {
    // resource can be:
    // { image: imageElement }
    // { video: videoElement }
    console.log(resource);
  });