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

npmlog

Package Overview
Dependencies
Maintainers
2
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

npmlog - npm Package Compare versions

Comparing version 0.1.1 to 1.0.0

test/progress.js

86

log.js

@@ -0,1 +1,4 @@

'use strict'
var Progress = require('are-we-there-yet')
var Gauge = require('gauge')
var EE = require('events').EventEmitter

@@ -23,2 +26,76 @@ var log = exports = module.exports = new EE

log.gauge = new Gauge(log.cursor)
log.tracker = new Progress.TrackerGroup()
// no progress bars unless asked
log.progressEnabled = false
var unicodeEnabled = undefined
log.enableUnicode = function () {
unicodeEnabled = true
log.gauge.theme = Gauge.unicode
}
log.disableUnicode = function () {
unicodeEnabled = false
log.gauge.theme = Gauge.ascii
}
log.enableProgress = function () {
if (this.progressEnabled) return
this.progressEnabled = true
if (this._pause) return
this.tracker.on('change', this.showProgress)
this.gauge.enable()
this.showProgress()
}
log.disableProgress = function () {
if (!this.progressEnabled) return
this.clearProgress()
this.progressEnabled = false
this.tracker.removeListener('change', this.showProgress)
this.gauge.disable()
}
var trackerConstructors = ['newGroup', 'newItem', 'newStream']
var mixinLog = function (tracker) {
// mixin the public methods from log into the tracker
// (except: conflicts and one's we handle specially)
Object.keys(log).forEach(function (P) {
if (P[0] === '_') return
if (trackerConstructors.filter(function (C) { return C === P }).length) return
if (tracker[P]) return
if (typeof log[P] !== 'function') return
var func = log[P]
tracker[P] = function () {
return func.apply(log, arguments)
}
})
// if the new tracker is a group, make sure any subtrackers get
// mixed in too
if (tracker instanceof Progress.TrackerGroup) {
trackerConstructors.forEach(function (C) {
var func = tracker[C]
tracker[C] = function () { return mixinLog(func.apply(tracker, arguments)) }
})
}
return tracker
}
// Add tracker constructors to the top level log object
trackerConstructors.forEach(function (C) {
log[C] = function () { return mixinLog(this.tracker[C].apply(this.tracker, arguments)) }
})
log.clearProgress = function () {
if (!this.progressEnabled) return
this.gauge.hide()
}
log.showProgress = function (name) {
if (!this.progressEnabled) return
this.gauge.show(name, this.tracker.completed())
}.bind(log) // bind for use in tracker's on-change listener
// temporarily stop emitting, but don't drop

@@ -38,2 +115,3 @@ log.pause = function () {

}, this)
if (this.progressEnabled) this.enableProgress()
}

@@ -93,2 +171,3 @@

}
if (this.progressEnabled) this.gauge.pulse(m.prefix)
var l = this.levels[m.level]

@@ -101,2 +180,3 @@ if (l === undefined) return

var disp = log.disp[m.level] || m.level
this.clearProgress()
m.message.split(/\r?\n/).forEach(function (line) {

@@ -113,2 +193,3 @@ if (this.heading) {

}, this)
this.showProgress()
}

@@ -120,2 +201,7 @@

this.cursor = ansi(this.stream, { enabled: colorEnabled })
var options = {}
if (unicodeEnabled != null) {
options.theme = unicodeEnabled ? Gauge.unicode : Gauge.ascii
}
this.gauge = new Gauge(options, this.cursor)
}

@@ -122,0 +208,0 @@

6

package.json

@@ -5,3 +5,3 @@ {

"description": "logger for npm",
"version": "0.1.1",
"version": "1.0.0",
"repository": {

@@ -16,3 +16,5 @@ "type": "git",

"dependencies": {
"ansi": "~0.3.0"
"ansi": "~0.3.0",
"are-we-there-yet": "~1.0.0",
"gauge": "~1.0.2"
},

@@ -19,0 +21,0 @@ "devDependencies": {

@@ -83,2 +83,18 @@ # npmlog

## log.enableProgress()
Enable the display of log activity spinner and progress bar
## log.disableProgress()
Disable the display of a progress bar
## log.enableUnicode()
Force the unicode theme to be used for the progress bar.
## log.disableUnicode()
Disable the use of unicode in the progress bar.
## log.pause()

@@ -127,2 +143,24 @@

## log.newItem(name, todo, weight)
* `name` {String} Optional; progress item name.
* `todo` {Number} Optional; total amount of work to be done. Default 0.
* `weight` {Number} Optional; the weight of this item relative to others. Default 1.
This adds a new `are-we-there-yet` item tracker to the progress tracker. The
object returned has the `log[level]` methods but is otherwise an
`are-we-there-yet` `Tracker` object.
## log.newStream(name, todo, weight)
This adds a new `are-we-there-yet` stream tracker to the progress tracker. The
object returned has the `log[level]` methods but is otherwise an
`are-we-there-yet` `TrackerStream` object.
## log.newGroup(name, weight)
This adds a new `are-we-there-yet` tracker group to the progress tracker. The
object returned has the `log[level]` methods but is otherwise an
`are-we-there-yet` `TrackerGroup` object.
# Events

@@ -129,0 +167,0 @@

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