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

@zcomp/loader

v0.0.4

Published

A helper library for loading data from remote source to a DOM element.

Downloads

1

Readme

What is it?

A helper library for loading data from remote source to a DOM element.

Installing

npm i --save @zcomp/loader

Usage

const loader = require('@zcomp/loader');
loader.LoaderFactory.init();
<div class="js-load" data-load="http://example.com/partial.html">
  <div class="js-load__content"></div>
  <div class="js-load__error"></div>
</div>

Here a HTML file located at given url will be loaded into js-load__content element. js-load__content element is optional. If there are no js-load__content child of js-load element, the loaded content will replace entire contents of js-load. If error is occupied during loading content, js-load__error will contain error message.

The content is not loaded automatically or on any event. You should manually call loader.load method when you need to load content.

data-load-plaintext

If root element has this attribute, loaded content will be treated as plain text (e.g., textContent will be used to set element value). You can set plainText property on options object to make all components to be plaintext by default.

Custom loader

Use loader property to set custom content loader:

LoaderFactory.init({
  loader: (url, done, component) => {
    // load data...
    if (err) {
      // on error
      done(err, null);
    } else {
      done(null, "loaded content");
    }
  }
});

Custom apply method

Use applier property to intercept process of applying content to element:

LoaderFactory.init({
  applier: (component, content, done) => {
    if (component.plainText) {
      component.contentElement.textContent = content;
    } else {
      component.contentElement.innerHTML = content;
    }
  }
})

Instant load timeout

To make interface look smooth, you can set instantLoadTimeout option. It can be useful when you want to display some loading animation, but not when network is fast and you can load assets in a blink of an eye. If you set this option, loading state will only be set if loading take longer than specified time.