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

champoo

v0.3.3

Published

Lazy loading pretty much everything!

Downloads

16

Readme

Champoo

npm

Champoo is a lazy loader library. By separating conditioners & loaders, it gives you the flexibility to easily load pretty much everything, the lazy way... It is extensible & has a small footprint.

Installation

Node

yarn add champoo

or

npm install champoo

Browser

The package is available as a UMD module: compatible with AMD, CommonJS and exposing a global variable Champoo in lib/Champoo.js (less than 1Kb minified and gzipped).

Usage

<link rel="stylesheet" data-lazy data-lazy-conditioner="timeout(1000)" data-lazy-loader="url(https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css, href)" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<img data-lazy data-lazy-conditioner="timeout(2000)" data-lazy-loader="url(https://www.google.com/logos/doodles/2017/mountain-day-2017-5742983679836160-2x.jpg)" />

<img data-lazy data-lazy-conditioner="viewport(100)" data-lazy-loader="url(https://www.google.com/logos/doodles/2017/sir-john-cornforths-100th-birthday-4995374627422208.2-2x.jpg)" />

<iframe data-lazy data-lazy-conditioner="pointer(40,20)" data-lazy-loader="url(https://www.google.com/logos/2011/henson11-hp.html)" scrolling="no" width="900px" height="304px" frameborder="0"></iframe>

<div id="fb-root" data-lazy data-lazy-conditioner="viewport(100)" data-lazy-loader="fb-comments(en_US)" />
<div class="fb-comments" data-href="https://developers.facebook.com/docs/plugins/comments#configurator" data-numposts="1" />
import Champoo from '../es/Champoo';
import { UrlLoader } from '../es/loaders';
import { TimeoutConditioner, ViewportConditioner, MousePointerConditioner } from '../es/conditioners';

import FaceBookCommentsLoader from './FaceBookCommentsLoader';

const champoo = new Champoo({
  conditioners: {
    timeout: new TimeoutConditioner(),
    viewport: new ViewportConditioner(),
    pointer: new MousePointerConditioner()
  },
  loaders: {
    'url': new UrlLoader(),
    'fb-comments': new FaceBookCommentsLoader()
  }
});

champoo.init().then((r) => {
  console.log('All lazy elements loaded.', r);
});

Demo

git clone https://github.com/mawrkus/champoo.git
cd champoo
npm install
npm run server:demo

Custom conditioners creation

A conditioner is a simple class having the following interface:

class AmazingConditioner {

  /**
   * @param  {HtmlElement} element
   * @param  {Array} params The conditioner parameters declared on the HTML element
   * @return {Promise}
   */
  check({ element, params }) {
    return new Promise((resolve, reject) => {
      // call resolve() whenever the element meets the condition(s)
      // call reject() if there's a problem
    });
  }

}

By registering it when instantiating Champoo...

const champoo = new Champoo({
  conditioners: {
    amazing: new AmazingConditioner()
  },
  loaders: {
    // ...
  }
});

...you can use it in the HTML:

<img data-lazy data-lazy-conditioner="amazing(1,2,3)" />

Custom loaders creation

A loader is a simple class having the following interface:

class AmazingLoader {

  /**
   * @param  {HtmlElement} element
   * @param  {Array} params The loader parameters declared on the HTML element
   * @return {Promise}
   */
  load({ element, params }) {
    return new Promise((resolve, reject) => {
      // call resolve() when the element has been loaded
      // call reject() if there's an error while loading
    });
  }

}

By registering it when instantiating Champoo...

const champoo = new Champoo({
  conditioners: {
    // ...
  },
  loaders: {
    amazing: new AmazingLoader()
  }
});

...you can use it in the HTML:

<img data-lazy data-lazy-loader="amazing(you,and,me)" />

Contribute

  1. Fork it: git clone https://github.com/mawrkus/champoo.git
  2. Create your feature branch: git checkout -b feature/my-new-feature
  3. Commit your changes: git commit -am 'Added some feature'
  4. Check the build: yarn run build
  5. Push to the branch: git push origin feature/my-new-feature
  6. Submit a pull request :D