File tree Expand file tree Collapse file tree
routes/tools/test/productPriority Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -149,6 +149,14 @@ export function escapeHtml(unsafe: string)
149149 . replace ( / ' / g, "'" ) ;
150150}
151151
152+ export function isIterable ( obj : never ) {
153+ // checks for null and undefined
154+ if ( obj == null ) {
155+ return false ;
156+ }
157+ return typeof obj [ Symbol . iterator ] === 'function' ;
158+ }
159+
152160
153161
154162export type HistoricalEntry = {
Original file line number Diff line number Diff line change 11<script lang =" ts" >
22
33 import {flip } from " svelte/animate" ;
4+ import { isIterable } from " $lib/utils" ;
45
56 export let data;
67
1112
1213 $ : {
1314 i ;
14- for (const product of data .products ) {
15- const lastStock = JSON .parse (product .stock );
16- const velocityInfluence = (product .available && product .purchasesPerHour == - 1 ? 100 : product .purchasesPerHour ) * (Math .random ()/ 2 );
17- let distance = (Date .now () - product .stockChecked );
18- if (! product .available && distance > 10 ) distance *= (Math .random ()/ 32 )
19- rankings [product .handle ] = ((distance / (3 * 60 * 60e3 )) + velocityInfluence ) / (lastStock ?.total === 0 ? 100 : (lastStock ?.total === - 1 ? 10 : 1 ));
20-
15+ if (isIterable (data .products as never )) {
16+ for (const product of data .products ) {
17+ const lastStock = JSON .parse (product .stock );
18+ const velocityInfluence = (product .available && product .purchasesPerHour == - 1 ? 100 : product .purchasesPerHour ) * (Math .random ()/ 2 );
19+ let distance = (Date .now () - product .stockChecked );
20+ if (! product .available && distance > 10 ) distance *= (Math .random ()/ 32 )
21+ rankings [product .handle ] = ((distance / (3 * 60 * 60e3 )) + velocityInfluence ) / (lastStock ?.total === 0 ? 100 : (lastStock ?.total === - 1 ? 10 : 1 ));
22+ }
2123 }
2224
2325 sortedRankings = Object .entries (rankings ).sort ((a , b ) => b [1 ] - a [1 ]);
You can’t perform that action at this time.
0 commit comments