interface WindowWithTextEncoder extends Window { TextEncoder : any ; } const windowWithTextEncoder = window as WindowWithTextEncoder ; function isValidIndexNameLength ( indexName ) { if ( windowWithTextEncoder . TextEncoder && new windowWithTextEncoder . TextEncoder ( 'utf-8' ) . encode ( indexName ) . length > 255 ) { return false ; } return indexName . length <= 255 ; } export function isValidIndexName ( indexName ) { return ( indexName === indexName . toLowerCase ( ) && /^[^\*\\/\?"<>|\s,#:]+$/ . test ( indexName ) && /^[^-_\+]+$/ . test ( indexName . charAt ( 0 ) ) && indexName !== '.' && indexName !== '..' && isValidIndexNameLength ( indexName ) ) ; }