Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@serverless-devs/progress-bar

Package Overview
Dependencies
Maintainers
3
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@serverless-devs/progress-bar

progress-bar for serverless-devs

  • 0.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
3
Weekly downloads
 
Created
Source

下载(@serverless-devs/progress-bar)

安装

$ npm install @serverless-devs/progress-bar --save

基本使用

import ProgressBar, { ProgressType } from '@serverless-devs/progress-bar';

const bar = new ProgressService(
  ProgressType.Loading,
  {
    total: 1000,
  }
);
for (let i = 0; i < 1000; i += 50) {
  bar.update(i);
}
bar.complete();

参数解析

import ProgressBar, { ProgressType } from '@serverless-devs/progress-bar';

const result = new ProgressService(
  type,
  options,
  format,
);
参数说明类型必填默认值
type进度条的显示方式ProgressType.Bar:总尺寸已知的进度条; ProgressType.Loading:总大小未知的加载样式-
options进度条的选项OptionsProgressType.Bar 时必填-
format进度条格式, 详见formatString-

Options

参数说明类型必填默认值
total要完成的数据总数numberProgressType.Loading 时默认 100
curr当前已完成索引number-
width进度条显示宽度number{total}
renderThrottle更新之间的最短时间(以毫秒为单位)number16
stream输出流NodeJS.WritableStream{process.stderr}
head头部字符, 默认为完成字符string{complete}
complete完成字符string=
incomplete未完成字符string-
callback进度条完成时调用Function-

Format 简述

type 取值 ProgressType.Bar 时默认为 Loading ${green(':loading')} ((:bar)) :current/:total(Bytes) :percent :etas
type 取值 ProgressType.Loading 时默认为 Loading ${green(':loading')} ((:bar)) :etas

解析一下这段文字 Loading ${green(':loading')} ((:bar)) :current/:total(Bytes) :percent :etas

Loading 是一个显示前缀,可以替换为一些固定的文案。
green() 是引入的 chalk, 显示一下颜色效果
:loading['⣴', '⣆', '⢻', '⢪', '⢫'] 交替显示的一个动态效果
((:bar)) 是显示进度条,由参数 options.total 控制总长度,使用 result.update(curr) 修改显示完成度。
:current 显示当前完成度
:total 要完成的数据总数
:percent 完成的百分比
:etas 估计完成时间(以秒为单位)
:elapsed 经过的时间(以秒为单位)
:rate 每秒刻度数

result

result.update

更新进度状态

接受参数为 number 类型
返回值 无

示例:

result.update(50)
result.terminate

中断进度条显示,并在上面写一条消息(此条信息不会被删除)

接受参数 string 返回值 无

示例:

result.interrupt('终')
result.terminate

终止显示

接受参数 无
返回值 无

示例:

result.terminate()
result.complete

获取完成状态

接受参数 无
返回值 boolean

示例:

const complete = result.complete()
result.curr

获取当前已完成索引

接受参数 无
返回值 number

示例:

const curr = result.curr()
result.total

获取要完成的数据总数

接受参数 无
返回值 number

示例:

const total = result.total()

FAQs

Package last updated on 16 Jun 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc