function resolve(relativeIRI, baseIRI) {
    baseIRI = baseIRI || '';
    const baseFragmentPos = baseIRI.indexOf('#');
    // Ignore any fragments in the base IRI
    if (baseFragmentPos > 0) {
        baseIRI = baseIRI.substr(0, baseFragmentPos);
    }
    // Convert empty value directly to base IRI
    if (!relativeIRI.length) {
        // At this point, the baseIRI MUST be absolute, otherwise we error
        if (baseIRI.indexOf(':') < 0) {
            throw new Error(`Found invalid baseIRI '${baseIRI}' for value '${relativeIRI}'`);
        }
        return baseIRI;
    }
    // If the value starts with a query character, concat directly (but strip the existing query)
    if (relativeIRI.startsWith('?')) {
        const baseQueryPos = baseIRI.indexOf('?');
        if (baseQueryPos > 0) {
            baseIRI = baseIRI.substr(0, baseQueryPos);
        }
        return baseIRI + relativeIRI;
    }
    // If the value starts with a fragment character, concat directly
    if (relativeIRI.startsWith('#')) {
        return baseIRI + relativeIRI;
    }
    // Ignore baseIRI if it is empty
    if (!baseIRI.length) {
        const relativeColonPos = relativeIRI.indexOf(':');
        if (relativeColonPos < 0) {
            throw new Error(`Found invalid relative IRI '${relativeIRI}' for a missing baseIRI`);
        }
        return removeDotSegmentsOfPath(relativeIRI, relativeColonPos);
    }
    // Ignore baseIRI if the value is absolute
    const valueColonPos = relativeIRI.indexOf(':');
    if (valueColonPos >= 0) {
        return removeDotSegmentsOfPath(relativeIRI, valueColonPos);
    }
    // At this point, the baseIRI MUST be absolute, otherwise we error
    const baseColonPos = baseIRI.indexOf(':');
    if (baseColonPos < 0) {
        throw new Error(`Found invalid baseIRI '${baseIRI}' for value '${relativeIRI}'`);
    }
    const baseIRIScheme = baseIRI.substr(0, baseColonPos + 1);
    // Inherit the baseIRI scheme if the value starts with '//'
    if (relativeIRI.indexOf('//') === 0) {
        return baseIRIScheme + removeDotSegmentsOfPath(relativeIRI, valueColonPos);
    }
    // Check cases where '://' occurs in the baseIRI, and where there is no '/' after a ':' anymore.
    let baseSlashAfterColonPos;
    if (baseIRI.indexOf('//', baseColonPos) === baseColonPos + 1) {
        // If there is no additional '/' after the '//'.
        baseSlashAfterColonPos = baseIRI.indexOf('/', baseColonPos + 3);
        if (baseSlashAfterColonPos < 0) {
            // If something other than a '/' follows the '://', append the value after a '/',
            // otherwise, prefix the value with only the baseIRI scheme.
            if (baseIRI.length > baseColonPos + 3) {
                return baseIRI + '/' + removeDotSegmentsOfPath(relativeIRI, valueColonPos);
            }
            else {
                return baseIRIScheme + removeDotSegmentsOfPath(relativeIRI, valueColonPos);
            }
        }
    }
    else {
        // If there is not even a single '/' after the ':'
        baseSlashAfterColonPos = baseIRI.indexOf('/', baseColonPos + 1);
        if (baseSlashAfterColonPos < 0) {
            // If we don't have a '/' after the ':',
            // prefix the value with only the baseIRI scheme.
            return baseIRIScheme + removeDotSegmentsOfPath(relativeIRI, valueColonPos);
        }
    }
    // If the value starts with a '/', then prefix it with everything before the first effective slash of the base IRI.
    if (relativeIRI.indexOf('/') === 0) {
        return baseIRI.substr(0, baseSlashAfterColonPos) + removeDotSegments(relativeIRI);
    }
    let baseIRIPath = baseIRI.substr(baseSlashAfterColonPos);
    const baseIRILastSlashPos = baseIRIPath.lastIndexOf('/');
    // Ignore everything after the last '/' in the baseIRI path
    if (baseIRILastSlashPos >= 0 && baseIRILastSlashPos < baseIRIPath.length - 1) {
        baseIRIPath = baseIRIPath.substr(0, baseIRILastSlashPos + 1);
        // Also remove the first character of the relative path if it starts with '.' (and not '..' or './')
        // This change is only allowed if there is something else following the path
        if (relativeIRI[0] === '.' && relativeIRI[1] !== '.' && relativeIRI[1] !== '/' && relativeIRI[2]) {
            relativeIRI = relativeIRI.substr(1);
        }
    }
    // Prefix the value with the baseIRI path where
    relativeIRI = baseIRIPath + relativeIRI;
    // Remove dot segment from the IRI
    relativeIRI = removeDotSegments(relativeIRI);
    // Prefix our transformed value with the part of the baseIRI until the first '/' after the first ':'.
    return baseIRI.substr(0, baseSlashAfterColonPos) + relativeIRI;
}
/**
 * Convert the given relative IRI to an absolute IRI
 * by taking into account the given optional baseIRI.
 *
 * @param {string} relativeIRI The relative IRI to convert to an absolute IRI.
 * @param {string} baseIRI The optional base IRI.
 * @return {string} an absolute IRI.
 */
