okami.mom/strata

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

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

main
500 B9 linesraw
1import type {Order} from './orders.ts';
2
3export function validateOrders(orders: Order[]): Order[] {
4  if(!Array.isArray(orders))throw new RangeError('orders');
5  return orders.map(o=>{
6    if(!o || typeof o.customer!=='string' || !o.customer.trim() || !Number.isInteger(o.priceCents) || o.priceCents<0 || !Number.isInteger(o.quantity) || o.quantity<=0 || (o.cancelled!==undefined && typeof o.cancelled!=='boolean'))throw new RangeError('order');
7    return {...o,customer:o.customer.trim()};
8  });
9}