Repository URL to install this package:
|
Version:
5.0.0 ▾
|
import { resolve } from 'path'
import { existsSync } from 'fs'
export function resolveToRoot(fileName: string) {
return resolve(process.cwd(), fileName)
}
export function toRootPath(fileName: string): string {
if (fileName.startsWith('/')) {
return fileName
} else {
const absolutePath = resolveToRoot(fileName)
return absolutePath
}
}
export function pathIfExists(fileName: string): string | false {
const absolutePath = toRootPath(fileName)
if (existsSync(absolutePath) === true) {
return absolutePath
} else {
return false
}
}
export function fromFileNamesToFirstExistingPath(
...fileNames: string[]
): string {
const found =
fileNames.find(x => pathIfExists(x) !== false) ||
'@EMPTY:fromFileNamesToFirstExistingPath'
return toRootPath(found)
}