Convert the given relative IRI to an absolute IRI
by taking into account the given optional baseIRI.

@param {string} relativeIRI The relative IRI to convert to an absolute IRI.
@param {string} baseIRI The optional base IRI.
@return {string} an absolute IRI.
Convert the given relative IRI to an absolute IRI by taking into account the given optional baseIRI . @param { string } relativeIRI The relative IRI to convert to an absolute IRI . @param { string } baseIRI The optional base IRI . @return { string } an absolute IRI .
function resolve(relativeIRI, baseIRI) {
    baseIRI = baseIRI || '';
    const baseFragmentPos = baseIRI.indexOf('#');
    if (baseFragmentPos > 0) {
        baseIRI = baseIRI.substr(0, baseFragmentPos);
    }
    if (!relativeIRI.length) {
        if (baseIRI.indexOf(':') < 0) {
            throw new Error(`Found invalid baseIRI '${baseIRI}' for value '${relativeIRI}'`);
        }
        return baseIRI;
    }
    if (relativeIRI.startsWith('?')) {
        const baseQueryPos = baseIRI.indexOf('?');
        if (baseQueryPos > 0) {
            baseIRI = baseIRI.substr(0, baseQueryPos);
        }
        return baseIRI + relativeIRI;
    }
    if (relativeIRI.startsWith('#')) {
        return baseIRI + relativeIRI;
    }
    if (!baseIRI.length) {
        const relativeColonPos = relativeIRI.indexOf(':');
        if (relativeColonPos < 0) {
            throw new Error(`Found invalid relative IRI '${relativeIRI}' for a missing baseIRI`);
        }
        return removeDotSegmentsOfPath(relativeIRI, relativeColonPos);
    }
    const valueColonPos = relativeIRI.indexOf(':');
    if (valueColonPos >= 0) {
        return removeDotSegmentsOfPath(relativeIRI, valueColonPos);
    }
    const baseColonPos = baseIRI.indexOf(':');
    if (baseColonPos < 0) {
        throw new Error(`Found invalid baseIRI '${baseIRI}' for value '${relativeIRI}'`);
    }
    const baseIRIScheme = baseIRI.substr(0, baseColonPos + 1);
    if (relativeIRI.indexOf('//') === 0) {
        return baseIRIScheme + removeDotSegmentsOfPath(relativeIRI, valueColonPos);
    }
    let baseSlashAfterColonPos;
    if (baseIRI.indexOf('//', baseColonPos) === baseColonPos + 1) {
        baseSlashAfterColonPos = baseIRI.indexOf('/', baseColonPos + 3);
        if (baseSlashAfterColonPos < 0) {
            if (baseIRI.length > baseColonPos + 3) {
                return baseIRI + '/' + removeDotSegmentsOfPath(relativeIRI, valueColonPos);
            }
            else {
                return baseIRIScheme + removeDotSegmentsOfPath(relativeIRI, valueColonPos);
            }
        }
    }
    else {
        baseSlashAfterColonPos = baseIRI.indexOf('/', baseColonPos + 1);
        if (baseSlashAfterColonPos < 0) {
            return baseIRIScheme + removeDotSegmentsOfPath(relativeIRI, valueColonPos);
        }
    }
    if (relativeIRI.indexOf('/') === 0) {
        return baseIRI.substr(0, baseSlashAfterColonPos) + removeDotSegments(relativeIRI);
    }
    let baseIRIPath = baseIRI.substr(baseSlashAfterColonPos);
    const baseIRILastSlashPos = baseIRIPath.lastIndexOf('/');
    if (baseIRILastSlashPos >= 0 && baseIRILastSlashPos < baseIRIPath.length - 1) {
        baseIRIPath = baseIRIPath.substr(0, baseIRILastSlashPos + 1);
        if (relativeIRI[0] === '.' && relativeIRI[1] !== '.' && relativeIRI[1] !== '/' && relativeIRI[2]) {
            relativeIRI = relativeIRI.substr(1);
        }
    }
    relativeIRI = baseIRIPath + relativeIRI;
    relativeIRI = removeDotSegments(relativeIRI);
    return baseIRI.substr(0, baseSlashAfterColonPos) + relativeIRI;
}
function resolve ( relativeIRI , baseIRI ) { baseIRI = baseIRI || '' ; const baseFragmentPos = baseIRI . indexOf ( '#' ) ; if ( baseFragmentPos > 0 ) { baseIRI = baseIRI . substr ( 0 , baseFragmentPos ) ; } if ( ! relativeIRI . length ) { if ( baseIRI . indexOf ( ':' ) < 0 ) { throw new Error ( ` ${ baseIRI } ${ relativeIRI } ` ) ; } return baseIRI ; } if ( relativeIRI . startsWith ( '?' ) ) { const baseQueryPos = baseIRI . indexOf ( '?' ) ; if ( baseQueryPos > 0 ) { baseIRI = baseIRI . substr ( 0 , baseQueryPos ) ; } return baseIRI + relativeIRI ; } if ( relativeIRI . startsWith ( '#' ) ) { return baseIRI + relativeIRI ; } if ( ! baseIRI . length ) { const relativeColonPos = relativeIRI . indexOf ( ':' ) ; if ( relativeColonPos < 0 ) { throw new Error ( ` ${ relativeIRI } ` ) ; } return removeDotSegmentsOfPath ( relativeIRI , relativeColonPos ) ; } const valueColonPos = relativeIRI . indexOf ( ':' ) ; if ( valueColonPos >= 0 ) { return removeDotSegmentsOfPath ( relativeIRI , valueColonPos ) ; } const baseColonPos = baseIRI . indexOf ( ':' ) ; if ( baseColonPos < 0 ) { throw new Error ( ` ${ baseIRI } ${ relativeIRI } ` ) ; } const baseIRIScheme = baseIRI . substr ( 0 , baseColonPos + 1 ) ; if ( relativeIRI . indexOf ( '//' ) === 0 ) { return baseIRIScheme + removeDotSegmentsOfPath ( relativeIRI , valueColonPos ) ; } let baseSlashAfterColonPos ; if ( baseIRI . indexOf ( '//' , baseColonPos ) === baseColonPos + 1 ) { baseSlashAfterColonPos = baseIRI . indexOf ( '/' , baseColonPos + 3 ) ; if ( baseSlashAfterColonPos < 0 ) { if ( baseIRI . length > baseColonPos + 3 ) { return baseIRI + '/' + removeDotSegmentsOfPath ( relativeIRI , valueColonPos ) ; } else { return baseIRIScheme + removeDotSegmentsOfPath ( relativeIRI , valueColonPos ) ; } } } else { baseSlashAfterColonPos = baseIRI . indexOf ( '/' , baseColonPos + 1 ) ; if ( baseSlashAfterColonPos < 0 ) { return baseIRIScheme + removeDotSegmentsOfPath ( relativeIRI , valueColonPos ) ; } } if ( relativeIRI . indexOf ( '/' ) === 0 ) { return baseIRI . substr ( 0 , baseSlashAfterColonPos ) + removeDotSegments ( relativeIRI ) ; } let baseIRIPath = baseIRI . substr ( baseSlashAfterColonPos ) ; const baseIRILastSlashPos = baseIRIPath . lastIndexOf ( '/' ) ; if ( baseIRILastSlashPos >= 0 && baseIRILastSlashPos < baseIRIPath . length - 1 ) { baseIRIPath = baseIRIPath . substr ( 0 , baseIRILastSlashPos + 1 ) ; if ( relativeIRI [ 0 ] === '.' && relativeIRI [ 1 ] !== '.' && relativeIRI [ 1 ] !== '/' && relativeIRI [ 2 ] ) { relativeIRI = relativeIRI . substr ( 1 ) ; } } relativeIRI = baseIRIPath + relativeIRI ; relativeIRI = removeDotSegments ( relativeIRI ) ; return baseIRI . substr ( 0 , baseSlashAfterColonPos ) + relativeIRI ; }
Convert the given relative IRI to an absolute IRI
 by taking into account the given optional baseIRI.
