browser-event-utils
TypeScript icon, indicating that this package has built-in type declarations

2.2.0 • Public • Published

browser-event-utils

🎟 A collection of higher-order functions for invoking common browser event methods.


Motivation

How often do you call stuff like event.preventDefault or event.stopPropagation when handling events in client-side JavaScript? I bet it's pretty often.

This (~1kb) package aims to provide you with a set of higher-order functions which handle these things for you.

Could you survive without this library? Absolutely. But I've found that in larger codebases, it can become cumbersome to always sprinkle e.stopImmediatePropagation() calls all over the place. It adds complexity to your event handlers, which violates the Do One Thing (DOT) principal, plus it (in theory) it makes your unit tests more complicated (if you care about asserting that event methods are called).

Installation

This package is available on NPM, and you can install it with npm or yarn:

npm install browser-event-utils

yarn add browser-event-utils

Add the -S flag if you want to save it to the "dependencies" section of your package.json.

Browser/UMD

If you want to just import this library directly in the browser, you can add the following script tag:

<script src="https://unpkg.com/browser-event-utils/bin/index.umd.js" />

This will expose a browserEventUtils global, on which you will find all of the utility methods.

Documentation

Please view the documentation for guides to explore what methods this package exposes and how to use them.

Contributing

Feel free to file an issue or open a pull request.


👌 Built by Dave Lunny in the wonderful year 2019.

/browser-event-utils/

    Package Sidebar

    Install

    npm i browser-event-utils

    Weekly Downloads

    4

    Version

    2.2.0

    License

    MIT

    Unpacked Size

    26.9 kB

    Total Files

    16

    Last publish

    Collaborators

    • himynameisdave