@harvest-profit/units
Advanced tools
Comparing version 1.3.1 to 1.4.0
@@ -8,6 +8,6 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "math", { | ||
Object.defineProperty(exports, "Units", { | ||
enumerable: true, | ||
get: function get() { | ||
return _Math["default"]; | ||
return _Units["default"]; | ||
} | ||
@@ -19,3 +19,3 @@ }); | ||
var _Math = _interopRequireDefault(require("./Math")); | ||
var _Units = _interopRequireDefault(require("./Units")); | ||
@@ -22,0 +22,0 @@ var _default = _UnitsHelper["default"]; |
@@ -24,6 +24,4 @@ "use strict"; | ||
var _lodash = _interopRequireDefault(require("lodash")); | ||
var _Units = _interopRequireDefault(require("./Units")); | ||
var _Math = _interopRequireDefault(require("./Math")); | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2["default"])(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2["default"])(this, result); }; } | ||
@@ -92,3 +90,3 @@ | ||
if (UnitsHelper.isCompatibleUnit(parsedFromUnit, parsedToUnit)) { | ||
return _Math["default"].unit(amount, parsedFromUnit).to(parsedToUnit).toNumber(); | ||
return new _Units["default"](amount, parsedFromUnit).to(parsedToUnit).toNumber(); | ||
} | ||
@@ -114,3 +112,3 @@ | ||
(0, _defineProperty2["default"])(UnitsHelper, "isCompatibleUnit", function (unit1, unit2) { | ||
return _Math["default"].unit(1, unit1).equalBase(_Math["default"].unit(1, unit2)); | ||
return _Units["default"].isCompatible(unit1, unit2); | ||
}); | ||
@@ -120,12 +118,5 @@ (0, _defineProperty2["default"])(UnitsHelper, "isLiquid", function (product) { | ||
}); | ||
(0, _defineProperty2["default"])(UnitsHelper, "liquidToSolid", function (liquidUnits, liquidUnitName, solidUnitName, density) { | ||
var densityName = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 'lbs/gal'; | ||
var densityConversion = _Math["default"].unit(density, densityName); | ||
var totalLiquid = _Math["default"].unit(liquidUnits, liquidUnitName); | ||
var totalSolid = _Math["default"].multiply(totalLiquid, densityConversion); | ||
return totalSolid.to(solidUnitName); | ||
(0, _defineProperty2["default"])(UnitsHelper, "liquidToSolid", function (liquidAmount, liquidUnitName, solidUnitName, density) { | ||
var liquidAmountInGallons = new _Units["default"](liquidAmount, liquidUnitName).to('gallons'); | ||
return new _Units["default"](liquidAmountInGallons.toNumber() * density, 'lbs').to(solidUnitName); | ||
}); | ||
@@ -137,3 +128,3 @@ (0, _defineProperty2["default"])(UnitsHelper, "perAcreCost", function (product, item, acres) { | ||
if (item.split) { | ||
acresRatio = _lodash["default"].toNumber(item.applied_acres) / acres; | ||
acresRatio = parseFloat(item.applied_acres || 0) / acres; | ||
} | ||
@@ -148,7 +139,6 @@ | ||
}); | ||
(0, _defineProperty2["default"])(UnitsHelper, "perUnitCost", function (product, item) { | ||
(0, _defineProperty2["default"])(UnitsHelper, "lineItemToProductUnits", function (item, product) { | ||
var productUnit = UnitsHelper.parseUnit(product.units); | ||
var lineItemUnit = UnitsHelper.parseUnit(item.units); | ||
var isProductLiquid = product.liquid && product.density > 0; | ||
var totalPerUnit = 0; | ||
@@ -159,75 +149,36 @@ try { | ||
var unit = lineItemUnit === 'custom' ? 'seed' : lineItemUnit; | ||
var lineItemInSeedUnits = _Math["default"].unit(amount, unit).to('seeds').toNumber(); | ||
var lineItemInSeedUnits = new _Units["default"](amount, unit).to('seeds').toNumber(); | ||
var lineIteminCustomUnits = lineItemInSeedUnits / product.multiplier; | ||
totalPerUnit = product.price * lineIteminCustomUnits; | ||
return lineIteminCustomUnits; | ||
} else if (isProductLiquid && !UnitsHelper.isCompatibleUnit(lineItemUnit, productUnit)) { | ||
var lbsPerGallon = _Math["default"].unit("".concat(product.density, " lbs/gal")); | ||
var finalCalc = UnitsHelper.liquidToSolid(1, lineItemUnit, productUnit, product.density).toNumber(); | ||
var finalUnit = _Math["default"].multiply(_Math["default"].unit(1, lineItemUnit), lbsPerGallon); | ||
var finalCalc = finalUnit.to(productUnit).toNumber(); | ||
if (finalCalc > 0) { | ||
totalPerUnit = product.price * finalCalc; | ||
return finalCalc; | ||
} | ||
} else { | ||
// If all else fails, try to convert | ||
var lineItemInProductUnits = _Math["default"].unit(1, lineItemUnit).to(productUnit).toNumber(); | ||
var lineItemInProductUnits = new _Units["default"](1, lineItemUnit).to(productUnit).toNumber(); | ||
if (lineItemInProductUnits > 0) { | ||
totalPerUnit = product.price * lineItemInProductUnits; | ||
return lineItemInProductUnits; | ||
} | ||
} | ||
} catch (error) { | ||
totalPerUnit = product.price; | ||
return 1; | ||
} | ||
return totalPerUnit; | ||
return 0; | ||
}); | ||
(0, _defineProperty2["default"])(UnitsHelper, "perUnitCost", function (product, item) { | ||
return UnitsHelper.lineItemToProductUnits(item, product) * product.price; | ||
}); | ||
(0, _defineProperty2["default"])(UnitsHelper, "toProductUnits", function (item, product) { | ||
var productUnit = UnitsHelper.parseUnit(product.units); | ||
var lineItemUnit = UnitsHelper.parseUnit(item.units); | ||
var isProductLiquid = product.liquid && product.density > 0; | ||
var totalAmount = 0; | ||
try { | ||
if (productUnit === 'custom') { | ||
var amount = lineItemUnit === 'custom' ? product.multiplier : 1; | ||
var unit = lineItemUnit === 'custom' ? 'seed' : lineItemUnit; | ||
var lineItemInSeedUnits = _Math["default"].unit(amount, unit).to('seeds').toNumber(); | ||
var lineIteminCustomUnits = lineItemInSeedUnits / product.multiplier; | ||
totalAmount = lineIteminCustomUnits * item.amount; | ||
} else if (isProductLiquid && !UnitsHelper.isCompatibleUnit(lineItemUnit, productUnit)) { | ||
var lbsPerGallon = _Math["default"].unit("".concat(product.density, " lbs/gal")); | ||
var finalUnit = _Math["default"].multiply(_Math["default"].unit(1, lineItemUnit), lbsPerGallon); | ||
var finalCalc = finalUnit.to(productUnit).toNumber(); | ||
if (finalCalc > 0) { | ||
totalAmount = finalCalc * item.amount; | ||
} | ||
} else { | ||
// If all else fails, try to convert | ||
var lineItemInProductUnits = _Math["default"].unit(1, lineItemUnit).to(productUnit).toNumber(); | ||
if (lineItemInProductUnits > 0) { | ||
totalAmount = lineItemInProductUnits * item.amount; | ||
} | ||
} | ||
} catch (error) { | ||
totalAmount = item.amount; | ||
} | ||
return totalAmount; | ||
return UnitsHelper.lineItemToProductUnits(item, product) * item.amount; | ||
}); | ||
(0, _defineProperty2["default"])(UnitsHelper, "parseUnit", function (unit) { | ||
return unit.replace('per ', '').replace('fl oz', 'floz').replace(' - ', '').replace('metric ton', 'tonne'); | ||
return unit.replace('per ', ''); | ||
}); | ||
(0, _defineProperty2["default"])(UnitsHelper, "parseOldUnit", function (unit) { | ||
return unit.replace('fl oz', 'floz').replace('litres', 'liters'); | ||
return unit; | ||
}); | ||
@@ -234,0 +185,0 @@ (0, _defineProperty2["default"])(UnitsHelper, "isLiquidUnit", function (unit) { |
{ | ||
"name": "@harvest-profit/units", | ||
"version": "1.3.1", | ||
"version": "1.4.0", | ||
"description": "Units helper for Harvest Profit javascript applications", | ||
@@ -29,6 +29,3 @@ "main": "dist/index.js", | ||
}, | ||
"dependencies": { | ||
"lodash": "^4.17.21", | ||
"mathjs": "^3.20.2" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
@@ -35,0 +32,0 @@ "@babel/cli": "^7", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
43532
0
17
432
1
- Removedlodash@^4.17.21
- Removedmathjs@^3.20.2
- Removedcomplex.js@2.0.4(transitive)
- Removeddecimal.js@9.0.1(transitive)
- Removedescape-latex@1.2.0(transitive)
- Removedfraction.js@4.0.4(transitive)
- Removedjavascript-natural-sort@0.7.1(transitive)
- Removedlodash@4.17.21(transitive)
- Removedmathjs@3.20.2(transitive)
- Removedseed-random@2.2.0(transitive)
- Removedtiny-emitter@2.0.2(transitive)
- Removedtyped-function@0.10.7(transitive)