import * as tmp from 'tmp' ; export async function createTemporaryFile ( extension , temporaryDirectory ? ) { const options = { postfix : extension } ; if ( temporaryDirectory ) { options . dir = temporaryDirectory ; } return new Promise < { filePath : string ; cleanupCallback : Function ; } > ( ( resolve , reject ) => { tmp . file ( options , ( err , tmpFile , _fd , cleanupCallback ) => { if ( err ) { return reject ( err ) ; } resolve ( { filePath : tmpFile , cleanupCallback : cleanupCallback } ) ; } ) ; } ) ; } export function formatDate ( date ) { const lang = process . env . language ; const dateOptions = { weekday : 'short' , day : 'numeric' , month : 'short' , year : 'numeric' , hour : 'numeric' , minute : 'numeric' , } ; return date . toLocaleString ( lang , dateOptions ) ; } export async function asyncFilter < T > ( arr , callback ) { return ( await Promise . all ( arr . map ( async ( item ) => ( ( await callback ( item ) ) ? item : undefined ) ) ) ) . filter ( i => i !== undefined ) as T [ ] ; } export const sleep = ( timeout ) => new Promise ( resolve => setTimeout ( resolve , timeout ) ) ; export function noop ( ) { }