import { ReactElement } from 'react' ; import { IClusterMapProps } from './typings' ; const PACKAGE_PROPS = [ 'isClusterExpandClick' , 'superClusterOptions' , 'renderClusterMarker' , 'style' , 'onMapReady' , 'onRegionChangeComplete' , 'region' , 'onClusterClick' , 'priorityMarker' , 'onZoomChange' , ] ; export const formatChildren = ( children , isInCluster ) => { if ( ! children ) { return [ ] ; } const childrenList = ! Array . isArray ( children ) ? [ children ] : children ; return childrenList . flat ( 1 ) . filter ( ( child ) => isInCluster && child . props ? child . props . isOutsideCluster !== true : child . props . isOutsideCluster ) ; } ; export const serializeProps = ( userProps ) => { return Object . keys ( userProps ) . reduce ( ( newProps , propKey ) => { if ( PACKAGE_PROPS . find ( ( prop ) => prop === propKey ) ) { return newProps ; } return { ... newProps , [ propKey ] : userProps [ propKey ] } ; } , { } ) ; } ; export const makeId = ( ) => { let id = '' ; const possibleChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' ; for ( let i = 0 ; i < 10 ; i ++ ) { id += possibleChar . charAt ( Math . floor ( Math . random ( ) * possibleChar . length ) ) ; } return id ; } ; export const calculateDelta = ( x , y ) : number => x > y ? x - y : y - x ; export const calculateAverage = ( ... args ) : number => { const argList = [ ... args ] ; if ( ! argList . length ) { return 0 ; } return argList . reduce ( ( sum , num ) => sum + num , 0 ) / argList . length ; } ;