okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-142c-small into f-142407ea8192

main
648 B14 linesraw
1export type Request = {id:string;sku:string;quantity:number};
2export function uniqueRequests(requests:Request[]):Request[]{
3 const out:Request[]=[];const seen=new Set<string>();
4 for(const r of requests){
5  if(typeof r.id!=='string'||typeof r.sku!=='string')throw new RangeError('id and sku must be strings');
6  const id=r.id.trim();const sku=r.sku.trim();
7  if(id===''||sku==='')throw new RangeError('id and sku must be nonempty');
8  if(!Number.isInteger(r.quantity)||r.quantity<=0)throw new RangeError('quantity must be a positive integer');
9  if(seen.has(id))continue;
10  seen.add(id);
11  out.push({id,sku,quantity:r.quantity});
12 }
13 return out;
14}