Convert the given relative IRI to an absolute IRI by taking into account the given optional baseIRI .
// Ignore any fragments in the base IRI // Convert empty value directly to base IRI // At this point, the baseIRI MUST be absolute, otherwise we error // If the value starts with a query character, concat directly (but strip the existing query) // If the value starts with a fragment character, concat directly // Ignore baseIRI if it is empty // Ignore baseIRI if the value is absolute // At this point, the baseIRI MUST be absolute, otherwise we error // Inherit the baseIRI scheme if the value starts with '//' // Check cases where '://' occurs in the baseIRI, and where there is no '/' after a ':' anymore. // If there is no additional '/' after the '//'. // If something other than a '/' follows the '://', append the value after a '/', // otherwise, prefix the value with only the baseIRI scheme. // If there is not even a single '/' after the ':' // If we don't have a '/' after the ':', // prefix the value with only the baseIRI scheme. // If the value starts with a '/', then prefix it with everything before the first effective slash of the base IRI. // Ignore everything after the last '/' in the baseIRI path // Also remove the first character of the relative path if it starts with '.' (and not '..' or './') // This change is only allowed if there is something else following the path // Prefix the value with the baseIRI path where // Remove dot segment from the IRI // Prefix our transformed value with the part of the baseIRI until the first '/' after the first ':'.