import * as cheerio from 'cheerio' ; import { v4 as uuidv4 } from 'uuid' ; export const fetchPage = async ( url , loadPage ) : Promise < cheerio . Root > => { const root = cheerio . load ( await loadPage ( url ) ) ; const html = root . html ( ) ; if ( html . includes ( 'error code:' ) || html . includes ( 'Sorry, you have been blocked' ) || html . includes ( 'Checking your browser before accessing' ) ) { throw new Error ( 'Access denied | www.hltv.org used Cloudflare to restrict access' ) ; } return root ; } ; export const generateRandomSuffix = ( ) => { return uuidv4 ( ) ; } ; export const percentageToDecimalOdd = ( odd ) : number => parseFloat ( ( ( 1 / odd ) * 100 ) . toFixed ( 2 ) ) ; export function getIdAt ( index , href ) ; export function getIdAt ( index ) ; export function getIdAt ( index ? , href ? ) { switch ( arguments . length ) { case 1 : return ( href ) => getIdAt ( index ! , href ) ; default : return parseNumber ( href ! . split ( '/' ) [ index ! ] ) ; } } export const notNull = < T > ( x ) : x is T => x !== null ; export const parseNumber = ( str ) : number | undefined => { if ( ! str ) { return undefined ; } const num = Number ( str ) ; return Number . isNaN ( num ) ? undefined : num ; } ; export const sleep = ( ms ) : Promise < void > => { return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ; } ;