dist/src/util.js
function normalizePath(path) {
    // Separate the path into parts (delimited by slashes)
    let parts = [""];
    for (let char of path) {
        if (char === "/" || char === "\\") {
            if (parts[parts.length - 1].length) {
                parts.push("");
            }
        }
        else {
            parts[parts.length - 1] += char;
        }
    }
    // Special case for when the entire path was "."
    if (parts.length === 1 && parts[0] === ".") {
        return ".";
    }
    // Resolve "." and ".."
    let i = 0;
    while (i < parts.length) {
        if (parts[i] === ".") {
            parts.splice(i, 1);
        }
        else if (i > 0 && parts[i] === "..") {
            parts.splice(i - 1, 2);
            i--;
        }
        else {
            i++;
        }
    }
    // Build the resulting path
    let result = "";
    for (let part of parts) {
        if (part && part.length) {
            if (result.length) {
                result += "/";
            }
            result += part;
        }
    }
    // Retain a slash at the beginning of the string
    if (path[0] === "/" || path[0] === "\\") {
        result = "/" + result;
    }
    // All done!
    return result;
}
function normalizePath(path) {
    // Separate the path into parts (delimited by slashes)
    let parts = [""];
    for (let char of path) {
        if (char === "/" || char === "\\") {
            if (parts[parts.length - 1].length) {
                parts.push("");
            }
        }
        else {
            parts[parts.length - 1] += char;
        }
    }
    // Special case for when the entire path was "."
    if (parts.length === 1 && parts[0] === ".") {
        return ".";
    }
    // Resolve "." and ".."
    let i = 0;
    while (i < parts.length) {
        if (parts[i] === ".") {
            parts.splice(i, 1);
        }
        else if (i > 0 && parts[i] === "..") {
            parts.splice(i - 1, 2);
            i--;
        }
        else {
            i++;
        }
    }
    // Build the resulting path
    let result = "";
    for (let part of parts) {
        if (part && part.length) {
            if (result.length) {
                result += "/";
            }
            result += part;
        }
    }
    // Retain a slash at the beginning of the string
    if (path[0] === "/" || path[0] === "\\") {
        result = "/" + result;
    }
    // All done!
    return result;
}
function normalizePath ( path ) { // Separate the path into parts (delimited by slashes) let parts = [ "" ] ; for ( let char of path ) { if ( char === "/" || char === "\\" ) { if ( parts [ parts . length - 1 ] . length ) { parts . push ( "" ) ; } } else { parts [ parts . length - 1 ] += char ; } } // Special case for when the entire path was "." if ( parts . length === 1 && parts [ 0 ] === "." ) { return "." ; } // Resolve "." and ".." let i = 0 ; while ( i < parts . length ) { if ( parts [ i ] === "." ) { parts . splice ( i , 1 ) ; } else if ( i > 0 && parts [ i ] === ".." ) { parts . splice ( i - 1 , 2 ) ; i -- ; } else { i ++ ; } } // Build the resulting path let result = "" ; for ( let part of parts ) { if ( part && part . length ) { if ( result . length ) { result += "/" ; } result += part ; } } // Retain a slash at the beginning of the string if ( path [ 0 ] === "/" || path [ 0 ] === "\\" ) { result = "/" + result ; } // All done! return result ; }
Helper function to normalize a file path for comparison. Makes all slashes forward slashes, removes trailing and redundant slashes, and resolves "." and "..".
Helper function to normalize a file path for comparison . Makes all slashes forward slashes removes trailing and redundant slashes and resolves . and .. .