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

@jbreneman/lazuli-js

v1.2.3

Published

A lazy loading library

Downloads

6

Readme

Lazuli

Lazuli is a promise based image lazyloader that works for both images and background images.

Installation

npm i @jbreneman/lazuli-js -S or yarn add @jbreneman/lazuli-js.

Usage

ES modules: import Lazuli from '@jbreneman/lazuli-js'; CJS modules: var Lazuli = require('@jbreneman/lazuli-js'); Global: Make sure it's getting included in your build somehow, then use as normal.

There are 3 different files being built, CommonJS, ES6 module, and UMD. You may need to tell your bundler to grab the right file if you're running into import issues.

In your HTML

Lazuli uses data attributes in place of actual attributes. Basically, take the normal attribute you would normally use and slap a data- in front of it and you're good to go. Lazuli supports all responsive images attributes as long as they're supported by the browser.

<img class="lazuli" data-src="image.jpg" alt="Basic example">

<img class="lazuli" data-src="image.jpg" data-srcset="image-200.jpg 200w, image-400.jpg 400w, image-800.jpg 800w" data-sizes="(max-width: 680px) 100vw, 50vw" alt="Srcset and sizes!">

Lazuli also supports background images using the exact same syntax, so this will just work:

<div class="lazuli" data-src="image.jpg">
	This div will lazyload image.jpg as a background image.
</div>

Lazuli tries to stay out of the way of your styles, meaning you'll need to set things like background-size like you would normally.

In your Javascript

Kicking off Lazuli is as simple as:

const lazy = new Lazuli();

By default it looks for the class lazuli but you can also pass in a selector as a string:

const lazy = new Lazuli('.lazy, .lazy-bg');

You can also pass in an options object for more control over what happens:

const lazy = new Lazuli({
	selector: '.lazy, .lazy-bg',
	background: false
});

Lazuli returns a promise that resolves once every image is loaded. You can use this to kick off other things once images are loaded or sequentially load groups of images:

new Lazuli('.primary-images').then((res) => {
	return new Lazuli('.secondary-images');
}).then((res) => {
	return new Lazuli('.tertiary-images');
}).catch((err) => {
	console.log('Whoops, something didn't load!', err);
});

Available options

{
	selector: '.lazuli',
	background: true,
	img: true,
	fancy: false,
	load: null
}

selector

Expects a string formatted as a css selector. Uses querySelectorAll internally, so it should be able to deal with pretty much everything.

background, img

Expects a boolean. Setting background to false means it will only look for tags, and setting img to false means it only looks for non- tags. Setting both to false is just silly. ;)

fancy

Background images currently support a fancy fade in animation (think medium.com headers). This is still a little experimental—it currently works pretty well but sometimes will break things since it injects it's own <div> inside the element you attach it to. Highly recommend giving it a shot though! Adding more configuration for this is in the roadmap.

load

Callback that runs each time an image is loaded. Returns an object with data:

{
	image: <Element>
}

finished

Callback that runs when all images have loaded. Returns an object with data:

{
	images: [<Element>, <Element>]
}

Contributing

Submit a PR!