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

@genips/raf

v1.1.6

Published

Timers with requestAnimationFrame

Downloads

3

Readme

@genips/raf

fileSize Coverage build type definitions code style: prettier

Installation:

npm install @genips/raf

or

yarn add @genips/raf

Specific version

npm install @genips/[email protected]

or

yarn add @genips/[email protected]

See tags for version numbers

Importing:

Add the following line to your script

import Raf from "@genips/raf";

Or add the folder to your webpack.config:

resolve: {
    modulesDirectories: ["node_modules/@sycoraxya"];
}

// And add the following line to your scripts
import Raf from "genips-raf";

Usage

genips-raf has 3 timers: Now, Timeout and Interval.

Now

Use Now to perform an action in the next animationframe.

import Raf from "@genips/raf";

Raf.now((rafInstance, elapsed) => {
    // Do stuff
});

Timeout

Use Timeout to perform an action after given MS.

The second argument can be a number or a Settings object.

import Raf from "@genips/raf";

Raf.timeout((rafInstance, elapsed) => {
    // Do stuff
}, 200);

Interval

Use Interval to perform an action after given MS and repeat it.

The second argument can be a number or a Settings object.

import Raf from "@genips/raf";

Raf.interval((rafInstance, elapsed) => {
    // Do stuff
}, 200);

Using a Settings object

If you want to specify a tickFn, use a Settings object instead of a number as the second argument

The tickFn includes the final tick

Raf.interval(
    (rafInstance, elapsed) => {
        // Do stuff after 200ms
    },
    {
        time: 200,
        tickFn: (rafInstance, elapsed) => {
            // Do stuff every tick
        },
    },
);

Types

Exported types

  • RafTimeout
  • RafInterval
  • RafNow

You can import these types like this:

import Raf, { RafInterval } from "@genips/raf";

let interval: RafInterval;

Callback

All callbacks are called with the following arguments:

| Argument | Description | | ----------- | ------------------------------------------------------------------------------- | | rafInstance | The instance of the raf timer that's created (RafNow, RafInterval, RafTimeout) | | elapsed | (number) The amount of time in ms that has elapsed since the method started |

Settings

A Settings object can be passed as the second argument instead of a number.

Settings can contain the following properties:

| Property | Required | Description | | -------- | -------- | ---------------------------------------------------------------------------- | | time | Yes | (number) the time in MS | | tickFn | No | (Callback) A function that gets called every animationframe |

RafNow & RafTimeout

methods

| Method | Description | | ------- | ------------------------------------------------------------------ | | pause | Pauses the timer | | resume | Resumes the timer | | stop | Stops the timer | | restart | Restarts the timer with the settings that were defined at creation |

properties

| Property | Type | Description | | -------- | ------- | ------------------------------------------------------------------ | | paused | boolean | Is the instance paused | | done | boolean | Is the instance done | | progress | number | The progress of the current iteration as a percentage | | elapsed | number | How much time has elapsed since the start of the current iteration |

RafInterval

RafInterval inherits all methods and properties from RafNow and adds the following:

properties

| Property | Description | | --------- | ------------------------------------------------------- | | iteration | (number) The iteration of the interval. Starts at 1 |