export type Stock = {sku:string;units:number}; export function buildStock(stock:Stock[]):Map{ const m=new Map(); for(const s of stock){ const sku=s.sku.trim(); if(!sku)throw new RangeError('empty sku'); if(!Number.isInteger(s.units)||s.units<0)throw new RangeError('invalid units'); m.set(sku,(m.get(sku)??0)+s.units); } return m; }