2022-10-15 16:44:43 +02:00
|
|
|
import trim from 'lodash/trim';
|
|
|
|
import path from 'path';
|
|
|
|
|
|
|
|
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) => {
|
|
|
|
return `${trim(name)}.json`;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getSubdirectoriesFromRoot = (rootPath, pathname) => {
|
|
|
|
if (!path.isAbsolute(pathname)) {
|
|
|
|
throw new Error('Invalid path!');
|
|
|
|
}
|
|
|
|
const relativePath = path.relative(rootPath, pathname);
|
|
|
|
return relativePath ? relativePath.split(path.sep) : [];
|
|
|
|
};
|