tool.js
function (base, path, noStartingSlash) {

        if (base === path) {
            return '';
        }

        // Sanitize inputs, convert windows to posix style slashes, ensure trailing slash for base
        base = base.replace(/^[a-z]:/i, '').replace(/\\/g, '/').replace(/\/$/g, '') + '/';
        path = path.replace(/^[a-z]:/i, '').replace(/\\/g, '/');
        // console.log(' ==== '+path);
        // Only truncate paths that overap with the base
        if (base === path.substr(0, base.length)) {
            path = '/' + path.substr(base.length);
        }

        var modifyStartingSlash = noStartingSlash !== undefined;

        if(modifyStartingSlash) {
            if (path[0] === '/' && noStartingSlash) {
                path = path.substr(1);
            } else if (path[0] !== '/' && !noStartingSlash){
                path = '/' + path;
            }
        }

        return path;

    }
function (base, path, noStartingSlash) {

        if (base === path) {
            return '';
        }

        // Sanitize inputs, convert windows to posix style slashes, ensure trailing slash for base
        base = base.replace(/^[a-z]:/i, '').replace(/\\/g, '/').replace(/\/$/g, '') + '/';
        path = path.replace(/^[a-z]:/i, '').replace(/\\/g, '/');
        // console.log(' ==== '+path);
        // Only truncate paths that overap with the base
        if (base === path.substr(0, base.length)) {
            path = '/' + path.substr(base.length);
        }

        var modifyStartingSlash = noStartingSlash !== undefined;

        if(modifyStartingSlash) {
            if (path[0] === '/' && noStartingSlash) {
                path = path.substr(1);
            } else if (path[0] !== '/' && !noStartingSlash){
                path = '/' + path;
            }
        }

        return path;

    }
function ( base , path , noStartingSlash ) { if ( base === path ) { return '' ; } // Sanitize inputs, convert windows to posix style slashes, ensure trailing slash for base base = base . replace ( / ^[a-z]: / i , '' ) . replace ( / \\ / g , '/' ) . replace ( / \/$ / g , '' ) + '/' ; path = path . replace ( / ^[a-z]: / i , '' ) . replace ( / \\ / g , '/' ) ; // console.log(' ==== '+path); // Only truncate paths that overap with the base if ( base === path . substr ( 0 , base . length ) ) { path = '/' + path . substr ( base . length ) ; } var modifyStartingSlash = noStartingSlash !== undefined ; if ( modifyStartingSlash ) { if ( path [ 0 ] === '/' && noStartingSlash ) { path = path . substr ( 1 ) ; } else if ( path [ 0 ] !== '/' && ! noStartingSlash ) { path = '/' + path ; } } return path ; }
Given a base path and resource path, will return resource path relative to the base.
Also replaces Windows forward-slash with a backslash.
Given a base path and resource path will return resource path relative to the base . Also replaces Windows forward - slash with a backslash .