Skip to main content
Version: 8.0.3

fpath

fpath utility mirrors node path module, but accepts IFilePath type instead of strings. It is useful when working with sos.fileSystem.

Not implemented functions:

  • format
  • matchesGlob
  • parse
  • relative
import { sos, fpath } from "@signageos/front-applet";

const [internal] = await sos.fileSystem.listInternalStorageUnits();
const rootPath = {
filePath: '', // Empty string is used as an absolute path instead of "/"
storageUnit: internal
};

// list saved files in videos/2025-05-19/ directory
const videos = await sos.fileSystem.listFiles(
fpath.join(rootPath, "videos", "2025-05-19"),
);

Properties

path

Underlying path polyfill

path: path.Path;

sep

Separator used for joining path segments

sep: string;

Methods

basename()

Return the last portion of path, since it is not a valid path, a string is returned.

basename(filePath: IFilePath, suffix?: string): string;

Example

const path = { filePath: "images/picture.png", storageUnit: ... };
fpath.basename(path); // "picture.png"

concat()

Concatenate fp with paths without adding separator

concat(filePath: IFilePath, ...paths: string[]): IFilePath;

Example

const path = { filePath: "uploads/archive.tar", storageUnit: ... };
fpath.concat(path, "_extracted"); // { filePath: "uploads/archive.tar_extracted", storageUnit: ... }

dirname()

Removes the last portion of path, returning the parent directory of the path. Ignores trailing slashes

dirname(filePath: IFilePath): IFilePath;

Example

const path = { filePath: "images/picture.png", storageUnit: ... };
fpath.dirname(path); // { filePath: "images", storageUnit: ... }

extname()

Returns extension of the path, from the last period, including the period.

extname(filePath: IFilePath): string;

Example

const path = { filePath: "images/picture.png", storageUnit: ... };
fpath.dirname(path); // .png

isAbsolute()

Always returns true, because all file paths are absolute

isAbsolute(_: IFilePath): boolean;

join()

Returns new filePath with paths appended to it and normalized (resolved . and ..)

join(filePath: IFilePath, ...paths: string[]): IFilePath;

Example

const path = { filePath: "images", storageUnit: ... };
fpath.join(path, "racoons", ".", "picture.png"); // { filePath: "images/racoons/picture.png", storageUnit: ... }

normalize()

Resolves . and .. in the path and removes multiple slashes

normalize(filePath: IFilePath): IFilePath;

Example

const path = { filePath: "images//test/../test2/./", storageUnit: ... };
fpath.normalize(path); // { filePath: "images/test2/", storageUnit: ... }

resolve()

Same as fpath.join()

resolve(filePath: IFilePath, ...paths: string[]): IFilePath;

safeJoin()

Similar to fpath.join, but resulting path will always be subdirectory of base

safeJoin(base: IFilePath, ...paths: string[]): IFilePath;

Example

const path = { filePath: "uploads/userA", storageUnit: ... };
fpath.safeJoin(path, "..", "userB", "picture.png"); // { filePath: "uploads/userA/userB/picture.png", storageUnit: ... }

stringify()

Convert filePath to string, this string is not guaranteed to be unique and should be only used for debugging/logging

stringify(filePath: IFilePath): string;