okami.mom/strata

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

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

main
594 B12 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'||typeof r.quantity!=='number'||!Number.isInteger(r.quantity)||r.quantity<=0)throw new RangeError('invalid request record');
6  const id=r.id.trim();const sku=r.sku.trim();
7  if(id===''||sku==='')throw new RangeError('empty id or sku');
8  if(seen.has(id))continue;
9  seen.add(id);out.push({id,sku,quantity:r.quantity});
10 }
11 return out;
12}