import { ILLEGAL_CHARACTERS_VISIBLE , CONTAINS_SPACES_KEY , ILLEGAL_CHARACTERS_KEY } from './types' ; function indexPatternContainsSpaces ( indexPattern ) { return indexPattern . includes ( ' ' ) ; } function findIllegalCharacters ( indexPattern ) { const illegalCharacters = ILLEGAL_CHARACTERS_VISIBLE . reduce ( ( chars , char ) => { if ( indexPattern . includes ( char ) ) { chars . push ( char ) ; } return chars ; } , [ ] ) ; return illegalCharacters ; } export function validateIndexPattern ( indexPattern ) { const errors = { } ; const illegalCharacters = findIllegalCharacters ( indexPattern ) ; if ( illegalCharacters . length ) { errors [ ILLEGAL_CHARACTERS_KEY ] = illegalCharacters ; } if ( indexPatternContainsSpaces ( indexPattern ) ) { errors [ CONTAINS_SPACES_KEY ] = true ; } return errors ; }