UNPKG

dataunlocker

Version:

DataUnlocker's command line interface utilities

23 lines (22 loc) 635 B
import { promises as fs } from 'fs'; import { isAbsolute, relative } from 'path'; export async function isFileExists(filePath) { try { await fs.access(filePath); return true; } catch (error) { return false; } } /** * Returns a filename relative to CWD given the full file path, otherwise returns the original string. */ export const getRelativeFileToCwd = (fullFilePath) => { const cwd = process.cwd(); const relativePath = relative(cwd, fullFilePath); if (relativePath.startsWith('..') || isAbsolute(relativePath)) { return fullFilePath; } return relativePath; };