forked from fuse-open/types
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
2392 lines (2277 loc) · 87.7 KB
/
index.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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* Allows you to encode and decode strings from Base64.
*
* This is useful when passing string to places where some characters are not allowed.
*
* This example demonstrates simple use of the `Base64` module. The code prints the input string, and the computed Base64 string.
*
* var Base64 = require("FuseJS/Base64");
* var string = "Hello, world!";
* console.log(string); //LOG: Hello, world!
* console.log(Base64.encodeAscii(string)); //LOG: SGVsbG8sIHdvcmxkIQ==
*/
declare module "FuseJS/Base64" {
/**
* Decodes the given base64 value to an ASCII string representation
*
* var Base64 = require("FuseJS/Base64");
* console.log(Base64.decodeAscii("SGVsbG8sIHdvcmxkIQ==")); //LOG: Hello, world!
*/
function decodeAscii(value: string): string;
/**
* Decodes the given base64 string to an ArrayBuffer.
*
* var Base64 = require("FuseJS/Base64");
* var buf = Base64.decodeBuffer("NxMAAA==");
* var view = new Int32Array(data);
* // Should print 0x1337
* console.log("0x" + view[0].toString(16));
*/
function decodeBuffer(base64String: string): ArrayBuffer;
/**
* Decodes the given base64 Latin-1 encoded bytes to a string.
*
* var Base64 = require("FuseJS/Base64");
* // Prints "hello world"
* console.log(Base64.decodeLatin1("aGVsbG8gd29ybGQ="));
*/
function decodeLatin1(stringToDecode: string): string;
/**
* Decodes the given base64 value to an UTF8 string representation
*
* var Base64 = require("FuseJS/Base64");
* console.log(Base64.encodeUtf8("Rm9vIMKpIGJhcg==")); //LOG: Foo ¸ bar
*/
function decodeUtf8(value: string): string;
/**
* Encodes the given ASCII value to base64 string representation
*
* var Base64 = require("FuseJS/Base64");
* console.log(Base64.encodeAscii("Hello, world!")); //LOG: SGVsbG8sIHdvcmxkIQ==
*/
function encodeAscii(value: string): string;
/**
* Encodes given array buffer to base64.
*
* var Base64 = require("FuseJS/Base64");
*
* var data = new ArrayBuffer(4);
* var view = new Int32Array(data);
* view[0] = 0x1337;
*
* console.log(Base64.encodeBuffer(data));
*/
function encodeBuffer(arrayBuffer: ArrayBuffer): string;
/**
* Encodes the given string to a Latin-1 base64 string.
*
* var Base64 = require("FuseJS/Base64");
* // Prints "aGVsbG8gd29ybGQ="
* console.log(Base64.encodeLatin1("hello world"));
*/
function encodeLatin1(stringToEncode: string): string;
/**
* Encodes the given UTF8 value to a base64 string representation
*
* var Base64 = require("FuseJS/Base64");
* console.log(Base64.encodeUtf8("Foo ¸ bar")); //LOG: Rm9vIMKpIGJhcg==
*/
function encodeUtf8(value: string): string;
}
/**
* The bundle API allows you to read files that is bundled with the application, defined in the project file (using `<filename>:Bundle`).
*
* ```
* var Bundle = require("FuseJS/Bundle");
* ```
*
* You can read up on bundling files [here](/docs/assets/bundle)
*/
declare module "FuseJS/Bundle" {
/**
* Asynchronously reads a file from the application bundle and writes it to a destination on the device.
* Use with `FuseJS/FileSystem` to determine destination paths. This is useful for extracting html and associated content for local use with WebView via `file://` protocol.
*
* ```
* var Bundle = require("FuseJS/Bundle");
* var FileSystem = require("FuseJS/FileSystem");
* var Observable = require("FuseJS/Observable");
* var urlForWebView = Observable();
*
* Bundle.extract("assets/site/page.html", FileSystem.dataDirectory + "site/page.html").then(function(resultPath) {
* urlForWebView.value = "file://" + resultPath;
* });
* ```
*/
function extract(bundleFilePath: string, destinationPath: string): Promise<string>;
/**
* Fetch a list of every file bundled with the application.
*
* ```
* var Bundle = require("FuseJS/Bundle");
*
* Bundle.list().then(function(list) {
* //list is an array of paths, such as "assets/image.jpg"
* });
* ```
*/
function list(): Promise<string[]>;
/**
* Asynchronously reads a file from the application bundle
*
* ```
* var Bundle = require("FuseJS/Bundle");
*
* Bundle.read("someData.json").then(function(contents) {
* console.log(contents);
* }, function(error) {
* console.log("Error!", error);
* });
* ```
*/
function read(filename: string): Promise<string>;
/**
* Read a bundled file as an ArrayBuffer of bytes
*
* ```
* var Observable = require("FuseJS/Observable");
* var Bundle = require("FuseJS/Bundle");
* var ImageTools = require("FuseJS/ImageTools");
* var imageUrlToDisplay = Observable();
*
* Bundle.readBuffer("assets/image.jpg").then(function(buffer) {
* //Do something with the image data here
* });
* ```
*/
function readBuffer(bundlePath: string): Promise<ArrayBuffer>;
/**
* Synchronously reads a file from the application bundle
*
* ```
* var Bundle = require("FuseJS/Bundle");
*
* var contents = Bundle.readSync("someData.json");
* console.log(contents);
* ```
*
* > Warning: This call will block until the operation is finished. If you are reading large amounts of data, use read() instead.
*/
function readSync(filename: string): string;
}
/**
* The Environment API allows you to check which platform your app is currently running on.
*
* You need to add a reference to `"FuseJS"` in your project file to use this feature.
*
* ## Examples
*
* You can check which platform your app is running on using the following boolean properties:
*
* var Environment = require('FuseJS/Environment');
*
* if(Environment.ios) console.log("Running on iOS");
* if(Environment.android) console.log("Running on Android");
* if(Environment.preview) console.log("Running in preview mode");
* if(Environment.mobile) console.log("Running on iOS or Android");
* if(Environment.desktop) console.log("Running on desktop");
*
* You can also get the version of the current *mobile* OS as a
* human-readable string using the `mobileOSVersion` property.
*
* console.log(Environment.mobileOSVersion);
*
* > *Note*
* >
* > On Android, `mobileOSVersion` returns [Build.VERSION.RELEASE](https://developer.android.com/reference/android/os/Build.VERSION.html#RELEASE)
* > (e.g. `1.0` or `3.4b5`).
* > On iOS, it returns a string in the format of `<major>.<minor>.<patch>`
* > (e.g. `9.2.1`).
* > Returns an empty string on all other platforms.
*/
declare module "FuseJS/Environment" {
const ios: boolean;
const android: boolean;
const preview: boolean;
const mobile: boolean;
const desktop: boolean;
/**
* A user-readable OS version number.On Android, it returns [Build.VERSION.RELEASE](https://developer.android.com/reference/android/os/Build.VERSION.html#RELEASE)
* (e.g. `1.0` or `3.4b5`).
* On iOS, it returns a string in the format of `<major>.<minor>.<patch>` (e.g. `9.2.1`).
* Returns an empty string on all other platforms.
*/
const mobileOSVersion: string;
}
/**
* Monitor the application lifecycle from JS
*
* The lifecycle of an app is the time from when your app starts to the time it terminates.
* During this time the app will go through a number of states.
*
* The Lifecycle module allows you query the current state and also be alerted when the
* app changes state.
*
* ## The States
*
* - Starting
* - Background
* - Foreground
* - Interactive
*
* ### Starting
* Your app start event is implicit, as this is when your JavaScript is first evaluated.
*
* ### Background
* Your app is not the app the user is interactive with right now and so the operating system
* has put it into a 'sleep' state.
*
* Whilst your app is in this state is is not allowed to run code, but you don't have to worry
* about this as Fuse will ensure your JS/UX is not doing something when it shouldn't.
*
* ### Foreground
* Your app is front and center on the user's device but they cannot yet interact with it. The
* main reason to be in this state is that the user has opened the notification bar on iOS or
* Android.
*
* ### Interactive
* Your app is now in the foreground and is accepting input from the user.
*
* ## Changing States
* It would be hard to work with app lifecycle if your app could just jump around the states
* randomly. Instead we guarentee the following flow through the states:
*
* Starting
*
* Background ? Foreground ? Interactive
*
* Terminating
*
* ## No `terminating` event
* You may be wondering why there is no `terminating` event. The reason is that on mobile
* platforms the OS doesn't promise to call you when terminating your app. It may, but in
* certain circumstances (low memory, emergency phone call, etc) it won't.
*
* Because of this the guides for mobile platforms strongly advise against using the `terminating`
* event as a cue that the app is shutting down, instead you should be regularly 'checkpointing'
* your app so you can recover from any kind of shutdown.
*
* Given that we are not meant to use it, we have opted not to expose the event.
*
* This module is an @EventEmitter, so the methods from @EventEmitter can be used to listen to events.
*
* ## Example
*
* <JavaScript>
* var Lifecycle = require('FuseJS/Lifecycle');
*
* Lifecycle.on("enteringForeground", function() {
* console.log("on enteringForeground");
* });
* Lifecycle.on("enteringInteractive", function() {
* console.log("on enteringInteractive");
* });
* Lifecycle.on("exitedInteractive", function() {
* console.log("on exitedInteractive");
* });
* Lifecycle.on("enteringBackground", function() {
* console.log("on enteringBackground");
* });
* Lifecycle.on("stateChanged", function(newState) {
* console.log("on stateChanged " + newState);
* });
* module.exports = { lifecycleState: Lifecycle.observe("stateChanged") }
* </JavaScript>
* <StackPanel>
* <Text TextWrapping="Wrap">Open the Fuse Monitor to see the logs</Text>
* <Text>Current lifecycle state:</Text>
* <Text Value="{lifecycleState}" />
* </StackPanel>
*
* In the above example we're using the @EventEmitter `on` method to listen to the different events.
* We're also using the @EventEmitter `observe` method on the `"stateChanged"` event to get an @Observable containing the current state.
*/
declare module "FuseJS/Lifecycle" {
const BACKGROUND: number;
const FOREGROUND: number;
const INTERACTIVE: number;
/**
* Will give you the current state as an integer
*
* var Lifecycle = require("FuseJS/Lifecycle");
*
* console.log(Lifecycle.state === Lifecycle.BACKGROUND);
* console.log(Lifecycle.state === Lifecycle.FOREGROUND);
* console.log(Lifecycle.state === Lifecycle.INTERACTIVE);
*/
const state: number;
type Event = "enteringBackground" |
"enteringForeground" |
"enteringInteractive" |
"exitedInteractive" |
"stateChanged";
/**
* Registers a function to be called when one of the following events occur.
*
* * `"enteringBackground"` - Triggered when the app is leaving the running state and is about to be suspended.
* * `"enteringForeground"` - Triggered when the app has left the suspended state and now is running.
* You will receive this event when the app starts.
* * `"enteringInteractive"` - Triggered when the app is entering a state where it is fully focused and receiving events.
* * `"exitedInteractive"` - Triggered when the app is partially obscured or is no longer the focus (e.g. when you drag open the notification bar)
* * `"stateChanged"` - Triggered when the app's lifecycle state has changed.
*/
function on(event: Event, callback: () => void): void;
}
/**
* Allows the capture of still images from the system camera.
*
* Images are returned as frozen JavaScript Image objects, consisting of a path, a filename, a width and a height.
* Once created or acquired, Images can be passed around to other APIs to use, fetch or alter their underlying data.
* All images are temporary "scratch images" until storage has been specified either through publishing to the CameraRoll or other.
*
* You need to add a reference to `"Fuse.Camera"` in your project file to use this feature.
*
* On Android using this API will request the CAMERA and WRITE_EXTERNAL_STORAGE permissions.
*
* ## Example
*
* var camera = require('FuseJS/Camera');
* camera.takePicture(640,480).then(function(image)
* {
* //Do things with image here
* }).catch(function(error) {
* //Something went wrong, see error for details
* });
*/
declare module "FuseJS/Camera" {
/**
* Checks if device has permissions to access the camera.
*/
function checkPermissions(): boolean;
/**
* Requests acccess to the camera
*/
function requestPermissions(): boolean;
/**
* Starts an OS-specific image capture view and returns a Promise of the resulting Image.
*
* If the desiredWidth and height parameters are set, returns an Image scaled as close to the specified
* width/height as possible while maintaining aspect ratio.
*
* If no size parameters are given, the taken image will be full-sized as determined by the device camera.
*
* The image capture view is user-configurable on Android.
*/
function takePicture(desiredWidth?: number, desiredHeight?: number): Promise<any>;
}
/**
* Allows adding images to- and fetching images from the system image gallery.
*
* Fuse represents images as frozen JavaScript Image objects, consisting of a path, a filename, a width and a height.
* Once created or acquired, Images can be passed around to other APIs to use, fetch or alter their underlying data.
* All images are temporary "scratch images" until storage has been specified either through publishing to the CameraRoll or other.
*
* Using this API on Android will request the `WRITE_EXTERNAL_STORAGE` and `READ_EXTERNAL_STORAGE` permissions.
*
* > **Note:** You need to add a package reference to `Fuse.CameraRoll` to use this API.
*
* ## Examples
*
* Requesting an image from the camera roll:
*
* var cameraRoll = require("FuseJS/CameraRoll");
*
* cameraRoll.getImage()
* .then(function(image) {
* // Will be called if the user successfully selected an image.
* }, function(error) {
* // Will be called if the user aborted the selection or if an error occurred.
* });
*
* Taking a picture with the camera and adding it to the camera roll:
*
* var cameraRoll = require("FuseJS/CameraRoll");
* var camera = require("FuseJS/Camera");
*
* camera.takePicture(640, 480)
* .then(function(image) {
* return cameraRoll.publishImage(image);
* })
* .then(function() {
* // Will be called if the image was successfully added to the camera roll.
* }, function(error) {
* // Will called if an error occurred.
* });
*
* > **Note**: You also need to add a package reference to `Fuse.Camera` for the above example to work.
*/
declare module "FuseJS/CameraRoll" {
/**
* Adds a copy of the Image instance to the system camera roll.
*
* On Android this is done by copying the image to the application's public image
* storage directory and notifying the media scanner.
*
* On iOS this is done by uploading a copy of the image to an asset collection
* named after the application within the system photo library.
*/
function publishImage(image: any): void;
/**
* Checks if device has permissions to access the camera roll.
*/
function checkPermissions(): boolean;
/**
* Requests acccess to photo gallery
*/
function requestPermissions(): boolean;
/**
* Starts an OS-specific image picker view (user-configurable on Android).
*/
function getImage(): Promise<any>;
}
/**
* Provides an interface to the file system.
*
* var FileSystem = require("FuseJS/FileSystem");
*
* Using the asynchronous Promise based functions is recommended to keep your UI responsive,
* although synchronous variants are also available if preferred.
*
* When saving files private to the application you can use the `dataDirectory` property
* as a base path.
*
* ## Example
*
* This example writes a text to a file, and then reads it back:
*
* var FileSystem = require("FuseJS/FileSystem");
* var path = FileSystem.dataDirectory + "/" + "testfile.tmp";
*
* FileSystem.writeTextToFile(path, "hello world")
* .then(function() {
* return FileSystem.readTextFromFile(path);
* })
* .then(function(text) {
* console.log("The read file content was: " + text);
* })
* .catch(function(error) {
* console.log("Unable to read file due to error:" + error);
* });
*/
declare module "FuseJS/FileSystem" {
interface AndroidPaths {
externalCache: string;
externalFiles: string;
cache: string;
files: string;
}
/**
* An object containing paths only exposed on Android devices:
*
* * `externalCache` - The directory acquired by calling `Context.getExternalCacheDir()`
* * `externalFiles` - The directory acquired by calling `Context.getExternalFilesDir(null)`
* * `cache` - The directory acquired by calling `Context.getCacheDir()`
* * `files` - The directory acquired by calling `Context.getFilesDir()`
*/
const androidPaths: AndroidPaths;
/**
* A directory to put cached files.
*
* Note that files in this directory might be automatically removed when space is low, depending on platform.
*/
const cacheDirectory: string;
/**
* A directory to put data files that are private to the application.
*
* * iOS - The Library directory for the application.
* * Android - The directory acquired by calling `Context.getFilesDir()`
* * Local preview - `<project dir>/build/Local/Preview/fs_data`
*
* Note that cleaning or rebuilding your project will delete this directory.
*/
const dataDirectory: string;
interface IosPaths {
documents: string;
library: string;
caches: string;
temp: string;
}
/**
* An object containing paths only exposed on iOS devices:
*
* * `documents` - Mapped to `NSDocumentDirectory`
* * `library` - Mapped to `NSLibraryDirectory`
* * `caches` - Mapped to `NSCachesDirectory`
* * `temp` - Mapped to `NSTemporaryDirectory`
*/
const iosPaths: IosPaths;
/**
* Asynchronously appends a string to a UTF-8 encoded file.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.appendTextToFile(FileSystem.dataDirectory + "/" + "myfile.txt", "Hello buddy")
* .then(function() {
* console.log("Successful append");
* }, function(error) {
* console.log(error);
* });
*/
function appendTextToFile(filename: string, contents: string): Promise<void>;
/**
* Synchronously appends a string to a UTF-8 encoded file.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.appendTextToFileSync("myfile.txt", "Hello buddy");
*/
function appendTextToFileSync(filename: string, contents: string): void;
/**
* Asynchronously copies a file or directory recursively from source to destination path
*
* ## Example
*
* FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.writeTextToFile("to-be-copied.txt", "hello world")
* .then(function() {
* return FileSystem.copy("to-be-copied.txt", "destination-reached.txt");
* })
* .catch(function(err) {
* console.log("Unable to copy file");
* });
*/
function copy(source: string, destination: string): Promise<void>;
/**
* Synchronously copies a file or directory recursively from source to destination path
*
* ## Example
*
* FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.writeTextToFileSync("to-be-copied.txt", "hello world");
* FileSystem.copySync("to-be-copied.txt", "destination-reached.txt");
*/
function copySync(source: string, destination: string): void;
/**
* Asynchronously creates a directory.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.createDirectory(FileSystem.dataDirectory + "/" + "new-directory")
* .then(function() {
* console.log("Directory created!");
* }, function(error) {
* console.log("Error trying to create directory.");
* });
*/
function createDirectory(path: string): Promise<void>;
/**
* Synchronously creates a directory.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.createDirectory(FileSystem.dataDirectory + "/" + "new-directory");
*/
function createDirectorySync(path: string): void;
/**
* Asynchronously delete a file.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.remove("myfile.txt")
* .then(function() {
* console.log("Delete succeeded");
* }, function(error) {
* console.log("Unable to delete file");
* });
*/
function remove(path: string): Promise<void>;
/**
* Synchronously delete a file.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.removeSync("myfile.txt");
*/
function removeSync(path: string): void;
/**
* Asynchronously check if a file exists.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.exists("myfile.txt")
* .then(function(x) {
* console.log(x ? "it's there! =)" : "it's missing :/");
* }, function(error) {
* console.log("Unable to check if file exists");
* });
*/
function exists(path: string): Promise<boolean>;
/**
* Synchronously check if a file exists.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* console.log(FileSystem.existsSync("myfile.txt") ? "It's there!" : "It's missing :/");
*/
function existsSync(path: string): boolean;
interface DirectoryInfo {
exists: boolean;
lastWriteTime: Date;
lastAccessTime: Date;
}
/**
* Asynchronously gets info about a directory.
*
* The returned object has the following properties:
*
* * `exists` - a boolean value stating whether the directory exists or not.
* * `lastWriteTime` - A `Date` stating when directory was last changed
* * `lastAccessTime` - A `Date` stating when directory was accessed
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.createDirectorySync("some-dir");
* FileSystem.getDirectoryInfo("some-dir")
* .then(function(dirInfo) {
* console.log("Directory was modified on " + dirInfo.lastWriteTime);
* })
* .catch(function(error) {
* console.log("Failed to get directory info " + error);
* });
*/
function getDirectoryInfo(path: string): Promise<DirectoryInfo>;
/**
* Synchronously gets info about a directory.
*
* The returned object has the following properties:
*
* * `exists` - A boolean value stating whether the directory exists
* * `lastWriteTime` - A `Date` stating when directory was last changed
* * `lastAccessTime` - A `Date` stating when directory was accessed
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.createDirectorySync("some-dir");
* var dirInfo = FileSystem.getDirectoryInfoSync("some-dir");
* console.log("file was modified on " + dirInfo.lastWriteTime);
*/
function getDirectoryInfoSync(path: string): DirectoryInfo;
interface FileInfo {
size: number;
exists: boolean;
lastWriteTime: Date;
lastAccessTime: Date;
}
/**
* Asynchronously gets info about a file.
*
* The returned object has the following properties:
*
* * `size` - size of file
* * `exists` - a boolean value stating whether file exists
* * `lastWriteTime` - A `Date` stating when file was last changed
* * `lastAccessTime` - A `Date` stating when file was accessed
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.writeTextToFileSync("some-file.txt", "hello there");
* FileSystem.getFileInfo("some-file.txt")
* .then(function(fileInfo) {
* console.log("file was modified on " + fileInfo.lastWriteTime);
* })
* .catch(function(error) {
* "failed stat " + error
* });
*/
function getFileInfo(path: string): Promise<FileInfo>;
/**
* Synchronously gets info about a file.
*
* The returned object has the following properties:
*
* * `exists` - a boolean value stating whether file exists
* * `lastWriteTime` - A `Date` stating when file was last changed
* * `lastAccessTime` - A `Date` stating when file was accessed
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.writeTextToFileSync("some-file.txt", "hello there");
* var fileInfo = FileSystem.getFileInfoSync("some-file.txt");
* console.log("file was modified on " + fileInfo.lastWriteTime);
*/
function getFileInfoSync(path: string): FileInfo;
/**
* Asynchronously list subdirectories in a directory.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.listDirectories(FileSystem.dataDirectory)
* .then(function(directories) {
* console.log("There are " + directories.length + " subdirectories in directory")
* }, function(error) {
* console.log("Unable to list subdirectories of directory: " + error);
* });
*/
function listDirectories(path: string): Promise<string[]>;
/**
* Synchronously list subdirectories in a directory.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* var directories = FileSystem.listDirectoriesSync(FileSystem.dataDirectory);
* console.log("There are " + directories.length + " subdirectories in directory");
*/
function listDirectoriesSync(path: string): string[];
/**
* Asynchronously lists both files and subdirectories in a directory.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.listEntries(FileSystem.dataDirectory)
* .then(function(entries) {
* console.log("There are " + entries.length + " entries in directory")
* }, function(error) {
* console.log("Unable to list entries in directory due to error " + error);
* });
*/
function listEntries(path: string): Promise<string[]>;
/**
* Synchronously lists both files and subdirectories in a directory.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* var entries = FileSystem.listEntriesSync(FileSystem.dataDirectory);
* console.log("There are " + entries.length + " entries in directory");
*/
function listEntriesSync(path: string): string[];
/**
* Asynchronously list files in directory.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.listFiles(FileSystem.dataDirectory)
* .then(function(files) {
* console.log("There are " + files.length + " files in directory")
* }, function(error) {
* console.log("Unable to list files in directory due to error " + error);
* });
*/
function listFiles(path: string): Promise<string[]>;
/**
* Synchronously list files in directory.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* var files = FileSystem.listFilesSync(FileSystem.dataDirectory);
* console.log("There are " + files.length + " files in directory");
*/
function listFilesSync(path: string): string[];
/**
* Asynchronously moves a file or directory from source to destination path
*
* ## Example
*
* FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.writeTextToFile("to-be-moved.txt", "hello world")
* .then(function() {
* return FileSystem.move("to-be-moved.txt", "destination-reached.txt");
* })
* .catch(function(err) {
* console.log("Unable to move file");
* });
*/
function move(source: string, destination: string): Promise<void>;
/**
* Synchronously moves a file or directory from source to destination path
*
* ## Example
*
* FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.writeTextToFileSync("to-be-moved.txt", "hello world");
* FileSystem.moveSync("to-be-moved.txt", "destination-reached.txt");
*/
function moveSync(source: string, destination: string): Promise<void>;
/**
* Asynchronously reads a file and returns a Promise of an ArrayBuffer with its contents.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.readBufferFromFile("myfile.txt")
* .then(function(contents) {
* console.log(contents);
* }, function(error) {
* console.log(error);
* });
*/
function readBufferFromFile(filename: string): Promise<ArrayBuffer>;
/**
* Synchronously reads a file and returns an ArrayBuffer with its contents.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* var data = FileSystem.readBufferFromFileSync("myfile.txt");
*/
function readBufferFromFileSync(filename: string): ArrayBuffer;
/**
* Asynchronously reads a file and returns a Promise of its contents.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.readTextFromFile("myfile.txt")
* .then(function(contents) {
* console.log(contents);
* }, function(error) {
* console.log(error);
* });
*/
function readTextFromFile(filename: string): Promise<string>;
/**
* Synchronously reads a file and returns its contents as a string.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* var content = FileSystem.readTextFromFileSync(FileSystem.dataDirectory + "/" + "myfile.txt");
* console.log("The file contains " + content));
*/
function readTextFromFileSync(filename: string): string;
/**
* Asynchronously writes an `ArrayBuffer` to a file.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* var data = new ArrayBuffer(4);
* var view = new Int32Array(data);
* view[0] = 0x1337;
*
* FileSystem.writeBufferToFile(FileSystem.dataDirectory + "/" + "myfile.txt", data)
* .then(function() {
* console.log("Successful write");
* }, function(error) {
* console.log(error);
* });
*/
function writeBufferToFile(filename: string, data: ArrayBuffer): Promise<void>;
/**
* Synchronously writes an `ArrayBuffer` to a file.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* var data = new ArrayBuffer(4);
* var view = new Int32Array(data);
* view[0] = 0x1337;
*
* FileSystem.writeBufferToFileSync(FileSystem.dataDirectory + "/" + "myfile.txt", data);
*/
function writeBufferToFileSync(filename: string, data: ArrayBuffer): void;
/**
* Asynchronously writes a string to a UTF-8 encoded file.
*
* ## Example
*
* var FileSystem = require("FuseJS/FileSystem");
*
* FileSystem.writeTextToFile(FileSystem.dataDirectory + "/" + "myfile.txt", "Hello buddy")
* .then(function() {
* console.log("Successful write");
* }, function(error) {
* console.log(error);
* });
*/
function writeTextToFile(filename: string, text: string): Promise<void>;
/**
* Synchronously writes a string to a UTF-8 encoded file.
*
* ## Example
*