Socket
Socket
Sign inDemoInstall

apm

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.0 to 1.0.1

5

package.json
{
"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",

38

source/index.js
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;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc