math-helper-functions
Advanced tools
Comparing version 3.0.2 to 3.0.3
@@ -57,9 +57,20 @@ "use strict"; | ||
var import_get2 = __toESM(require("lodash/get")); | ||
var import_is2 = __toESM(require("@sindresorhus/is")); | ||
// src/modules/arrays.ts | ||
var import_get = __toESM(require("lodash/get")); | ||
var import_is = __toESM(require("@sindresorhus/is")); | ||
// src/modules/checks.ts | ||
function isEmptyString(val) { | ||
return typeof val === "string" && val.trim() === ""; | ||
} | ||
function isNonEmptyString(val) { | ||
return typeof val === "string" && val.trim() !== ""; | ||
} | ||
function isEmptyArray(value) { | ||
return Array.isArray(value) && value.length === 0; | ||
} | ||
// src/modules/arrays.ts | ||
function getSimpleArray(array, property) { | ||
if (import_is.default.nonEmptyString(property)) { | ||
if (isNonEmptyString(property)) { | ||
return array.map((d) => (0, import_get.default)(d, property)); | ||
@@ -84,3 +95,3 @@ } | ||
} | ||
if (import_is2.default.emptyArray(array)) { | ||
if (isEmptyArray(array)) { | ||
return 0; | ||
@@ -118,3 +129,3 @@ } | ||
function calcWeightedMean(array, valueProperty, weightProperty) { | ||
if (!import_is2.default.nonEmptyString(valueProperty) || !import_is2.default.nonEmptyString(weightProperty)) { | ||
if (isEmptyString(valueProperty) || isEmptyString(weightProperty)) { | ||
throw new Error("Both valueProperty and weightProperty params are required"); | ||
@@ -121,0 +132,0 @@ } |
@@ -57,9 +57,20 @@ "use strict"; | ||
var import_get2 = __toESM(require("lodash/get")); | ||
var import_is2 = __toESM(require("@sindresorhus/is")); | ||
// src/modules/arrays.ts | ||
var import_get = __toESM(require("lodash/get")); | ||
var import_is = __toESM(require("@sindresorhus/is")); | ||
// src/modules/checks.ts | ||
function isEmptyString(val) { | ||
return typeof val === "string" && val.trim() === ""; | ||
} | ||
function isNonEmptyString(val) { | ||
return typeof val === "string" && val.trim() !== ""; | ||
} | ||
function isEmptyArray(value) { | ||
return Array.isArray(value) && value.length === 0; | ||
} | ||
// src/modules/arrays.ts | ||
function getSimpleArray(array, property) { | ||
if (import_is.default.nonEmptyString(property)) { | ||
if (isNonEmptyString(property)) { | ||
return array.map((d) => (0, import_get.default)(d, property)); | ||
@@ -84,3 +95,3 @@ } | ||
} | ||
if (import_is2.default.emptyArray(array)) { | ||
if (isEmptyArray(array)) { | ||
return 0; | ||
@@ -118,3 +129,3 @@ } | ||
function calcWeightedMean(array, valueProperty, weightProperty) { | ||
if (!import_is2.default.nonEmptyString(valueProperty) || !import_is2.default.nonEmptyString(weightProperty)) { | ||
if (isEmptyString(valueProperty) || isEmptyString(weightProperty)) { | ||
throw new Error("Both valueProperty and weightProperty params are required"); | ||
@@ -121,0 +132,0 @@ } |
{ | ||
"name": "math-helper-functions", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"description": "Helper with misc. math functions such as sums, averages, max, min, etc", | ||
@@ -53,3 +53,2 @@ "main": "./dist/index.js", | ||
"dependencies": { | ||
"@sindresorhus/is": "^6.1.0", | ||
"d3-array": "^2.0.3", | ||
@@ -56,0 +55,0 @@ "lodash": "^4.17.21" |
import get from 'lodash/get'; | ||
import is from '@sindresorhus/is'; | ||
import { isNonEmptyString } from './checks'; | ||
@@ -14,3 +14,3 @@ /** | ||
export function getSimpleArray<T>(array: T[], property?: string): any[] { | ||
if (is.nonEmptyString(property)) { | ||
if (isNonEmptyString(property)) { | ||
return array.map((d) => get(d, property)); | ||
@@ -17,0 +17,0 @@ } |
@@ -5,4 +5,4 @@ import { | ||
import get from 'lodash/get'; | ||
import is from '@sindresorhus/is'; | ||
import { getSimpleArray } from './arrays'; | ||
import { isEmptyArray, isEmptyString } from './checks'; | ||
@@ -55,3 +55,3 @@ /** | ||
} | ||
if (is.emptyArray(array)) { | ||
if (isEmptyArray(array)) { | ||
return 0; | ||
@@ -120,3 +120,3 @@ } | ||
): number { | ||
if (!is.nonEmptyString(valueProperty) || !is.nonEmptyString(weightProperty)) { | ||
if (isEmptyString(valueProperty) || isEmptyString(weightProperty)) { | ||
throw new Error('Both valueProperty and weightProperty params are required'); | ||
@@ -123,0 +123,0 @@ } |
Sorry, the diff of this file is not supported yet
65341
2
15
1415
- Removed@sindresorhus/is@^6.1.0
- Removed@sindresorhus/is@6.3.1(transitive)