| Current Path : /home/emeraadmin/public_html/4d695/ |
| Current File : /home/emeraadmin/public_html/4d695/proggy.tar |
lib/tracker.js 0000644 00000002570 15170143730 0007310 0 ustar 00 // The tracker class is intentionally as naive as possible. it is just
// an ergonomic wrapper around process.emit('progress', ...)
const EE = require('events')
class Tracker extends EE {
constructor (name, key, total) {
super()
if (!name) {
throw new Error('proggy: Tracker needs a name')
}
if (typeof key === 'number' && !total) {
total = key
key = null
}
if (!total) {
total = 100
}
if (!key) {
key = name
}
this.done = false
this.name = name
this.key = key
this.value = 0
this.total = total
}
finish (metadata = {}) {
this.update(this.total, this.total, metadata)
}
update (value, total, metadata) {
if (!metadata) {
if (total && typeof total === 'object') {
metadata = total
} else {
metadata = {}
}
}
if (typeof total !== 'number') {
total = this.total
}
if (this.done) {
const msg = `proggy: updating completed tracker: ${JSON.stringify(this.key)}`
throw new Error(msg)
}
this.value = value
this.total = total
const done = this.value >= this.total
process.emit('progress', this.key, {
...metadata,
name: this.name,
key: this.key,
value,
total,
done,
})
if (done) {
this.done = true
this.emit('done')
}
}
}
module.exports = Tracker
lib/index.js 0000644 00000001033 15170143730 0006755 0 ustar 00 exports.Client = require('./client.js')
exports.Tracker = require('./tracker.js')
const trackers = new Map()
exports.createTracker = (name, key, total) => {
const tracker = new exports.Tracker(name, key, total)
if (trackers.has(tracker.key)) {
const msg = `proggy: duplicate progress id ${JSON.stringify(tracker.key)}`
throw new Error(msg)
}
trackers.set(tracker.key, tracker)
tracker.on('done', () => trackers.delete(tracker.key))
return tracker
}
exports.createClient = (options = {}) => new exports.Client(options)
lib/client.js 0000644 00000005017 15170143730 0007132 0 ustar 00 const EE = require('events')
const onProgress = Symbol('onProgress')
const bars = Symbol('bars')
const listener = Symbol('listener')
const normData = Symbol('normData')
class Client extends EE {
constructor ({ normalize = false, stopOnDone = false } = {}) {
super()
this.normalize = !!normalize
this.stopOnDone = !!stopOnDone
this[bars] = new Map()
this[listener] = null
}
get size () {
return this[bars].size
}
get listening () {
return !!this[listener]
}
addListener (...args) {
return this.on(...args)
}
on (ev, ...args) {
if (ev === 'progress' && !this[listener]) {
this.start()
}
return super.on(ev, ...args)
}
off (ev, ...args) {
return this.removeListener(ev, ...args)
}
removeListener (ev, ...args) {
const ret = super.removeListener(ev, ...args)
if (ev === 'progress' && this.listeners(ev).length === 0) {
this.stop()
}
return ret
}
stop () {
if (this[listener]) {
process.removeListener('progress', this[listener])
this[listener] = null
}
}
start () {
if (!this[listener]) {
this[listener] = (...args) => this[onProgress](...args)
process.on('progress', this[listener])
}
}
[onProgress] (key, data) {
data = this[normData](key, data)
if (!this[bars].has(key)) {
this.emit('bar', key, data)
}
this[bars].set(key, data)
this.emit('progress', key, data)
if (data.done) {
this[bars].delete(key)
this.emit('barDone', key, data)
if (this.size === 0) {
if (this.stopOnDone) {
this.stop()
}
this.emit('done')
}
}
}
[normData] (key, data) {
const actualValue = data.value
const actualTotal = data.total
let value = actualValue
let total = actualTotal
const done = data.done || value >= total
if (this.normalize) {
const bar = this[bars].get(key)
total = 100
if (done) {
value = 100
} else {
// show value as a portion of 100
const pct = 100 * actualValue / actualTotal
if (bar) {
// don't ever go backwards, and don't stand still
// move at least 1% of the remaining value if it wouldn't move.
value = (pct > bar.value) ? pct
: (100 - bar.value) / 100 + bar.value
}
}
}
// include the key
return {
...data,
key,
name: data.name || key,
value,
total,
actualValue,
actualTotal,
done,
}
}
}
module.exports = Client
package.json 0000644 00000002643 15170143730 0007040 0 ustar 00 {
"_id": "proggy@2.0.0",
"_inBundle": true,
"_location": "/npm/proggy",
"_phantomChildren": {},
"_requiredBy": [
"/npm/@npmcli/arborist"
],
"author": {
"name": "GitHub Inc."
},
"bugs": {
"url": "https://github.com/npm/proggy/issues"
},
"description": "Progress bar updates at a distance",
"devDependencies": {
"@npmcli/eslint-config": "^3.0.1",
"@npmcli/template-oss": "4.5.1",
"chalk": "^4.1.2",
"cli-progress": "^3.10.0",
"npmlog": "^6.0.1",
"tap": "^16.0.1"
},
"engines": {
"node": "^14.17.0 || ^16.13.0 || >=18.0.0"
},
"files": [
"bin/",
"lib/"
],
"homepage": "https://github.com/npm/proggy#readme",
"license": "ISC",
"main": "lib/index.js",
"name": "proggy",
"repository": {
"type": "git",
"url": "git+https://github.com/npm/proggy.git"
},
"scripts": {
"lint": "eslint \"**/*.js\"",
"lintfix": "npm run lint -- --fix",
"postlint": "template-oss-check",
"postsnap": "eslint lib test --fix",
"posttest": "npm run lint",
"snap": "tap",
"template-oss-apply": "template-oss-apply --force",
"test": "tap"
},
"tap": {
"coverage-map": "map.js",
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
]
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"version": "4.5.1"
},
"version": "2.0.0"
}
LICENSE 0000644 00000001346 15170143730 0005556 0 ustar 00 The ISC License
Copyright (c) GitHub, Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.