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

calc-stats

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

calc-stats - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0

64

calc-stats.js

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

const { getOrCreateIterator } = require("iter-fun");
const fasterMedian = require("faster-median");
const isArray = (data) => {
try {
return data.constructor.name.endsWith("Array");
} catch {
return false;
}
};
const hasNext = (data) => {
try {
return typeof data.next === "function";
} catch {
return false;
}
};
const hasIterator = (data) => {
try {
return "@@iterator" in data;
} catch {
return false;
}
};
const hasSymbolIterator = (data) => {
try {
return Symbol.iterator in data.constructor.prototype;
} catch {
return false;
}
};
const getIterator = (data) => {
const iter = data["@@iterator"];
if (hasNext(iter)) {
return iter;
} else if (typeof iter === "function") {
return iter();
}
};
const createIterator = (data) => {
let i = 0;
let len = data.length;
return {
next: () => (i++ < len ? { value: data[i], done: false } : { done: true }),
};
};
function calcStats(

@@ -65,16 +17,4 @@ data,

) {
let iter;
const iter = getOrCreateIterator(data);
if (hasNext(data)) {
iter = data;
} else if (hasSymbolIterator(data)) {
iter = data[Symbol.iterator]();
} else if (hasIterator(data)) {
iter = getIterator(data);
} else if (typeof data === "string" || isArray(data)) {
iter = createIterator(data);
} else {
throw "[calc-stats] unable to determine iterator";
}
let needCount = calcMean || calcMedian;

@@ -81,0 +21,0 @@ let needHistogram = calcHistogram || calcMedian || calcMode || calcModes;

5

package.json
{
"name": "calc-stats",
"version": "0.0.4",
"version": "0.1.0",
"description": "Memory-Aware Statistical Calculations",

@@ -40,4 +40,5 @@ "main": "calc-stats.js",

"dependencies": {
"faster-median": "^0.2.0"
"faster-median": "^0.2.0",
"iter-fun": "^0.1.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