2022-10-15 16:44:43 +02:00
|
|
|
import trim from 'lodash/trim';
|
|
|
|
import path from 'path';
|
2023-02-12 17:16:42 +01:00
|
|
|
import slash from './slash';
|
2022-10-15 16:44:43 +02:00
|
|
|
|
|
|
|
export const isElectron = () => {
|
2022-10-20 11:39:30 +02:00
|
|
|
if (!window) {
|
2022-10-15 16:44:43 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return window.ipcRenderer ? true : false;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const isLocalCollection = (collection) => {
|
|
|
|
return collection.pathname ? true : false;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const resolveRequestFilename = (name) => {
|
2023-01-16 21:30:58 +01:00
|
|
|
return `${trim(name)}.bru`;
|
2022-10-15 16:44:43 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export const getSubdirectoriesFromRoot = (rootPath, pathname) => {
|
2023-02-12 17:16:42 +01:00
|
|
|
// convert to unix style path
|
|
|
|
pathname = slash(pathname);
|
|
|
|
rootPath = slash(rootPath);
|
|
|
|
|
2022-10-15 16:44:43 +02:00
|
|
|
const relativePath = path.relative(rootPath, pathname);
|
|
|
|
return relativePath ? relativePath.split(path.sep) : [];
|
|
|
|
};
|
2023-02-12 17:16:42 +01:00
|
|
|
|
|
|
|
export const getDirectoryName = (pathname) => {
|
|
|
|
// convert to unix style path
|
|
|
|
pathname = slash(pathname);
|
|
|
|
|
|
|
|
return path.dirname(pathname);
|
|
|
|
}
|