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

ivent

v0.2.0

Published

Helper functions for browser event listener

Downloads

8

Readme

ivent

ivent.min.js

Helper functions for browser event listener

Table of Contents

Import ivent

Use one of the following examples to import script.

ESM

We provide a version of ivent built as ESM (ivent.esm.js and ivent.esm.min.js) which allows you to use ivent as a module in your browser, if your targeted browsers support it.

<script type="module">
  import { on, off } from "ivent.esm.min.js";
</script>

ESM CDN

<script type="module">
  import { on, off } from "https://cdn.jsdelivr.net/npm/[email protected]/+esm";
</script>

UMD

ivent may be also used in a traditional way by including script in HTML and using library by accessing window.ivent.

<script src="ivent.min.js"></script>

UMD CDN

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/ivent.min.js"></script>

CJS (Bundlers like Webpack)

Install ivent as a Node.js module using npm

npm install ivent

Import ivent by adding this line to your app's entry point (usually index.js or app.js):

import { on, off } from 'ivent';

Methods

on

one

DOM event listener:

import { on } from 'ivent';

on(document, 'click', (e) => {
  console.log('clicked', e);
});

Event listener with delegated target:

import { on } from 'ivent';

on(document, 'click', '.custom-element-selector', (e) => {
  console.log('clicked', e);
});

Custom event listener with namespace:

import { on } from 'ivent';

on(document, 'the-custom-event.with-namespace', (e) => {
  console.log('clicked', e);
});

off

Remove DOM event listener:

import { on } from 'ivent';

on(document, 'click', (e) => {
  console.log('clicked', e);
});

off(document, 'click');

Remove DOM event listener by namespace:

import { on } from 'ivent';

on(document, 'click.my-namespace', (e) => {
  console.log('clicked', e);
});

off(document, '.my-namespace');

trigger

Trigger event:

import { trigger } from 'ivent';

trigger(document, 'click');

Custom Events

ready

Create ready event which work in the same way as DOMContentLoaded with additional check for dom loaded. For example, if dom is already loaded, the ready event callback will be fired immediately.

Example:

import { on } from 'ivent';

on(document, 'ready', (e) => {
  console.log('dom ready', e);
});

mouseenter

mouseleave

pointerenter

pointerleave

Create mouseenter / mouseleave events using mouseover / mouseout so that event delegation works properly. Do the same for pointerenter / pointerleave and pointerover / pointerout.

Example:

import { on } from 'ivent';

on(document, 'mouseenter', 'button', (e) => {
  console.log('button mouseenter event created using mouseover', e);
});

For Developers

Installation

  • Run npm install in the command line. Or if you need to update some dependencies, run npm update

Building

  • npm run build to run build

Linting

  • npm run js-lint to show eslint errors
  • npm run js-lint-fix to automatically fix some of the eslint errors