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

@harvest-profit/units

Package Overview
Dependencies
Maintainers
4
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@harvest-profit/units - npm Package Compare versions

Comparing version 1.3.1 to 1.4.0

dist/definitions/liquid.js

6

dist/index.js

@@ -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

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