Your IP : 216.73.216.86


Current Path : /home/emeraadmin/public_html/4d695/
Upload File :
Current File : /home/emeraadmin/public_html/4d695/proggy.tar

lib/tracker.js000064400000002570151701437300007310 0ustar00// 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.js000064400000001033151701437300006755 0ustar00exports.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.js000064400000005017151701437300007132 0ustar00const 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.json000064400000002643151701437300007040 0ustar00{
  "_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"
}
LICENSE000064400000001346151701437300005556 0ustar00The 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.