UNPKG

qsu

Version:

qsu is a utility library that contains useful and frequently used functions. Start with your preferred language and the modern development environment.

1 lines 420 B
import{posix as e,win32 as t}from"path";export function toValidFilePath(i,n){if(i?.length<1)return n?"\\":"/";if(n){let e=i;return e=t.normalize(e).replace(/\.$/g,""),e.endsWith("\\")&&e.length>1&&(e=e.replace(/\\+$/,"")),e.endsWith(":")&&(e=`${e}\\`),e.startsWith("\\")||-1!==e.indexOf(":")||(e=`\\${e}`),e}{let t=i;return t=e.normalize(t),e.isAbsolute(t)||(t=`/${t}`),t.endsWith("/")&&t.length>1&&(t=t.slice(0,-1)),t}}