Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "apm", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "Actions per minute! Or any other time, actually.", | ||
@@ -18,2 +18,5 @@ "main": "source/", | ||
], | ||
"scripts": { | ||
"prepublish" : "PACKAGE_VERSION=$(cat package.json | grep version | head -1 | awk -F: '{ print $2 }' | sed 's/[\",]//g' | tr -d '[[:space:]]') && git tag $PACKAGE_VERSION && git push --tags" | ||
}, | ||
"author": "Florian Wendelborn", | ||
@@ -20,0 +23,0 @@ "license": "MIT", |
function Module (options) { | ||
this.options = options; | ||
this.actions = {}; | ||
this.accuracy = options.accuracy || 1; | ||
this.timeSpan = options.timeSpan || 60; | ||
if (this.accuracy > this.timeSpan) { | ||
throw new Error('invalid arguments'); | ||
} | ||
this.data = []; | ||
for (var i = 0; i < this.timeSpan; i += this.accuracy) { | ||
this.data[i] = { | ||
lastUpdate: 0, | ||
amount: 0 | ||
}; | ||
} | ||
} | ||
@@ -10,9 +21,28 @@ | ||
} | ||
this.actions[id] += amount; | ||
var index = Math.floor( | ||
( | ||
Date.now() % ( | ||
this.timeSpan * 1000 | ||
) | ||
) / ( | ||
this.accuracy * 1000 | ||
) | ||
); | ||
if (this.data[index].lastUpdate - Date.now() > (this.timeSpan * 1000)) { | ||
this.data[index].amount = 0; | ||
} | ||
this.data[index].lastUpdate = Date.now(); | ||
this.data[index].amount += amount; | ||
}; | ||
Module.prototype.get = function (id) { | ||
return this.actions[id]; | ||
Module.prototype.get = function () { | ||
var result = 0; | ||
this.data.forEach(function (e) { | ||
if (e.lastUpdate - Date.now() > (this.timeSpan * 1000)) { | ||
result += e.amount; | ||
} | ||
}); | ||
return result; | ||
}; | ||
module.exports = Module; |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
3077
44
0