import { AxiosError } from 'axios' ; import { Group , ContentElement } from '../models' ; import * as presets from './presets' ; export const getSectionPosition = ( section ) => ( { pageNumber : section . coordinates [ 0 ] . page , position : section . coordinates [ 0 ] . y , } ) ; export const createEvent = < D extends any > ( type , details ) => { return new CustomEvent < D > ( type , { detail : details } ) ; } ; export const createListener = < T extends object > ( type , cb ) => { document . addEventListener ( type , cb as EventListener ) ; return ( ) => document . removeEventListener ( type , cb as EventListener ) ; } ; export const isMac = /mac/i . test ( navigator . platform ) ; export const filterGroups = < T extends Group > ( groups , value ) => { return groups . filter ( group => new RegExp ( `^${ value }` , 'i' ) . test ( group . name ) ) ; } ; export const isAxiosError = ( e ) : e is AxiosError => { return e && typeof e === 'object' && e . hasOwnProperty ( 'isAxiosError' ) ; } ; export const isValidEmailAddress = ( email ) => { const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/ ; return re . test ( email ) ; } ; export { presets } ;