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

math-helper-functions

Package Overview
Dependencies
Maintainers
1
Versions
35
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

math-helper-functions - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

21

dist/math-helper-functions.cjs.development.js

@@ -5,4 +5,7 @@ 'use strict';

function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var d3Array = require('d3-array');
var lodash = require('lodash');
var get = _interopDefault(require('lodash/get'));
var isEmpty = _interopDefault(require('lodash/isEmpty'));

@@ -19,5 +22,5 @@ /**

function getSimpleArray(array, property) {
if (!lodash.isEmpty(property)) {
if (isEmpty(property) === false) {
return array.map(function (d) {
return lodash.get(d, property);
return get(d, property);
});

@@ -63,3 +66,3 @@ } else {

if (lodash.isEmpty(array)) {
if (isEmpty(array)) {
return 0;

@@ -92,7 +95,7 @@ }

if (weight === midpoint) {
var prevItem = lodash.get(sortedArray[index - 1], 'value', 0);
var currItem = lodash.get(sortedArray[index], 'value', 0);
var prevItem = get(sortedArray[index - 1], 'value', 0);
var currItem = get(sortedArray[index], 'value', 0);
return (prevItem + currItem) / 2;
} else {
return lodash.get(sortedArray[index - 1], 'value', 0);
return get(sortedArray[index - 1], 'value', 0);
}

@@ -128,4 +131,4 @@ }

var result = array.map(function (d) {
var weight = lodash.get(d, weightProperty, 0);
var upper = lodash.get(d, valueProperty, 0) * weight;
var weight = get(d, weightProperty, 0);
var upper = get(d, valueProperty, 0) * weight;
return [upper, weight];

@@ -132,0 +135,0 @@ }).reduce(function (acc, d) {

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var r=require("d3-array"),e=require("lodash");function t(r,t){return e.isEmpty(t)?r:r.map((function(r){return e.get(r,t)}))}var n=function(r,e){this.value=r,this.weight=e};function u(e,n){return r.extent(t(e,n))}function a(r,e,t){return e*t/r}exports.calcDistribution=function(e,t){return(null==t?r.histogram():r.histogram().thresholds(t))(e).reduce((function(r,e){var t=e.length;return r.labels.push(e.x0+" - "+e.x1),r.data.push(t),r}),{labels:[],data:[]})},exports.calcDomain=u,exports.calcHistogram=function(r,e,n){void 0===e&&(e=4);for(var a=t(r,n),o=u(a),i=o[0],c=(o[1]-i)/e,s=a.length,l=new Array(e).fill(0),h=0;h<s;h++)l[Math.min(Math.floor((a[h]-i)/c),e-1)]+=1;return l},exports.calcMax=function(e,n){return r.max(t(e,n))},exports.calcMean=function(e,n){return r.mean(t(e,n))},exports.calcMedian=function(e,n){return r.median(t(e,n))},exports.calcMin=function(e,n){return r.min(t(e,n))},exports.calcPercent=function(r,e){return a(e,100,r)},exports.calcQuartiles=function(r,e){var n=r.length,u=[].concat(t(r,e));return u.sort((function(r,e){return r-e})),[u[Math.round(n/4)-1],u[Math.round(n/2)-1],u[Math.round(3*n/4)-1]]},exports.calcSum=function(e,n){return r.sum(t(e,n))},exports.calcWeightedMean=function(r,t,n){if(!t||!n)throw new Error("Both valueProperty and weightProperty params are required");var u=r.map((function(r){var u=e.get(r,n,0);return[e.get(r,t,0)*u,u]})).reduce((function(r,e){return[r[0]+e[0],r[1]+e[1]]}),[0,0]);return u[0]/u[1]},exports.calcWeightedMedian=function(r,t,u){if(!t||!u)throw new Error("Both valueProperty and weightProperty params are required");if(e.isEmpty(r))return 0;for(var a=r.reduce((function(r,e){return r.array.push(new n(e[t],e[u])),r.weightSum+=e[u],r}),{array:[],weightSum:0}),o=a.weightSum,i=a.array.sort((function(r,e){return r.value-e.value})),c=o/2,s=0,l=0;l<c;)l+=i[s].weight,s++;return l===c?(e.get(i[s-1],"value",0)+e.get(i[s],"value",0))/2:e.get(i[s-1],"value",0)},exports.ruleOfThree=a;
"use strict";function r(r){return r&&"object"==typeof r&&"default"in r?r.default:r}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("d3-array"),t=r(require("lodash/get")),n=r(require("lodash/isEmpty"));function u(r,e){return!1===n(e)?r.map((function(r){return t(r,e)})):r}var a=function(r,e){this.value=r,this.weight=e};function o(r,t){return e.extent(u(r,t))}function i(r,e,t){return e*t/r}exports.calcDistribution=function(r,t){return(null==t?e.histogram():e.histogram().thresholds(t))(r).reduce((function(r,e){var t=e.length;return r.labels.push(e.x0+" - "+e.x1),r.data.push(t),r}),{labels:[],data:[]})},exports.calcDomain=o,exports.calcHistogram=function(r,e,t){void 0===e&&(e=4);for(var n=u(r,t),a=o(n),i=a[0],c=(a[1]-i)/e,l=n.length,s=new Array(e).fill(0),f=0;f<l;f++)s[Math.min(Math.floor((n[f]-i)/c),e-1)]+=1;return s},exports.calcMax=function(r,t){return e.max(u(r,t))},exports.calcMean=function(r,t){return e.mean(u(r,t))},exports.calcMedian=function(r,t){return e.median(u(r,t))},exports.calcMin=function(r,t){return e.min(u(r,t))},exports.calcPercent=function(r,e){return i(e,100,r)},exports.calcQuartiles=function(r,e){var t=r.length,n=[].concat(u(r,e));return n.sort((function(r,e){return r-e})),[n[Math.round(t/4)-1],n[Math.round(t/2)-1],n[Math.round(3*t/4)-1]]},exports.calcSum=function(r,t){return e.sum(u(r,t))},exports.calcWeightedMean=function(r,e,n){if(!e||!n)throw new Error("Both valueProperty and weightProperty params are required");var u=r.map((function(r){var u=t(r,n,0);return[t(r,e,0)*u,u]})).reduce((function(r,e){return[r[0]+e[0],r[1]+e[1]]}),[0,0]);return u[0]/u[1]},exports.calcWeightedMedian=function(r,e,u){if(!e||!u)throw new Error("Both valueProperty and weightProperty params are required");if(n(r))return 0;for(var o=r.reduce((function(r,t){return r.array.push(new a(t[e],t[u])),r.weightSum+=t[u],r}),{array:[],weightSum:0}),i=o.weightSum,c=o.array.sort((function(r,e){return r.value-e.value})),l=i/2,s=0,f=0;f<l;)f+=c[s].weight,s++;return f===l?(t(c[s-1],"value",0)+t(c[s],"value",0))/2:t(c[s-1],"value",0)},exports.ruleOfThree=i;
//# sourceMappingURL=math-helper-functions.cjs.production.min.js.map
import { median, mean, max, min, extent, histogram, sum } from 'd3-array';
import { isEmpty, get } from 'lodash-es';
import get from 'lodash-es/get';
import isEmpty from 'lodash-es/isEmpty';

@@ -14,3 +15,3 @@ /**

function getSimpleArray(array, property) {
if (!isEmpty(property)) {
if (isEmpty(property) === false) {
return array.map(function (d) {

@@ -17,0 +18,0 @@ return get(d, property);

{
"name": "math-helper-functions",
"version": "2.0.1",
"version": "2.0.2",
"description": "Helper with misc. math functions such as sums, averages, max, min, etc",

@@ -5,0 +5,0 @@ "main": "dist/index.js",

@@ -1,2 +0,3 @@

import {get, isEmpty} from 'lodash';
import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty';

@@ -12,3 +13,3 @@ /**

export function getSimpleArray(array: any[], property?: string): any[] {
if (!isEmpty(property)) {
if (isEmpty(property) === false) {
return array.map((d) => get(d, property as string));

@@ -15,0 +16,0 @@ } else {

import {mean, median} from 'd3-array';
import {getSimpleArray} from './arrays';
import {isEmpty, get} from 'lodash';
import get from 'lodash/get';
import isEmpty from 'lodash/isEmpty';

@@ -5,0 +6,0 @@ /**

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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