s3-file-manager
Version:
A streamlined, high-level S3 client for Node.js with built-in retries and support for uploads, downloads, and file operations — works with any S3-compatible storage.
16 lines (15 loc) • 443 B
JavaScript
export const formatPrefix = (filename, prefix) => {
let formattedPrefix;
const prefixSlash = prefix.endsWith("/");
const filenameSlash = filename.startsWith("/");
if (prefixSlash && filenameSlash) {
formattedPrefix = prefix.slice(0, -1);
}
else if (!prefixSlash && !filenameSlash) {
formattedPrefix = prefix + "/";
}
else {
formattedPrefix = prefix;
}
return formattedPrefix;
};