import * as del from 'del' ; import { Collection } from 'lokijs' ; const imageFilter = function ( req , file , cb ) { if ( ! file . originalname . match ( /\.(jpg|jpeg|png|gif)$/ ) ) { return cb ( new Error ( 'Only image files are allowed!' ) , false ) ; } cb ( null , true ) ; } ; const loadCollection = function ( colName , db ) : Promise < Collection < any > > { return new Promise ( resolve => { db . loadDatabase ( { } , ( ) => { const _collection = db . getCollection ( colName ) || db . addCollection ( colName ) ; resolve ( _collection ) ; } ) ; } ) ; } ; const cleanFolder = function ( folderPath ) { del . sync ( [ `${ folderPath }/**` , `!${ folderPath }` ] ) ; } ; export { imageFilter , loadCollection , cleanFolder } ;