/
folder.d.ts
253 lines (251 loc) · 7.82 KB
/
folder.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
///<reference path="./file.d.ts" />
interface Folder {
/**
* References a folder.
* The folder does not have to exist.
*
* #### Example 1: Get a reference to an existing folder
* ```javascript
* var myFolder = new Folder( 'PROJECT' );
* console.log( myFolder.exists );
* // true
* ```
*
* #### Example 2: Get a reference to a missing folder
* ```javascript
* var myFolder = new Folder( 'PROJECT/missing-folder' );
* console.log( myFolder.exists );
* // false
* ```
*
* @param path Absolute path of the folder to reference.
*/
new (path: String): WAKFolderInstance;
/**
* Check if the path references a folder.
*
* ```javascript
* var myIsFolder = Folder.isFolder( 'PROJECT' );
* console.log( myIsFolder );
* // true
* ```
*
* @param path Absolute path to a folder
* @returns `true` is the path references a folder, `false` otherwise.
*/
isFolder(path: String): Boolean;
}
interface WAKFolderInstance {
/**
* Creation date for the folder.
*/
readonly creationDate: Date;
/**
* `true` if the folder exists at the defined path, `false` otherwise.
*/
readonly exists: Boolean;
/**
* Folder extension.
*/
readonly extension: String;
/**
* Array of Files.
*/
readonly files: Array<WAKFileInstance>;
// /**
// *FileSystem of the object.
// */
// filesystem: FileSystemSync;
/**
* First file found in the folder.
*/
readonly firstFile: WAKFileInstance;
/**
* First folder (i.e., subfolder) in the folder.
*/
readonly firstFolder: WAKFolderInstance;
/**
* Array of Folder objects.
*/
folders: Array<WAKFolderInstance>;
/**
* Last modification date for the folder.
*/
readonly modificationDate: Date;
/**
* Name of the folder without the path.
*/
readonly name: String;
/**
* Name of the folder without the extension.
*/
readonly nameNoExt: String;
/**
* Parent folder of the folder.
*/
readonly parent: WAKFolderInstance;
/**
* Full path of the folder.
*/
readonly path: String;
/**
* `true` if the folder is visible, `false` otherwise.
*/
readonly visible: Boolean;
/**
* Creates a new folder on disk.
*
* ```javascript
* var myFolder = new Folder( 'PROJECT/my-created-folder' );
* var myResult = myFolder.create();
* console.log( myResult );
* // true
* ```
*
* @throws An error if something goes wrong: folder already exists, invalid path, ...
* @returns `true` if the folder is well created
*/
create(): Boolean;
/**
* Calls `callback` function for each file at the first level of the folder.
*
* #### Example 1: Basic usage
* ```javascript
* var folder = new Folder( 'PROJECT/' );
* folder.forEachFile( function( file )
* {
* console.log( file.path );
* });
* ```
*
* #### Example 2: Override `this`
* ```javascript
* var folder = new Folder( 'PROJECT/' );
* folder.forEachFile( function( file )
* {
* console.log( this );
* }, {data: 'some-data' } );
* // {"data":"some-data"}
* ```
*
* @warning `break` is not working in `forEachFile`
* @param callback Defines the function called for each file
* @param callback.file Current file being processed
* @param thisArg Defines `this` value of the callback
*/
forEachFile(callback: (file: WAKFileInstance) => void, thisArg?: Object): void;
/**
* Calls `callback` function for each folder at the first level of the folder.
*
* #### Example 1: Basic usage
* ```javascript
* var folder = new Folder( 'PROJECT/' );
* folder.forEachFolder( function( folder )
* {
* console.log( folder.path );
* });
* ```
*
* #### Example 2: Override `this`
* ```javascript
* var folder = new Folder( 'PROJECT/' );
* folder.forEachFolder( function( folder )
* {
* console.log( this );
* }, {data: 'some-data' } );
* // {"data":"some-data"}
* ```
*
* @warning `break` is not working in `forEachFolder`
* @param callback Defines the function called for each folder
* @param callback.folder Current folder being processed
* @param thisArg Defines `this` value of the callback
*/
forEachFolder(callback: (folder: WAKFolderInstance) => void, thisArg?: Object): void;
/**
* Returns the size of the free space (expressed in bytes) available on the volume where the Folder object is stored.
* @param quotas (default: `true`) `true` if consider the whole volume, `false` if consider only the allowed size for the quota
*/
getFreeSpace(quotas?: Boolean): Number;
/**
* Returns the absolute URL of the Folder object.
* @param encoding (default: `false`) `true` if encode the url, `false` otherwise.
*/
getURL(encoding?: Boolean): String;
/**
* Returns the total size (expressed in bytes) of the volume where the Folder object is stored.
*/
getVolumeSize(): Number;
// /**
// *puts the folder pointer on the next subfolder in an iteration of subfolders.
// */
// next() : Boolean;
/**
* Calls `callback` function for each file in the folder tree (first-level and sub-level folder).
*
* #### Example 1: Basic usage
* ```javascript
* var folder = new Folder( 'PROJECT/' );
* folder.parse( function( file, position, folder )
* {
* console.log( '-----------------------------' );
* console.log( file.path );
* console.log( position );
* console.log( folder.path );
* });
* ```
*
* #### Example 2: Override `this`
* ```javascript
* var folder = new Folder( 'PROJECT/' );
* folder.parse( function( file, position, folder )
* {
* console.log( this );
* }, {data: 'some-data' } );
* // {"data":"some-data"}
* ```
*
* @warning `break` is not working in `parse`
* @param callback Defines the function called for each folder
* @param thisArg Defines `this` value of the callback
* @param callback.file Current processed file
* @param callback.position Position of the file currently being processed
* @param callback.folder Folder of the processed file
*/
parse(callback: (file: WAKFileInstance, position: Number, folder: WAKFolderInstance) => void, thisArg?: Object): void;
/**
* Removes the folder and its content from the disk.
* @returns `true` if the folder is not here, `false` otherwise.
*/
remove(): Boolean;
/**
* Removes the contents of the folder from the disk.
*/
removeContent(): Boolean;
/**
* Rename the folder on disk.
*
* ```javascript
* var myFolder = new Folder( 'PROJECT/my-folder' );
* // The folder must exists to be renamed
* myFolder.create();
* // The destination folder name must be free
* myFolder.setName( 'my-renamed-folder' );
* // myFolder always references the "my-folder" folder
* // The referenced folder did not change with the setName() action.
* console.log( myFolder.path );
* // PROJECT/my-folder
* ```
*
* @warning The folder must exist on disk to be renamed
* @warning The folder destination must be free
* @param name New folder name
* @returns `true` if the folder is successfully renamed
* @throws An error if something goes wrong: folder already exists, invalid name, ...
*/
setName(newName: String): void;
// /**
// *checks the validity of the pointer to the current folder within an iteration of folders
// */
// valid() : Boolean;
}