-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.ts
More file actions
48 lines (28 loc) · 1.02 KB
/
index.ts
File metadata and controls
48 lines (28 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/* IMPORT */
import {Source, Options} from './types';
import {Boostnote, Enex, HTML, Markdown} from './providers';
import Utils from './utils';
/* DUMPER */
const Dumper = {
providers: [
Boostnote,
Enex,
HTML,
Markdown
],
isSupported ( source: Source ): boolean {
return !!Dumper.providers.find ( provider => provider.isSupported ( source ) );
},
async dump ( options: Options ): Promise<void> {
const sources = Utils.lang.castArray ( options.source ),
sourcesUnsupported = sources.filter ( source => !Dumper.isSupported ( source ) );
if ( sourcesUnsupported.length ) throw new Error ( `These sources are not supported: ${sourcesUnsupported.join ( ', ' )}` );
for ( const source of sources ) {
const provider = Dumper.providers.find ( provider => provider.isSupported ( source ) );
if ( !provider ) throw new Error ( `This source is not supported: ${source}` );
await provider.dump ( source, options.dump );
}
}
};
/* EXPORT */
export default Dumper;