-
Notifications
You must be signed in to change notification settings - Fork 0
/
json-porter.d.ts
53 lines (53 loc) · 1.62 KB
/
json-porter.d.ts
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
49
50
51
52
53
/*****************************************************************************************************
* Description: Save a JavaScript object as a JSON file download, and import a JSON file to
* parse it to an object
* Author: Mark Gabriel
* Version: 1.0.2
* License: MIT
*****************************************************************************************************/
export default class JsonPorter<T> {
/**
* HTML Imput element
*/
private _inputFile;
/**
* Import promise resolve function
*/
private _importResolve;
/**
* Import promise reject function
*/
private _importReject;
/**
* Accepts a data object and a filename, this function
* serializes the object to a json string and then
* tells the browser to download a file with the given
* name and the json string as the contents of the file
* @param obj Object to serialize to json file
* @param filename name of file to generator and download
*/
export(obj: any, filename: string): void;
/**
* Opens a file selection dialog to import
* a JSON a file which will be parsed to an
* object expected to be of type T
*/
import(): Promise<T>;
/**
* Presents user with a file picker dialog
*/
private _selectImportFile;
/**
* File selection event handler
*/
private _onImportFile_select;
private _processFileContents;
/**
* Destroys file input element and resets json-porter
*/
private _cleanUp;
/**
* Returns true if browser is IE, otherwise false
*/
private _isIE;
}