node-fetch-progress
Advanced tools
Comparing version 1.0.0 to 1.0.1
"use strict"; | ||
var _distance_in_words_to_now = _interopRequireDefault(require("date-fns/distance_in_words_to_now")); | ||
var _add_seconds = _interopRequireDefault(require("date-fns/add_seconds")); | ||
var _throttleDebounce = require("throttle-debounce"); | ||
var _bytes = _interopRequireDefault(require("bytes")); | ||
var _events = _interopRequireDefault(require("events")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
@@ -21,13 +33,2 @@ | ||
var distanceInWordsToNow = require("date-fns/distance_in_words_to_now"); | ||
var addSeconds = require("date-fns/add_seconds"); | ||
var _require = require("throttle-debounce"), | ||
throttle = _require.throttle; | ||
var bytes = require("bytes"); | ||
var EventEmitter = require("events"); | ||
var Progress = | ||
@@ -45,14 +46,14 @@ /*#__PURE__*/ | ||
_this.options = options || {}; | ||
_this.total = Number(response.headers.get("content-length")); | ||
_this.total = Number(response.headers.get('content-length')); | ||
_this.done = 0; | ||
_this.startedAt = Date.now(); | ||
var throttled = throttle(_this.options.throttle || 0, _this.onProgress.bind(_assertThisInitialized(_assertThisInitialized(_this)))); | ||
response.body.on("data", function (chunk) { | ||
var throttled = (0, _throttleDebounce.throttle)(_this.options.throttle || 0, _this.onProgress.bind(_assertThisInitialized(_assertThisInitialized(_this)))); | ||
response.body.on('data', function (chunk) { | ||
_this.done += chunk.length; | ||
return throttled(); | ||
}); | ||
response.body.on("end", function () { | ||
response.body.on('end', function () { | ||
_this.onProgress(); | ||
_this.emit("finish"); | ||
_this.emit('finish'); | ||
}); | ||
@@ -66,15 +67,15 @@ return _this; | ||
function onProgress() { | ||
var totalh = bytes(this.total); | ||
var doneh = bytes(this.done); | ||
var totalh = (0, _bytes["default"])(this.total); | ||
var doneh = (0, _bytes["default"])(this.done); | ||
var elapsed = (Date.now() - this.startedAt) / 1000; | ||
var rate = this.done / elapsed; | ||
var rateh = bytes(rate) + "/s"; | ||
var rateh = "".concat((0, _bytes["default"])(rate), "/s"); | ||
var estimated = this.total / rate; | ||
var progress = this.done / this.total; | ||
var eta = estimated - elapsed; | ||
var etaDate = addSeconds(new Date(), eta); | ||
var etah = distanceInWordsToNow(etaDate, { | ||
var etaDate = (0, _add_seconds["default"])(new Date(), eta); | ||
var etah = (0, _distance_in_words_to_now["default"])(etaDate, { | ||
includeSeconds: true | ||
}); | ||
this.emit("progress", { | ||
this.emit('progress', { | ||
total: this.total, | ||
@@ -101,4 +102,4 @@ done: this.done, | ||
return Progress; | ||
}(EventEmitter); | ||
}(_events["default"]); | ||
module.exports = Progress; |
{ | ||
"name": "node-fetch-progress", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"main": "dist/index.js", | ||
"autor": "Michael Albertz <michael@prio.one>", | ||
"license": "MIT", | ||
@@ -61,3 +62,18 @@ "dependencies": { | ||
] | ||
} | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
}, | ||
"keywords": [ | ||
"fetch", | ||
"progress" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/prioe/node-fetch-progress.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/prioe/node-fetch-progress/issues" | ||
}, | ||
"homepage": "https://github.com/prioe/node-fetch-progress#readme" | ||
} |
@@ -1,14 +0,14 @@ | ||
const distanceInWordsToNow = require("date-fns/distance_in_words_to_now"); | ||
const addSeconds = require("date-fns/add_seconds"); | ||
const { throttle } = require("throttle-debounce"); | ||
const bytes = require("bytes"); | ||
const EventEmitter = require("events"); | ||
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now' | ||
import addSeconds from 'date-fns/add_seconds' | ||
import { throttle } from 'throttle-debounce' | ||
import bytes from 'bytes' | ||
import EventEmitter from 'events' | ||
class Progress extends EventEmitter { | ||
constructor(response, options) { | ||
super(); | ||
this.options = options || {}; | ||
this.total = Number(response.headers.get("content-length")); | ||
this.done = 0; | ||
this.startedAt = Date.now(); | ||
constructor (response, options) { | ||
super() | ||
this.options = options || {} | ||
this.total = Number(response.headers.get('content-length')) | ||
this.done = 0 | ||
this.startedAt = Date.now() | ||
@@ -18,28 +18,28 @@ const throttled = throttle( | ||
this.onProgress.bind(this) | ||
); | ||
) | ||
response.body.on("data", chunk => { | ||
this.done += chunk.length; | ||
return throttled(); | ||
}); | ||
response.body.on('data', (chunk) => { | ||
this.done += chunk.length | ||
return throttled() | ||
}) | ||
response.body.on("end", () => { | ||
this.onProgress(); | ||
this.emit("finish"); | ||
}); | ||
response.body.on('end', () => { | ||
this.onProgress() | ||
this.emit('finish') | ||
}) | ||
} | ||
onProgress() { | ||
const totalh = bytes(this.total); | ||
const doneh = bytes(this.done); | ||
const elapsed = (Date.now() - this.startedAt) / 1000; | ||
const rate = this.done / elapsed; | ||
const rateh = bytes(rate) + "/s"; | ||
const estimated = this.total / rate; | ||
const progress = this.done / this.total; | ||
const eta = estimated - elapsed; | ||
const etaDate = addSeconds(new Date(), eta); | ||
const etah = distanceInWordsToNow(etaDate, { includeSeconds: true }); | ||
onProgress () { | ||
const totalh = bytes(this.total) | ||
const doneh = bytes(this.done) | ||
const elapsed = (Date.now() - this.startedAt) / 1000 | ||
const rate = this.done / elapsed | ||
const rateh = `${bytes(rate)}/s` | ||
const estimated = this.total / rate | ||
const progress = this.done / this.total | ||
const eta = estimated - elapsed | ||
const etaDate = addSeconds(new Date(), eta) | ||
const etah = distanceInWordsToNow(etaDate, { includeSeconds: true }) | ||
this.emit("progress", { | ||
this.emit('progress', { | ||
total: this.total, | ||
@@ -58,6 +58,6 @@ done: this.done, | ||
etaDate | ||
}); | ||
}) | ||
} | ||
} | ||
module.exports = Progress; | ||
module.exports = Progress |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
9250
5
2
0
0
42
0