forked from M3-Academy/challenge-vtex-io
31 lines
554 B
TypeScript
31 lines
554 B
TypeScript
export const calculationPercent = (
|
|
percent: number | undefined,
|
|
value: number | undefined
|
|
) => {
|
|
if (value && percent) {
|
|
const newPercent = percent / 100;
|
|
|
|
const discount = value * newPercent;
|
|
|
|
const newValue = value - discount;
|
|
|
|
return newValue.toFixed(2).toString().replace(".", ",");
|
|
}
|
|
|
|
return "";
|
|
};
|
|
|
|
export const sanatizeColor = (color: string) => {
|
|
if (color) {
|
|
const [first] = color.split(" ");
|
|
|
|
if (first.indexOf("c-") === 0) {
|
|
return first;
|
|
}
|
|
|
|
return "c-on-base";
|
|
}
|
|
|
|
return "c-on-base";
|
|
};
|