calc-stats
Advanced tools
Comparing version 0.0.4 to 0.1.0
@@ -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; |
{ | ||
"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" | ||
} | ||
} |
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
11877
2
64
+ Addediter-fun@^0.1.0
+ Addediter-fun@0.1.2(transitive)