import _ from 'lodash' ; param html return export function escapeArray ( html ) { return _ . map ( html , ( character ) => { if ( character . length === 1 ) { return character . replace ( /[\u00A0-\u9999<>&]/g , ( substring ) => { return '&#' + substring . charCodeAt ( 0 ) + ';' ; } ) ; } return character ; } ) ; } param html return export function escape ( html ) ; export function escape ( html ) ; export function escape ( html ) { if ( _ . isArray ( html ) ) { return escapeArray ( html ) ; } return escapeArray ( Array . from ( html ) ) . join ( '' ) ; } param str return export function replaceImgTagByAlt ( str ) { return str . replace ( /<img.*?alt="(.*?)"[^>]?>/g , '$1' ) ; } param file return export function readTextFile ( file ) { return new Promise ( ( resolve , reject ) => { const fileReader = new FileReader ( ) ; fileReader . onabort = reject ; fileReader . onerror = reject ; fileReader . onload = ( event ) => { const target = event . target as FileReader ; if ( ! _ . isNil ( target ) && _ . isString ( target . result ) ) { resolve ( target . result ) ; } else { reject ( ) ; } } ; fileReader . readAsText ( file ) ; } ) ; } param url return export function sanitizeUrlForPreview ( urlToSanitize ) { let url = urlToSanitize ; if ( url . endsWith ( '.gifv' ) ) { url = url . slice ( 0 , - 1 ) ; } return url ; }