import * as path from 'path' ; import sanitize from 'sanitize-filename' ; import { Constants } from './constants' ; export class Utils { public static async sleep ( milliseconds ) { return new Promise < void > ( resolve => setTimeout ( resolve , milliseconds ) ) ; } public static caseInsensitiveNameSort ( object1 , object2 ) { return object1 . name . toLowerCase ( ) . localeCompare ( object2 . name . toLowerCase ( ) ) ; } public static containsAny ( text , items ) { for ( let i = 0 ; i < items . length ; i ++ ) { const item = items [ i ] . toLowerCase ( ) ; if ( text . toLowerCase ( ) . indexOf ( item ) > - 1 ) { return true ; } } return false ; } public static containsAll ( text , items ) { for ( let i = 0 ; i < items . length ; i ++ ) { const item = items [ i ] . toLowerCase ( ) ; if ( text . toLowerCase ( ) . indexOf ( item ) < 0 ) { return false ; } } return true ; } public static pathToCollection ( collectionDirectoryPath ) { return path . dirname ( collectionDirectoryPath ) . split ( path . sep ) . pop ( ) ; } public static collectionToPath ( storageDirectory , collection ) { return path . join ( storageDirectory , collection ) ; } public static getNoteExportPath ( exportDirectory , noteTitle ) { return path . join ( exportDirectory , `${ sanitize ( noteTitle ) }${ Constants . noteExportExtension }` ) ; } public static getPdfExportPath ( exportDirectory , noteTitle ) { return path . join ( exportDirectory , `${ sanitize ( noteTitle ) }.pdf` ) ; } }