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

new-functs

v1.1.2

Published

A library that introduces a bunch of new functions.

Downloads

929

Readme

New-Functs

A library that introduces a bunch of new functions.

Documentation:

nf

  • The function that holds all the other functions in its object that's returned from calling the function.

nf.pushMaterial(arrayToPushInto, whatToPush, starting, ending, addition)

EXAMPLE 1:

let array = [];
nf.pushMaterial(array, nf.pM_i, 0, 10, 1);

//(By the way, nf.pM_i is an optional variable that is used whenever you're using nf.pushMaterial and it just means the iteration count of the for loop. This is how you can create repeating numbers, like shown in the output below. The addition parameter will change how much nf.pM_i changes for each loop. So, if the addition parameter is 2, it would output "0, 2, 4, 6, 8, 10, 12, 14, 16, 18")

console.log(array); //Outputs "0, 1, 2, 3, 4, 5, 6, 7, 8, 9"

EXAMPLE 2:

let array = [];
let a = 0;
nf.pushMaterial(array, a, 0, 10, 1);
console.log(array); //Outputs "0, 0, 0, 0, 0, 0, 0, 0, 0, 0"

nf.timer Variable:

IMPORTANT: You will have to put the function nf.timer.update(); in the draw function for the timer variable to work.

There is a variable inside the object that is returned from nf called timer. This holds the Timer constructor.

There are functions followed with it, such as:

  • nf.timer.timeout(callback, delay, repetitions);

    • This will execute the callback function in the callback parameter after the amount of milliseconds that are passed in the delay parameter have passed. The repetition parameter will decide how many times it will repeat this.

    EXAMPLE 1:

    function draw() {
        nf.timer.update();
    };
    nf.timer.timeout(function() {
        console.log("Hello, World!");
    }, 1000, 3);
    //Outputs "Hello, World!" 3 times, each after 1000 milliseconds (1 second)
  • nf.timer.interval(callback, delay); & nf.timer.removeInterval(id);

    • nf.timer.interval will execute the callback function in the callback parameter after the amount of milliseconds that are passed in the delay parameter have passed repeatedly.

    • Once you call nf.timer.removeInterval(); with the id (variable) of the interval, then you will remove the interval and stop it completely. (See example below)

    EXAMPLE 1:

      // Create a function to be called repeatedly
      let printMessage = function() {
      console.log("Hello, World!");
      };
    
      // Start an interval that calls printMessage every second (1000 milliseconds)
      let myIntervalID = nf.timer.interval(printMessage, 1000);
    
      function draw() {
          nf.timer.update();
    
          // Let's say we want to clear the interval after 5 seconds (5000 milliseconds)
          // We'll use the "nf.timer.timeout();" function for this
          nf.timer.timeout(function() {
              console.log("Interval cleared!");
              nf.timer.removeInterval(myIntervalID);
          }, 5000);
      };
  • nf.timer.pause(id, type); & nf.timer.resume(id, type);

    • This will pause/resume an interval or a timeout. If you use nf.timer.pause(); and give the type parameter the value of "interval" then it will pause the interval that has the id of the id you give in the id parameter. Same thing if you set the type parameter to "timeout". Makes more sense if you see the examples.

    EXAMPLE 1 WITH INTERVAL:

    // initialize the counter
    let counter = 0;
    
    // this function increments the counter and prints it
    let count = function() {
        counter++;
        console.log("Counter: " + counter);
    };
    
    // setting up an interval that will call count function every second
    let intervalID = nf.timer.interval(count, 1000);
    
    // setting up a timeout that will pause the interval after 5 seconds
    nf.timer.timeout(function() {
        console.log("Pausing interval...");
        nf.timer.pause(intervalID, 'interval');
    }, 5000, 1);
    
    // setting up a timeout that will resume the interval after 5 more seconds
    nf.timer.timeout(function() {
        console.log("Resuming interval...");
        nf.timer.resume(intervalID, 'interval');
    }, 10000, 1);
    
    function draw() {
        nf.timer.update();
    };

    EXAMPLE 2 WITH TIMEOUT:

    // initialize the counter
    let counter = 0;
    
    // this function increments the counter and prints it
    let incrementCounter = function() {
        counter++;
        console.log("Counter: " + counter);
    };
    
    // setting up a timeout that will call incrementCounter function after 1 seconds
    let timeoutID = nf.timer.timeout(incrementCounter, 1000, 2);
    
    // setting up a timeout that will pause the previous timeout 1.5 seconds after the program starts
    nf.timer.timeout(function() {
        console.log("Pausing timeout...");
        nf.timer.pause(timeoutID, 'timeout');
    }, 1500, 1);
    
    // setting up a timeout that will resume the paused timeout after 2 more seconds
    nf.timer.timeout(function() {
        console.log("Resuming timeout...");
        nf.timer.resume(timeoutID, 'timeout');
    }, 3500, 1);
    
    function draw() {
        nf.timer.update();
    };