okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
407ea8192
main
1export type Stock = { sku :string ; units :number }; 2export function buildStock ( stock :Stock []) :Map < string , number >{ 3const map = new Map < string , number >(); 4for ( const s of stock ){ 5if ( typeof s . sku !== 'string' || s . sku . trim () === '' ) throw new RangeError ( 'invalid stock sku' ); 6if ( typeof s . units !== 'number' ||! Number . isInteger ( s . units ) || s . units < 0 ) throw new RangeError ( 'invalid stock units' ); 7const sku = s . sku . trim (); map . set ( sku ,( map . get ( sku ) ?? 0 ) + s . units ); 8} 9return map ; 10}