MCPcopy Create free account
hub / github.com/Packstack-Tech/packstack / getItemWeight

Function getItemWeight

frontend/src/lib/utils/weight.ts:59–69  ·  view source on GitHub ↗
(unit: WeightUnit, item: PackItem | Item)

Source from the content-addressed store, hash-verified

57};
58
59export const getItemWeight = (unit: WeightUnit, item: PackItem | Item): WeightProps => {
60 const { weight, weight_unit } = item;
61 const quantity = 'packItem' in item ? item.packItem.quantity : 1;
62 const conversionValue = weight_unit ? converter(weight).from(unitDict[weight_unit]).to(unitDict[unit]) : 0;
63 const floatValue = parseFloat(conversionValue) * quantity;
64
65 return {
66 value: floatValue,
67 label: floatValue.toFixed(2)
68 }
69};
70
71export const getWeightByCategory = (unit: WeightUnit, items: (PackItem | Item)[]): CategoryItemSpecs[] => {
72 const itemsByCategory = getItemsByCategory(items);

Callers 1

ItemsFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected