Installations
npm install super-progress
Releases
Unable to fetch releases
Developer
s73obrien
Developer Guide
Module System
CommonJS
Min. Node Version
>=8.0.0
Typescript Support
Yes
Node Version
8.9.4
NPM Version
5.6.0
Statistics
3 Stars
41 Commits
2 Watching
1 Branches
1 Contributors
Updated on 04 Mar 2023
Languages
TypeScript (98.62%)
JavaScript (1.38%)
Total Downloads
Cumulative downloads
Total Downloads
8,729
Last day
0%
52
Compared to previous day
Last week
-19.5%
157
Compared to previous week
Last month
-25.8%
588
Compared to previous month
Last year
2,884.3%
6,476
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Super Progress Bar
Super progress bar is a CLI progress bar.
Installation
npm i -S super-progress
Usage
API
Typescript
1import { Progress } from 'super-progress'; 2import { clearInterval } from 'timers'; 3import { EOL } from 'os'; 4 5const pb = Progress.create(process.stdout.columns - 1); 6 7let t = setInterval(() => { 8 pb.tick() 9 .then(() => { 10 if (pb.state.percentComplete >= 1.0) { 11 clearInterval(t); 12 process.stdout.write(EOL); 13 } 14 }) 15}, 100);
Javascript
1const Progress = require('super-progress').Progress; 2// or 3const { Progress } = require('super-progress'); 4 5/* Same as above */
NEW! Stream support
Super Progress Bar now includes support for streams. An instance will also act as a Transform stream operating in object mode. It emits arrays of strings (the same as the output from the render function).
1import { Progress, ConsoleAdapter } from 'super-progress'; 2 3const StreamTest = require('streamtest'); 4 5StreamTest['v2'].fromObjects(' '.repeat(100).split(''), 100) 6.pipe(Progress.create(process.stdout.columns! - 1)) 7.pipe(new ConsoleAdapter(1000)) 8.pipe(process.stdout);
Configuration
Pattern String
Super Progress Bar accepts a pattern string that contains tokens that represent the different fields that can be output in the progress bar.
1// Default pattern string 2let pb = Progress.create( 3 width, 4 { 5 pattern: `[{spinner}] {bar} | Elapsed: {elapsed} | {percent}` 6 } 7);
It also accepts a set of custom token definitions that define the various tokens in the pattern string as well as how to render each token.
1// Example token definition 2{ 3 percent: { 4 render: (state: ProgressState, allowed: number): string => { 5 return (state.percentComplete * 100).toFixed(2) + '%'; 6 }, 7 width: () => 7 8 } 9}
Token Definition
Each token is specified within the pattern string by its key, surrounded by curly braces (ex. {bar}
). If a custom token has the same key as a default token, the default token is replaced.
Each token definition is composed of three parts:
- It's key, which you insert into the pattern string to indicate where to put the rendered token
- A function that returns a number indicating the width of the rendered token, in single characters. Each token may instead return a -1 to to indicate that it will take as much space as is available (more on that below)
- A function that returns the rendered token
Multiple instances of the same token are allowed in the pattern string.
Rendering
The progress bar rendering function uses a two-pass process to render the whole bar.
On the first pass, each token is queried for its rendered width. If a token returns a -1 instead of a width, this indicates that the token is variable-width and will use the space allotted to it by the render function.
On the second pass, all of the widths of the known-width tokens and 'literal' characters (characters that are not a part of any known token) in the pattern string are added together and subtracted from the space available in the console. The amount left over (if any) is then divided evenly across all of the tokens that returned a -1 on the first pass. Every token's render function is then called with the current state of the progress bar and the allowed width per unknown-width token as arguments. The return value of each render function is then inserted in place of the token's placeholder(s) in the pattern string.
API
ProgressOptions
This can be passed to Progress.create() to customize the layout, token definitions, and capacity of the progress bar
1interface ProgressOptions { 2 total?: number; 3 pattern?: string; 4 renderInterval?: number; 5}
total
The capacity of the progress bar
pattern
The pattern string specifying where the tokens are to be inserted. Each token can be used as many times as needed.
For example:
'{spinner}--{spinner} {indeterminate} {bar} {indeterminate} {spinner}--{spinner}'
yields
renderInterval
The minimum amount of time (in ms) to wait between frames. This only applies if you use the display method provided in the Progress class.
ProgressState
This contains the current state of the progress bar. It can be saved and reused to restore the progress bar's state at a later time (for example, if the current process has to be interrupted).
1interface ProgressState { 2 startTime: number; 3 elapsedTime: number; 4 remainingTime: number; 5 nextRender: number; 6 7 percentComplete: number; 8 rateTicks: number; 9 currentTicks: number; 10 totalTicks: number; 11 ticksLeft: number; 12}
startTime
The time at which the progress bar was created, in the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
elapsedTime
The amount of time (in ms) that has passed since the progress bar was created.
remainingTime
The estimated amount of time (in ms) remaining in the process.
nextRender
The time at which the next render should take place. This only applies if you use the display method provided in the Progress class.
percentComplete
The amount of the process that has completed, as a percentage.
rateTicks
The rate of tick completion, calculated as ticks per millisecond.
currentTicks
The current number of ticks that have been completed.
totalTicks
The total number of ticks in the whole process (as provided to the Progress class constructor).
ticksLeft
The total number of ticks that remain in the process.
ProgressTokenDefinitions
Contains the definitions of the tokens in the progress bar.
1interface ProgressTokenDefinitions { 2 'key': { 3 render: (state: ProgressState, allowed: number) => string; 4 width: (state: ProgressState) => number; 5 } 6 . . . 7}
key
The string that, when surrounded by curly braces {}
and inserted into the pattern string, acts as the placeholder for the rendered content of the token.
render(state: ProgressState, allowed: number): string
The function that renders the token output. The current state and the space allowance are given as inputs.
width(state: ProgressState): number
This function indicates how much space the token will take up (in characters) when rendered. A return of -1 indicates that the token will take up as much space as is available to it.
Progress
Main class that represents the progress bar
1export class Progress { 2 public static create(width: number, options?: ProgressOptions, tokens?: ProgressTokenDefinitions, state?: ProgressState): Progress 3 public async display(rendered: string[], stream: Writable): Promise<void> 4 public async update(ticks: number = 1): Promise<void> 5 public async complete(): Promise<void> 6 public async render(): Promise<string[]> 7}
create(width: number, options?: ProgressOptions, tokens?: ProgressTokenDefinitions, state?: ProgressState): Progress
Creates a new Progress object using the specified parameters. The line width must be specified.
Default parameters:
1options = { 2 total: 100, 3 pattern: `[{spinner}] {bar} | Elapsed: {elapsed} | {percent}`, 4 renderInterval: 33 5} 6 7tokens = { 8 // the bar token displays a bar showing how much of a process has 9 // completed. It takes up as much space as the layout engine will 10 // allow. This is specified by returning -1 in the width function. 11 bar: {/*...*/}, 12 13 // the elapsed token displays the amount time that has elapsed since 14 // the beginning of the process. It is displayed in hh:mm:ss.sss format. 15 // Since we know the exact width of the desired output, we return it 16 // in the width function. 17 elapsed: {/*...*/}, 18 19 // the percent token displays the amount of the process that has been 20 // completed as a percentage. It shows 2 decimal places of precision. 21 percent: {/*...*/}, 22 23 // The spinner token simply displays an ascii 'wheel' that constantly 24 // spins as the process is occurring. 25 spinner: {/*...*/} 26} 27 28state = { 29 elapsedTime: 0, 30 remainingTime: 0, 31 percentComplete: 0, 32 currentTicks: 0, 33 rateTicks: 0, 34 nextRender: 0, 35 startTime: Date.now(), 36 totalTicks: 100, // or the value supplied in options, if supplied 37 ticksLeft: 100, // or the value supplied in options, if supplied 38}
tick(ticks: number = 1, stream: Writable = process.stdout): Promise
This helper function updates, renders and outputs the progress bar on the given stream.
display(rendered: string[], stream: Writable): Promise
Displays the strings in rendered on the provided stream. Each entry in the array represents a line. This function joins the array with os.EOL, writes it to the stream and repositions the cursor to the beginning of the line on which it started.
update(ticks?: number = 1): Promise
Updates the state of the progress bar by the specified number of ticks.
complete(): Promise
Call this when the process is complete; it works like update.
render(): Promise<string[]>
Renders the progress bar in its current state. The width specified on progress bar creation controls how wide each output string is when rendered.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/26 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 6 are checked with a SAST tool
Reason
68 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-v88g-cgmw-v5xw
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-fwr7-v2mv-hh25
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-cwfw-4gq5-mrqx
- Warn: Project is vulnerable to: GHSA-g95f-p29q-9xw4
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-rq8g-5pc5-wrhr
- Warn: Project is vulnerable to: GHSA-9vvw-cc9w-f27h
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-hr2v-3952-633q
- Warn: Project is vulnerable to: GHSA-h6ch-v84p-w6p9
- Warn: Project is vulnerable to: GHSA-qrmc-fj45-qfc2
- Warn: Project is vulnerable to: GHSA-8r6j-v8pm-fqw3
- Warn: Project is vulnerable to: MAL-2023-462
- Warn: Project is vulnerable to: GHSA-xf7w-r453-m56c
- Warn: Project is vulnerable to: GHSA-q42p-pg8m-cqh6
- Warn: Project is vulnerable to: GHSA-w457-6q6x-cgp9
- Warn: Project is vulnerable to: GHSA-62gr-4qp9-h98f
- Warn: Project is vulnerable to: GHSA-f52g-6jhx-586p
- Warn: Project is vulnerable to: GHSA-2cf5-4w76-r9qv
- Warn: Project is vulnerable to: GHSA-3cqr-58rm-57f8
- Warn: Project is vulnerable to: GHSA-g9r4-xpmj-mj65
- Warn: Project is vulnerable to: GHSA-q2c6-c6pm-g3gh
- Warn: Project is vulnerable to: GHSA-765h-qjxv-5f44
- Warn: Project is vulnerable to: GHSA-f2jv-r9rf-7988
- Warn: Project is vulnerable to: GHSA-44pw-h2cw-w3vq
- Warn: Project is vulnerable to: GHSA-jp4x-w63m-7wgm
- Warn: Project is vulnerable to: GHSA-c429-5p7v-vgjp
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-qqgx-2p2h-9c37
- Warn: Project is vulnerable to: GHSA-2pr6-76vf-7546
- Warn: Project is vulnerable to: GHSA-8j8c-7jfh-h6hx
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-fvqr-27wr-82fm
- Warn: Project is vulnerable to: GHSA-4xc9-xhrj-v574
- Warn: Project is vulnerable to: GHSA-x5rq-j2xg-h7qm
- Warn: Project is vulnerable to: GHSA-jf85-cpcp-j695
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-4xcv-9jjx-gfj3
- Warn: Project is vulnerable to: GHSA-f9cm-qmx5-m98h
- Warn: Project is vulnerable to: GHSA-7wpw-2hjm-89gp
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-vh95-rmgr-6w4m / GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-6394-6h9h-cfjg
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-6g33-f262-xjp4
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-g4rg-993r-mgx7
- Warn: Project is vulnerable to: GHSA-2m39-62fm-q8r3
- Warn: Project is vulnerable to: GHSA-mf6x-7mm4-x2g7
- Warn: Project is vulnerable to: GHSA-j44m-qm6p-hp7m
- Warn: Project is vulnerable to: GHSA-3jfq-g458-7qm9
- Warn: Project is vulnerable to: GHSA-5955-9wpr-37jh
- Warn: Project is vulnerable to: GHSA-f5x3-32g6-xq36
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-g7q5-pjjr-gqvp
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
- Warn: Project is vulnerable to: GHSA-p9pc-299p-vxgp
Score
1.7
/10
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to super-progress
@babel/plugin-transform-object-super
Compile ES2015 object super to ES5
toastify-react-native
🎉 toastify-react-native allows you to add notifications to your react-native app (ios, android) with ease. No more nonsense!
request-progress
Tracks the download progress of a request made with mikeal/request, giving insight of various metrics including progress percent, download speed and time remaining
cli-progress
easy to use progress-bar for command-line/terminal applications