@signageos/front-applet 8.5.1 → 8.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,19 +1,49 @@
1
1
  ---
2
- sidebar_position: 0
2
+ sidebar_position: 99
3
3
  ---
4
4
 
5
5
  # fpath
6
6
 
7
+ `fpath` utility mirrors node [path](https://nodejs.org/docs/latest/api/path.html)
8
+ module, but accepts IFilePath type instead of strings. It is useful when
9
+ working with [sos.fileSystem](/sdk/sos/fileSystem).
10
+
11
+ :::info Not implemented functions:
12
+ - `format()`
13
+ - `matchesGlob()`
14
+ - `parse()`
15
+ - `relative()`
16
+ :::
17
+
18
+ ```ts
19
+ import { sos, fpath } from "@signageos/front-applet";
20
+
21
+ const [internal] = await sos.fileSystem.listInternalStorageUnits();
22
+ const rootPath = {
23
+ filePath: '', // Empty string is used as an absolute path instead of "/"
24
+ storageUnit: internal
25
+ };
26
+
27
+ // list saved files in videos/2025-05-19/ directory
28
+ const videos = await sos.fileSystem.listFiles(
29
+ fpath.join(rootPath, "videos", "2025-05-19"),
30
+ );
31
+ ```
32
+
7
33
  ## Properties
8
34
 
9
35
  ### path
10
36
 
37
+ Underlying path polyfill
38
+
11
39
  ```ts expandable
12
- path: import("path-browserify").Path;
40
+ path: path.Path;
13
41
  ```
14
42
 
15
43
  ### sep
16
44
 
45
+ Separator used for joining path segments
46
+
17
47
  ```ts expandable
18
48
  sep: string;
19
49
  ```
@@ -22,78 +52,658 @@ sep: string;
22
52
 
23
53
  ### basename()
24
54
 
55
+ Return the last portion of path, since it is not a valid path, a string is returned.
56
+
25
57
  ```ts expandable
26
- basename(filePath: import("./FrontApplet/FileSystem/types").IFilePath, suffix?: string): string;
58
+ basename(filePath: IFilePath, suffix?: string): string;
59
+ // show-more
60
+ /**
61
+ * Base File System interface for methods.
62
+ */
63
+ interface IFilePath {
64
+ /**
65
+ * Storage unit which is selected for performing file operations.
66
+ */
67
+ storageUnit: IStorageUnit;
68
+ /**
69
+ * File path within the storage unit.
70
+ */
71
+ filePath: string;
72
+ }
73
+
74
+ /**
75
+ * File System Storage Unit returned by the File System API.
76
+ */
77
+ interface IStorageUnit {
78
+ /**
79
+ * The type of the storage unit, e.g., "internal" or "external".
80
+ */
81
+ type: string;
82
+ /**
83
+ * The total capacity of the storage unit in bytes.
84
+ */
85
+ capacity: number;
86
+ /**
87
+ * The amount of free space available in the storage unit in bytes.
88
+ */
89
+ freeSpace: number;
90
+ /**
91
+ * The amount of usable space in the storage unit in bytes.
92
+ */
93
+ usableSpace: number;
94
+ /**
95
+ * Indicates whether the storage unit is removable (e.g., an SD card).
96
+ */
97
+ removable: boolean;
98
+ }
99
+
100
+ ```
101
+
102
+ #### Params
103
+
104
+ | Name | Type | Required | Description |
105
+ |------------|-------------|------------------|-----------------------------------------------|
106
+ | `filePath` | `IFilePath` | <div>Yes</div> | The file path to extract the base name from. |
107
+ | `suffix` | `string` | <div>No</div> | An optional suffix to remove from the result. |
108
+
109
+ #### Return value
110
+
111
+ The last portion of path, with suffix removed if it is provided and present in the path.
112
+
113
+ #### Example
114
+
115
+ ```ts
116
+ const path = { filePath: "images/picture.png", storageUnit: ... };
117
+ fpath.basename(path); // "picture.png"
27
118
  ```
28
119
 
29
120
  <Separator />
30
121
 
31
122
  ### concat()
32
123
 
124
+ Concatenate filePath with paths without adding separator.
125
+
33
126
  ```ts expandable
34
- concat(filePath: import("./FrontApplet/FileSystem/types").IFilePath, ...paths: string[]): import("./FrontApplet/FileSystem/types").IFilePath;
127
+ concat(filePath: IFilePath, ...paths: string[]): IFilePath;
128
+ // show-more
129
+ /**
130
+ * Base File System interface for methods.
131
+ */
132
+ interface IFilePath {
133
+ /**
134
+ * Storage unit which is selected for performing file operations.
135
+ */
136
+ storageUnit: IStorageUnit;
137
+ /**
138
+ * File path within the storage unit.
139
+ */
140
+ filePath: string;
141
+ }
142
+
143
+ /**
144
+ * File System Storage Unit returned by the File System API.
145
+ */
146
+ interface IStorageUnit {
147
+ /**
148
+ * The type of the storage unit, e.g., "internal" or "external".
149
+ */
150
+ type: string;
151
+ /**
152
+ * The total capacity of the storage unit in bytes.
153
+ */
154
+ capacity: number;
155
+ /**
156
+ * The amount of free space available in the storage unit in bytes.
157
+ */
158
+ freeSpace: number;
159
+ /**
160
+ * The amount of usable space in the storage unit in bytes.
161
+ */
162
+ usableSpace: number;
163
+ /**
164
+ * Indicates whether the storage unit is removable (e.g., an SD card).
165
+ */
166
+ removable: boolean;
167
+ }
168
+
169
+ ```
170
+
171
+ #### Params
172
+
173
+ | Name | Type | Required | Description |
174
+ |------------|-------------|------------------|----------------------------------|
175
+ | `filePath` | `IFilePath` | <div>Yes</div> | The file path to concatenate to. |
176
+ | `paths` | `string[]` | <div>Yes</div> | Strings to concatenate. |
177
+
178
+ #### Return value
179
+
180
+ New file path with paths concatenated to it.
181
+
182
+ #### Example
183
+
184
+ ```ts
185
+ const path = { filePath: "uploads/archive.tar", storageUnit: ... };
186
+ fpath.concat(path, "_extracted"); // { filePath: "uploads/archive.tar_extracted", storageUnit: ... }
35
187
  ```
36
188
 
37
189
  <Separator />
38
190
 
39
191
  ### dirname()
40
192
 
193
+ Removes the last portion of path, returning the parent directory of the path. Ignores trailing slashes
194
+
41
195
  ```ts expandable
42
- dirname(filePath: import("./FrontApplet/FileSystem/types").IFilePath): import("./FrontApplet/FileSystem/types").IFilePath;
196
+ dirname(filePath: IFilePath): IFilePath;
197
+ // show-more
198
+ /**
199
+ * Base File System interface for methods.
200
+ */
201
+ interface IFilePath {
202
+ /**
203
+ * Storage unit which is selected for performing file operations.
204
+ */
205
+ storageUnit: IStorageUnit;
206
+ /**
207
+ * File path within the storage unit.
208
+ */
209
+ filePath: string;
210
+ }
211
+
212
+ /**
213
+ * File System Storage Unit returned by the File System API.
214
+ */
215
+ interface IStorageUnit {
216
+ /**
217
+ * The type of the storage unit, e.g., "internal" or "external".
218
+ */
219
+ type: string;
220
+ /**
221
+ * The total capacity of the storage unit in bytes.
222
+ */
223
+ capacity: number;
224
+ /**
225
+ * The amount of free space available in the storage unit in bytes.
226
+ */
227
+ freeSpace: number;
228
+ /**
229
+ * The amount of usable space in the storage unit in bytes.
230
+ */
231
+ usableSpace: number;
232
+ /**
233
+ * Indicates whether the storage unit is removable (e.g., an SD card).
234
+ */
235
+ removable: boolean;
236
+ }
237
+
238
+ ```
239
+
240
+ #### Params
241
+
242
+ | Name | Type | Required | Description |
243
+ |------------|-------------|------------------|------------------------------------------|
244
+ | `filePath` | `IFilePath` | <div>Yes</div> | The file path to get the directory from. |
245
+
246
+ #### Return value
247
+
248
+ The parent directory of the path, with the same storage unit.
249
+
250
+ #### Example
251
+
252
+ ```ts
253
+ const path = { filePath: "images/picture.png", storageUnit: ... };
254
+ fpath.dirname(path); // { filePath: "images", storageUnit: ... }
43
255
  ```
44
256
 
45
257
  <Separator />
46
258
 
47
259
  ### extname()
48
260
 
261
+ Returns extension of the path, from the last period, including the period.
262
+
49
263
  ```ts expandable
50
- extname(filePath: import("./FrontApplet/FileSystem/types").IFilePath): string;
264
+ extname(filePath: IFilePath): string;
265
+ // show-more
266
+ /**
267
+ * Base File System interface for methods.
268
+ */
269
+ interface IFilePath {
270
+ /**
271
+ * Storage unit which is selected for performing file operations.
272
+ */
273
+ storageUnit: IStorageUnit;
274
+ /**
275
+ * File path within the storage unit.
276
+ */
277
+ filePath: string;
278
+ }
279
+
280
+ /**
281
+ * File System Storage Unit returned by the File System API.
282
+ */
283
+ interface IStorageUnit {
284
+ /**
285
+ * The type of the storage unit, e.g., "internal" or "external".
286
+ */
287
+ type: string;
288
+ /**
289
+ * The total capacity of the storage unit in bytes.
290
+ */
291
+ capacity: number;
292
+ /**
293
+ * The amount of free space available in the storage unit in bytes.
294
+ */
295
+ freeSpace: number;
296
+ /**
297
+ * The amount of usable space in the storage unit in bytes.
298
+ */
299
+ usableSpace: number;
300
+ /**
301
+ * Indicates whether the storage unit is removable (e.g., an SD card).
302
+ */
303
+ removable: boolean;
304
+ }
305
+
306
+ ```
307
+
308
+ #### Params
309
+
310
+ | Name | Type | Required | Description |
311
+ |------------|-------------|------------------|----------------------------------------------|
312
+ | `filePath` | `IFilePath` | <div>Yes</div> | The file path to extract the extension from. |
313
+
314
+ #### Return value
315
+
316
+ The extension of the path, from the last period, including the period.
317
+
318
+ #### Example
319
+
320
+ ```ts
321
+ const path = { filePath: "images/picture.png", storageUnit: ... };
322
+ fpath.dirname(path); // .png
51
323
  ```
52
324
 
53
325
  <Separator />
54
326
 
55
327
  ### isAbsolute()
56
328
 
329
+ Always returns true, because all file paths are absolute
330
+
57
331
  ```ts expandable
58
- isAbsolute(_: import("./FrontApplet/FileSystem/types").IFilePath): boolean;
332
+ isAbsolute(_: IFilePath): boolean;
333
+ // show-more
334
+ /**
335
+ * Base File System interface for methods.
336
+ */
337
+ interface IFilePath {
338
+ /**
339
+ * Storage unit which is selected for performing file operations.
340
+ */
341
+ storageUnit: IStorageUnit;
342
+ /**
343
+ * File path within the storage unit.
344
+ */
345
+ filePath: string;
346
+ }
347
+
348
+ /**
349
+ * File System Storage Unit returned by the File System API.
350
+ */
351
+ interface IStorageUnit {
352
+ /**
353
+ * The type of the storage unit, e.g., "internal" or "external".
354
+ */
355
+ type: string;
356
+ /**
357
+ * The total capacity of the storage unit in bytes.
358
+ */
359
+ capacity: number;
360
+ /**
361
+ * The amount of free space available in the storage unit in bytes.
362
+ */
363
+ freeSpace: number;
364
+ /**
365
+ * The amount of usable space in the storage unit in bytes.
366
+ */
367
+ usableSpace: number;
368
+ /**
369
+ * Indicates whether the storage unit is removable (e.g., an SD card).
370
+ */
371
+ removable: boolean;
372
+ }
373
+
59
374
  ```
60
375
 
376
+ #### Params
377
+
378
+ | Name | Type | Required | Description |
379
+ |------|-------------|------------------|-------------------------|
380
+ | `_` | `IFilePath` | <div>Yes</div> | The file path to check. |
381
+
61
382
  <Separator />
62
383
 
63
384
  ### join()
64
385
 
386
+ Returns new filePath with paths appended to it and normalized (resolved . and ..)
387
+
65
388
  ```ts expandable
66
- join(filePath: import("./FrontApplet/FileSystem/types").IFilePath, ...paths: string[]): import("./FrontApplet/FileSystem/types").IFilePath;
389
+ join(filePath: IFilePath, ...paths: string[]): IFilePath;
390
+ // show-more
391
+ /**
392
+ * Base File System interface for methods.
393
+ */
394
+ interface IFilePath {
395
+ /**
396
+ * Storage unit which is selected for performing file operations.
397
+ */
398
+ storageUnit: IStorageUnit;
399
+ /**
400
+ * File path within the storage unit.
401
+ */
402
+ filePath: string;
403
+ }
404
+
405
+ /**
406
+ * File System Storage Unit returned by the File System API.
407
+ */
408
+ interface IStorageUnit {
409
+ /**
410
+ * The type of the storage unit, e.g., "internal" or "external".
411
+ */
412
+ type: string;
413
+ /**
414
+ * The total capacity of the storage unit in bytes.
415
+ */
416
+ capacity: number;
417
+ /**
418
+ * The amount of free space available in the storage unit in bytes.
419
+ */
420
+ freeSpace: number;
421
+ /**
422
+ * The amount of usable space in the storage unit in bytes.
423
+ */
424
+ usableSpace: number;
425
+ /**
426
+ * Indicates whether the storage unit is removable (e.g., an SD card).
427
+ */
428
+ removable: boolean;
429
+ }
430
+
431
+ ```
432
+
433
+ #### Params
434
+
435
+ | Name | Type | Required | Description |
436
+ |------------|-------------|------------------|--------------------------|
437
+ | `filePath` | `IFilePath` | <div>Yes</div> | The base file path. |
438
+ | `paths` | `string[]` | <div>Yes</div> | Path segments to append. |
439
+
440
+ #### Return value
441
+
442
+ New file path with paths appended to it and normalized.
443
+
444
+ #### Example
445
+
446
+ ```ts
447
+ const path = { filePath: "images", storageUnit: ... };
448
+ fpath.join(path, "racoons", ".", "picture.png"); // { filePath: "images/racoons/picture.png", storageUnit: ... }
67
449
  ```
68
450
 
69
451
  <Separator />
70
452
 
71
453
  ### normalize()
72
454
 
455
+ Resolves `.` and `..` in the path and removes multiple slashes.
456
+
73
457
  ```ts expandable
74
- normalize(filePath: import("./FrontApplet/FileSystem/types").IFilePath): import("./FrontApplet/FileSystem/types").IFilePath;
458
+ normalize(filePath: IFilePath): IFilePath;
459
+ // show-more
460
+ /**
461
+ * Base File System interface for methods.
462
+ */
463
+ interface IFilePath {
464
+ /**
465
+ * Storage unit which is selected for performing file operations.
466
+ */
467
+ storageUnit: IStorageUnit;
468
+ /**
469
+ * File path within the storage unit.
470
+ */
471
+ filePath: string;
472
+ }
473
+
474
+ /**
475
+ * File System Storage Unit returned by the File System API.
476
+ */
477
+ interface IStorageUnit {
478
+ /**
479
+ * The type of the storage unit, e.g., "internal" or "external".
480
+ */
481
+ type: string;
482
+ /**
483
+ * The total capacity of the storage unit in bytes.
484
+ */
485
+ capacity: number;
486
+ /**
487
+ * The amount of free space available in the storage unit in bytes.
488
+ */
489
+ freeSpace: number;
490
+ /**
491
+ * The amount of usable space in the storage unit in bytes.
492
+ */
493
+ usableSpace: number;
494
+ /**
495
+ * Indicates whether the storage unit is removable (e.g., an SD card).
496
+ */
497
+ removable: boolean;
498
+ }
499
+
500
+ ```
501
+
502
+ #### Params
503
+
504
+ | Name | Type | Required | Description |
505
+ |------------|-------------|------------------|-----------------------------|
506
+ | `filePath` | `IFilePath` | <div>Yes</div> | The file path to normalize. |
507
+
508
+ #### Return value
509
+
510
+ Normalized file path.
511
+
512
+ #### Example
513
+
514
+ ```ts
515
+ const path = { filePath: "images//test/../test2/./", storageUnit: ... };
516
+ fpath.normalize(path); // { filePath: "images/test2/", storageUnit: ... }
75
517
  ```
76
518
 
77
519
  <Separator />
78
520
 
79
521
  ### resolve()
80
522
 
523
+ Works like `fpath.join()`, but if any of the paths is an absolute path, it will be resolved to the root of the storage unit instead of the root of the file system.
524
+
81
525
  ```ts expandable
82
- resolve(filePath: import("./FrontApplet/FileSystem/types").IFilePath, ...paths: string[]): import("./FrontApplet/FileSystem/types").IFilePath;
526
+ resolve(filePath: IFilePath, ...paths: string[]): IFilePath;
527
+ // show-more
528
+ /**
529
+ * Base File System interface for methods.
530
+ */
531
+ interface IFilePath {
532
+ /**
533
+ * Storage unit which is selected for performing file operations.
534
+ */
535
+ storageUnit: IStorageUnit;
536
+ /**
537
+ * File path within the storage unit.
538
+ */
539
+ filePath: string;
540
+ }
541
+
542
+ /**
543
+ * File System Storage Unit returned by the File System API.
544
+ */
545
+ interface IStorageUnit {
546
+ /**
547
+ * The type of the storage unit, e.g., "internal" or "external".
548
+ */
549
+ type: string;
550
+ /**
551
+ * The total capacity of the storage unit in bytes.
552
+ */
553
+ capacity: number;
554
+ /**
555
+ * The amount of free space available in the storage unit in bytes.
556
+ */
557
+ freeSpace: number;
558
+ /**
559
+ * The amount of usable space in the storage unit in bytes.
560
+ */
561
+ usableSpace: number;
562
+ /**
563
+ * Indicates whether the storage unit is removable (e.g., an SD card).
564
+ */
565
+ removable: boolean;
566
+ }
567
+
83
568
  ```
84
569
 
570
+ #### Params
571
+
572
+ | Name | Type | Required | Description |
573
+ |------------|-------------|------------------|---------------------------|
574
+ | `filePath` | `IFilePath` | <div>Yes</div> | The base file path. |
575
+ | `paths` | `string[]` | <div>Yes</div> | Path segments to resolve. |
576
+
577
+ #### Return value
578
+
579
+ New file path with paths resolved to it.
580
+
85
581
  <Separator />
86
582
 
87
583
  ### safeJoin()
88
584
 
585
+ Similar to `fpath.join()`, but resulting path will always be subdirectory of base.
586
+
89
587
  ```ts expandable
90
- safeJoin(base: import("./FrontApplet/FileSystem/types").IFilePath, ...paths: string[]): import("./FrontApplet/FileSystem/types").IFilePath;
588
+ safeJoin(base: IFilePath, ...paths: string[]): IFilePath;
589
+ // show-more
590
+ /**
591
+ * Base File System interface for methods.
592
+ */
593
+ interface IFilePath {
594
+ /**
595
+ * Storage unit which is selected for performing file operations.
596
+ */
597
+ storageUnit: IStorageUnit;
598
+ /**
599
+ * File path within the storage unit.
600
+ */
601
+ filePath: string;
602
+ }
603
+
604
+ /**
605
+ * File System Storage Unit returned by the File System API.
606
+ */
607
+ interface IStorageUnit {
608
+ /**
609
+ * The type of the storage unit, e.g., "internal" or "external".
610
+ */
611
+ type: string;
612
+ /**
613
+ * The total capacity of the storage unit in bytes.
614
+ */
615
+ capacity: number;
616
+ /**
617
+ * The amount of free space available in the storage unit in bytes.
618
+ */
619
+ freeSpace: number;
620
+ /**
621
+ * The amount of usable space in the storage unit in bytes.
622
+ */
623
+ usableSpace: number;
624
+ /**
625
+ * Indicates whether the storage unit is removable (e.g., an SD card).
626
+ */
627
+ removable: boolean;
628
+ }
629
+
630
+ ```
631
+
632
+ #### Params
633
+
634
+ | Name | Type | Required | Description |
635
+ |---------|-------------|------------------|----------------------------------------------------------------------|
636
+ | `base` | `IFilePath` | <div>Yes</div> | The base file path that the result will always be a subdirectory of. |
637
+ | `paths` | `string[]` | <div>Yes</div> | Path segments to append. |
638
+
639
+ #### Return value
640
+
641
+ New file path with paths appended to it, normalized and guaranteed to be a subdirectory of base.
642
+
643
+ #### Example
644
+
645
+ ```ts
646
+ const path = { filePath: "uploads/userA", storageUnit: ... };
647
+ fpath.safeJoin(path, "..", "userB", "picture.png"); // { filePath: "uploads/userA/userB/picture.png", storageUnit: ... }
91
648
  ```
92
649
 
93
650
  <Separator />
94
651
 
95
652
  ### stringify()
96
653
 
654
+ Convert filePath to string, this string is not guaranteed to be unique and should be only used for debugging/logging.
655
+
97
656
  ```ts expandable
98
- stringify(filePath: import("./FrontApplet/FileSystem/types").IFilePath): string;
99
- ```
657
+ stringify(filePath: IFilePath): string;
658
+ // show-more
659
+ /**
660
+ * Base File System interface for methods.
661
+ */
662
+ interface IFilePath {
663
+ /**
664
+ * Storage unit which is selected for performing file operations.
665
+ */
666
+ storageUnit: IStorageUnit;
667
+ /**
668
+ * File path within the storage unit.
669
+ */
670
+ filePath: string;
671
+ }
672
+
673
+ /**
674
+ * File System Storage Unit returned by the File System API.
675
+ */
676
+ interface IStorageUnit {
677
+ /**
678
+ * The type of the storage unit, e.g., "internal" or "external".
679
+ */
680
+ type: string;
681
+ /**
682
+ * The total capacity of the storage unit in bytes.
683
+ */
684
+ capacity: number;
685
+ /**
686
+ * The amount of free space available in the storage unit in bytes.
687
+ */
688
+ freeSpace: number;
689
+ /**
690
+ * The amount of usable space in the storage unit in bytes.
691
+ */
692
+ usableSpace: number;
693
+ /**
694
+ * Indicates whether the storage unit is removable (e.g., an SD card).
695
+ */
696
+ removable: boolean;
697
+ }
698
+
699
+ ```
700
+
701
+ #### Params
702
+
703
+ | Name | Type | Required | Description |
704
+ |------------|-------------|------------------|-------------------------------------|
705
+ | `filePath` | `IFilePath` | <div>Yes</div> | The file path to convert to string. |
706
+
707
+ #### Return value
708
+
709
+ The string representation of the file path.