progress-str
TypeScript icon, indicating that this package has built-in type declarations

3.4.4 • Public • Published

progress-str

NPM version NPM downloads

GitHub NodeJS Codecov

semantic-release

Visual Studio Code Wallaby.js

Create a string based progress bar.

Usage

import { progressBar } from 'progress-str'

const bar = progressBar()

bar.render(0.5)          // [-----------|-----------] 50%

// Also support multiple values
bar.render(0.25, 0.5, 1) // [---|--|-----|] 25%  50%  100%

// If the value is unknown/not available, pass in undefined:
bar.render(0.5, undefined) // [---------|----------] 0.5 ---

Configure

progressBar({
  bar: {
    completedMarker: '-', // marker for completed section of the bar
    incompleteMarker: '-', // marker for incomplete section of the bar
    leftBracketMarker: '[',
    rightBracketMarker: ']',
  },
  length: 30, // total length of the result, including the text
  textAlign: 'left', // align text relative to max possible text length of each entry.
  textPosition: 'right', // 'left' | 'right' | 'none'
  value: {
    digits: 1, // number of fraction digits. 0 | 1 | 2.
              // It defaults to different values depending on the max value.
    max: 1, // Value that means 100%.
            // It can be set to undefined, to indicate that value is not available.
            // But the render value must also be undefined.
            // If not it will throws MissingMaxValue.
    marker: '|', // marker for the value
    textStyle: 'percentage', // 'percentage' | 'number' | 'ratio'
    textTransform(text: string): string, // transform the styled string, can use this to color the text
  }
})

// To style multiple values differently.
progressBar({
  ...,
  value: [{ ... }, { ... }, ...],
})

Readme

Keywords

none

Package Sidebar

Install

npm i progress-str

Weekly Downloads

1

Version

3.4.4

License

MIT

Unpacked Size

36.8 kB

Total Files

36

Last publish

Collaborators

  • unional