leonmargaritis 397efc9ff4
Feat/lhac 202 reshape images and money (#4)
* feat: add reshape functions for money and image
2023-11-17 15:27:49 +01:00

26 lines
749 B
TypeScript

import {
TypedMoney as CommercetoolsTypedMoney,
Image as CommercetoolsImage,
CentPrecisionMoney,
HighPrecisionMoney,
TypedMoney
} from "@commercetools/platform-sdk";
import { Image, Money } from "./types";
export function reshapeMoney(typedMoney: TypedMoney): Money {
const { fractionDigits, currencyCode, type } = typedMoney;
const typedAmount = type === "centPrecision" ? typedMoney.centAmount : typedMoney.preciseAmount;
const amount = (typedAmount / Math.pow(10, fractionDigits)).toString();
return { amount, currencyCode };
}
export function reshapeImage(image: CommercetoolsImage): Image {
return {
url: image.url,
width: image.dimensions.w,
height: image.dimensions.h,
altText: image.label || ""
};
}