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

swipey.js

v1.0.3

Published

A simple and lightweight JS library to add swipe gestures to your app

Downloads

21

Readme

Swipey.js

NPM JavaScript Style Guide

A simple and super lightweight (1.29kb) JS library to add swipe gestures to your app.

Installation

Vanilla JS

Download the latest release and include the script in your HTML

<script src="./swipey.js"></script>

React

Install the module into your project

$ npm install swipey.js

Import the module

import swipey from 'swipey.js';

Basic Usage

Vanilla JS

Select the element you wish to be able to swipe on and pass it into swipey.add with a callback function to be fired off when a valid swipe occurs.

let element = document.querySelector(".yourElement");

swipey.add(element, myCallback);

function myCallback(ev){
    //Do some stuff
    console.log(ev);
}

React

Swipey in React works the exact same as Vanilla JS. If you are using functional components then the useRef hook is recommended to select the element you wish to swipe on.

function App() {

    const element = useRef(null);

    swipey.add(element.current, myCallback);

    function myCallback(ev) {
        console.log(ev);
    }

  return (
    <div ref={element} className="App">
        <p>some stuff</p>
    </div>
  );
}

Customization

swipey.add also accepts an optional object for better customization.

The default options are as follows:

{
    vertical: true,
    horizontal: true,
    diagonal: true,
    swipeDistance: 100
}

You may override these defaults by passing your custom options into swipey.add as a 3rd parameter.

In this case the minimum swipe distance will be 25 pixels and will only allow horizontal swipes.

swipey.add(element, myCallback, {
    swipeDistance: 25,
    vertical: false,
    diagonal: false
})

Returned Data

The callback passed into swipey.add will be fired with an event object passed in. The object will contain the following information:

  • swipeLength: The length of the swipe in pixels
  • direction: A string value with the direction of the swipe; up, down, left, right, up-right, up-left, down-right or down-left
  • target: A DOM reference to the element that was swiped on. This is useful for cases where you have multiple swipeable objects and need to know which object was swiped on

An example of what the returned object will look like

{
    swipeLength: 177.55073067405448,
    direction: "down-left",
    target: div.App
}