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

@stefftek/tick.js

v1.1.1

Published

Tick System for performing tasks X times a second.

Downloads

31

Readme

Discord License GitHub code size in bytes GitHub issues Build

Tick.js

Execute tasks multiple times a second based on a tick count. Tick.js helps to maintain a clean code without the need of thousands of setIntervals and it's easy to use!

About

Tick.js was created during a webex call in which we learned to use git like I didn't already knew, so because I got bored and I needed a tick based system for one of my projects, Tick.js was born.

New in 1.1.0

You can now execute functions after x amount of ticks.

Installation

NodeJS Installation

npm i @stefftek/tick.js

or - script tag for the browser

<script src="https://unpkg.com/@stefftek/tick.js@latest/TickSystem.js" type="text/javascript"></script>

Usage

Import

with Common JS

/* Import Tick.js */
const TickSystem = require("@stefftek/tick.js");

or - TypeScript Import

/* Import Tick.js */
import TickSystem from "@stefftek/tick.js";

Using the Class

/* Create New Tick System */
/* Starts Tick System aswell */
/* Default Tickrate: 64 */
const tickSystem = new TickSystem();

/* To use other Tickrate */
const tickSystem = new TickSystem(32);

/* Add new Callback */
tickSystem.onTick(debug);

/* Remove Callback */
tickSystem.offTick(debug);

/* Debug Function */
function debug() {
  console.log(tickSystem.currentTick);
}

/* Stop Ticking */
tickSystem.stop();

/* Start Ticking */
/* Only needed if stopped */
tickSystem.start();

Executing functions after x amount of ticks (added in 1.1.0):

/* Wait 100 ticks till execution */
tickSystem.executeAfter(100, () => {
  console.log("I ran after 100 ticks!");
});

/* Wait 3 seconds till execution */
tickSystem.executeAfterSeconds(3, () => {
  console.log("I ran after 3 seconds!");
});

What is a tick rate?

Tick Rate defines how many times a second, the onTick function will execute. A much more simple explaination: Tick Rate is kinda like FPS in Games. More FPS means smoother animations or physics interpolation, but the cost is a higher usage of system resources.

Variables

tickSystem.callbacks : Array  // All Callbacks that are registered

tickSystem.tickRate : Number    // Tick rate specified on creation
tickSystem.currentTick : Number // The current tick from 0 to (tickRate - 1)
tickSystem.tickLatency : Number // Latency between the ticks in ms
tickSystem.tickDelta : Number   // Latency between the ticks in seconds

tickSystem.lastTick : Number  // Timestamp in ms of the last executed tick
tickSystem.tickTime : Number  // Time in ms per tick

tickSystem.performanceMonitor : PerformanceMonitor // Performance Monitor if enabled

Initial Testing seemed stable and perform well! ❤

Performance Monitoring

⚠️Warning: May impact performance⚠️ Yes... Seriously

To measure the performance of the tick system, you can enable performance monitoring.

tickSystem.monitor(true);

To Disable, use .monitor(false);

Performance Reports can be collected either manual or for

  • the last frame
  • the last second
  • and for the last 5 seconds

combined.

To collect performance reports, either use

tickSystem.performanceMonitor.report()

for a group report, or

tickSystem.performanceMonitor.singleReport(10) // Tick count

for a report of the size you prefer.

Please note: you can only collect Tick Rate * 5 on a single report.