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

prejs

v1.2.6

Published

A lightweight preloading javascript library for images, video and audio without any dependencies.

Downloads

5

Readme

Introduction

PreJS is a lightweight preloading javascript library for images, video and audio without any dependencies.

Installation

Using npm

$ npm install prejs --save

Using Yarn

$ yarn add prejs

Usage

import PreJS from 'prejs'

let $progress = document.querySelector('.progress')

let pre = new PreJS()
let images = [
  'http://i.imgur.com/Wo0Kyth.jpg',
  'http://i.imgur.com/5pKVfC1.jpg',
  'http://i.imgur.com/1yK4wnx.gif',
  'http://i.imgur.com/GsBSYth.mp4',
  'http://i.imgur.com/YUxVkvN.png',
  'http://i.imgur.com/68Tnk5j.jpg',
]

pre.on('start', () => {
  console.log('Starting')
})

pre.on('progress', progress => {
  $progress.style.width = progress * 100 + '%'
})

pre.load(images)

Events

'start'

Fired when the loader attempts to load the first item.

'loaded'

Fired when an individual item is finished loading in, use this if you want a progressive indiciation of items loading. Returns: item

'error'

Fired when an individual item is fails to load, you can use this to handle image fallbacks. Returns: item

'progress'

Fired when the overall loader progress increases (due to an item loading/partially loading). Returns: progress (number between 0 - 1)

'complete'

Fired when all items have either loaded or errored out. Returns array of items


Item

| key | value | description | | --- | --- | --- | | url | string | The original url given to the loader | | progress | number | A value between 0 - 1 showing the percentage loaded | | asset | HTMLElement | Returns a html element (img, audio, video, etc..), this can be modified and appended to the page |

API

load(urls, loader)

Accepts an array of urls and a loader type to handle them.

Built in loaders are:

'image'

Loads .jpg, .png, .svg, .jpeg and anything else Image() accepts. Uses the Image() element to load in files.

'audio'

Loads .mp3, .ogg, .wave and anything else Audio() accepts. Uses the Audio() element to load in files.

'video'

Loads .mp4, .ogv, .webm files. Uses XMLHttpRequest to grab the full video, this unfortunately means that its IE10+ and restricted to same origin unless the host has the correct Cross-Origin headers set.

If a loader is not defined explicitly, PreJS will attempt to figure out which loader to use based on the file extension.

// loader can be a string:
pre.load([url1, url2, url3], 'image')

// loader can be undefined and PreJS will guess:
pre.load([url1, url2, url3])

// or your own function:
pre.load([url1, url2, url3], (item) => {
	console.log(item)
	customLoadingFunction(() => {
		pre.loaded(item)
	})
})

on(event, cb)

Add an event listener to different events.

pre.on('loaded', (item) => {
	console.log('loaded:', item)
})

dispatch(event)

Dispatch all event listeners for an event.

pre.dispatch('loaded', item)