@adyen/adyen-platform-experience-web
Version:

19 lines (18 loc) • 820 B
JavaScript
import { EMPTY_ARRAY as a } from "../../../../../utils/value/constants.js";
import { isUndefined as r } from "../../../../../utils/value/is.js";
import { clamp as s } from "../../../../../utils/value/number.js";
const f = (o, u, i, c = 0) => {
const { ...n } = o.get(i.id), t = s(0, Math.trunc(c), n.quantity += i.quantity);
n.quantity -= t, o.set(i.id, Object.freeze(n)), t > 0 && u.push(Object.freeze({ ...n, quantity: t }));
}, q = (o, u, i = a) => {
const c = new Map((i == null ? void 0 : i.map(({ id: t, quantity: e }) => [t, e])) ?? a), n = [];
return u.forEach((t) => {
const e = c.get(t.id);
r(e) ? n.push(t) : c.delete(t.id) && f(o, n, t, e);
}), c.forEach((t, e) => {
f(o, n, { id: e, quantity: 0 }, t);
}), n.length > 0 ? Object.freeze(n) : a;
};
export {
q as updateRefundItems
};