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

@yetnt/progressbar

v3.0.1

Published

An easy, simple and customizable string progress bar

Downloads

20

Readme

progressbar

A progress bar creator in ~~javascript~~ typescript!

NOTE: All examples and explanations are in javascript.

Installation

npm install @yetnt/progressbar
sudo npm install @yetnt/progressbar
yarn add @yetnt/progressbar

(Jump To)

Usage (examples below this)

const { progressBar, ProgressBar } = require('@yetnt/progressbar')

progressBar(percentage, barWidth, emptyChar, fullChar, returnAr?, firstEdgeOverride?, lastEdgeOverride?)

percentage = 45 // How much of the bar is full. If 100% the whole thing is full. If 0 everything is empty.
barWidth = 10 // Width of the bar. If 10 it's 10 characters long
emptyChar = "□" // Empty character to display for parts of the bar that aren't filled.
fullChar = "■" // Full character to display for parts of the bar that  are filled.
returnAr = false // (optional) Return an array or not
firstEdgeOverride = ["◁", "◀"] // (optional) Overrides the first edge with the elements
lastEdgeOverride = ["▷", "▶"] // (optional) Overrides the last edge with elements

// This is exactly the same for class, but returnAr is not a parameter

let bar = new ProgressBar(percentage, barWidth, emptyChar, fullChar, firstEdgeOverride?, lastEdgeOverride?)

or if you don't want to deconstruct them (for some reason)

const pb = require("@yetnt/progressbar");
pb.progressBar();
// or
new pb.ProgressBar();

A Simple bar

Function

progressBar(45, 10, "□", "■");

Class

let bar = new ProgressBar(45, 10, "□", "■");
bar.bar;

Output

"■■■■□□□□□□";

Return Array

Function

progressBar(45, 10, "□", "■", true);

Class

let bar = new ProgressBar(45, 10, "□", "■", true);
bar.barArray;

Output

["■", "■", "■", "■", "□", "□", "□", "□", "□", "□"];

Edge overrides

If you'd like you can also change the first bar element and the last bar element so you can edge it with emojis or something else.

Edge Syntax

["emptyChar", "filledChar"];

Edge Use

Function

progressBar(56, 30, "▢", "▧", false, ["◁", "◀"], ["▷", "▶"]);

Class

let bar = new ProgressBar(56, 30, "▢", "▧", ["◁", "◀"], ["▷", "▶"]);
bar.bar;

Output

"◀▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▢▢▢▢▢▢▢▢▢▢▢▢▢▷";

Discord.js example

Code may need to be modified depending on your command handler, currently setup using ic4d Command Handler/(Under Ctrl's Command Handler)

const { ProgressBar, progressBar } = require("@yetnt/progressbar"); // deconstructing
module.exports = {
    name: "progressbar",
    description: "useful npm package made by yet",
    callback: async (client, interaction) => {
        const progressBar = new ProgressBar(55, 10, "▢", "▧");

        interaction.reply({
            content: progressBar.bar,
            ephemeral: true,
        });
    },
};

Output

Differences

Dynamic Bar

Unlike the function, If you update any one of the properties of the ProgessBar object, the bar updates.

let bar = new ProgressBar(56, 30, "▢", "▧", ["◁", "◀"], ["▷", "▶"]);

bar.bar; // ◀▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▢▢▢▢▢▢▢▢▢▢▢▢▢▷

bar.barWidth = 20;
bar.bar; // ◀▧▧▧▧▧▧▧▧▧▧▢▢▢▢▢▢▢▢▷

bar.percentage = 80;
bar.bar; // ◀▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▢▢▢▷

bar.firstEdgeOverride = [];
bar.lastEdgeOberride = [];
bar.bar; // ▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▢▢▢▢ (Removes Edge Overrides)

Warning : Bar may not work properly if you edit any other properties that aren't meant to be edited. (these tend to be properties with an _)

Seprated Bar (charsplit method)

To seprate a bar with some value (Replace the last filled char), you can use the charSplit() method.

let bar = new ProgressBar(56, 30, "▢", "▧");
bar.bar; // ▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▢▢▢▢▢▢▢▢▢▢▢▢▢▢
bar.charSplit("▶");
bar.bar; // ▧▧▧▧▧▧▧▧▧▧▧▧▧▧▧▶▢▢▢▢▢▢▢▢▢▢▢▢▢▢

The bar will NOT charSplit if :

  1. Last Edge Override is provided

    AND

  2. Bar's percentage is 100%

Links

NPM

Math on a progress bar

Github