Skip to content

⬅️ Back to Table of Contents

📄 LoaderUtils.js

📊 Analysis Summary

Metric Count
🔧 Functions 2
🧱 Classes 1

📚 Table of Contents

🛠️ File Location:

📂 src/loaders/LoaderUtils.js

Functions

LoaderUtils.extractUrlBase(url: string): string

JSDoc:

/**
     * Extracts the base URL from the given URL.
     *
     * @param {string} url -The URL to extract the base URL from.
     * @return {string} The extracted base URL.
     */

Parameters:

  • url string

Returns: string

Calls:

  • url.lastIndexOf
  • url.slice
Code
static extractUrlBase( url ) {

        const index = url.lastIndexOf( '/' );

        if ( index === - 1 ) return './';

        return url.slice( 0, index + 1 );

    }

LoaderUtils.resolveURL(url: string, path: string): string

JSDoc:

/**
     * Resolves relative URLs against the given path. Absolute paths, data urls,
     * and blob URLs will be returned as is. Invalid URLs will return an empty
     * string.
     *
     * @param {string} url -The URL to resolve.
     * @param {string} path - The base path for relative URLs to be resolved against.
     * @return {string} The resolved URL.
     */

Parameters:

  • url string
  • path string

Returns: string

Calls:

  • /^https?:\/\//i.test
  • /^\//.test
  • path.replace
  • /^(https?:)?\/\//i.test
  • /^data:.*,.*$/i.test
  • /^blob:.*$/i.test

Internal Comments:

// Invalid URL
// Host Relative URL
// Absolute URL http://,https://,//
// Data URI
// Blob URL
// Relative URL

Code
static resolveURL( url, path ) {

        // Invalid URL
        if ( typeof url !== 'string' || url === '' ) return '';

        // Host Relative URL
        if ( /^https?:\/\//i.test( path ) && /^\//.test( url ) ) {

            path = path.replace( /(^https?:\/\/[^\/]+).*/i, '$1' );

        }

        // Absolute URL http://,https://,//
        if ( /^(https?:)?\/\//i.test( url ) ) return url;

        // Data URI
        if ( /^data:.*,.*$/i.test( url ) ) return url;

        // Blob URL
        if ( /^blob:.*$/i.test( url ) ) return url;

        // Relative URL
        return path + url;

    }

Classes

LoaderUtils

Class Code
class LoaderUtils {

    /**
     * Extracts the base URL from the given URL.
     *
     * @param {string} url -The URL to extract the base URL from.
     * @return {string} The extracted base URL.
     */
    static extractUrlBase( url ) {

        const index = url.lastIndexOf( '/' );

        if ( index === - 1 ) return './';

        return url.slice( 0, index + 1 );

    }

    /**
     * Resolves relative URLs against the given path. Absolute paths, data urls,
     * and blob URLs will be returned as is. Invalid URLs will return an empty
     * string.
     *
     * @param {string} url -The URL to resolve.
     * @param {string} path - The base path for relative URLs to be resolved against.
     * @return {string} The resolved URL.
     */
    static resolveURL( url, path ) {

        // Invalid URL
        if ( typeof url !== 'string' || url === '' ) return '';

        // Host Relative URL
        if ( /^https?:\/\//i.test( path ) && /^\//.test( url ) ) {

            path = path.replace( /(^https?:\/\/[^\/]+).*/i, '$1' );

        }

        // Absolute URL http://,https://,//
        if ( /^(https?:)?\/\//i.test( url ) ) return url;

        // Data URI
        if ( /^data:.*,.*$/i.test( url ) ) return url;

        // Blob URL
        if ( /^blob:.*$/i.test( url ) ) return url;

        // Relative URL
        return path + url;

    }

}

Methods

extractUrlBase(url: string): string
Code
static extractUrlBase( url ) {

        const index = url.lastIndexOf( '/' );

        if ( index === - 1 ) return './';

        return url.slice( 0, index + 1 );

    }
resolveURL(url: string, path: string): string
Code
static resolveURL( url, path ) {

        // Invalid URL
        if ( typeof url !== 'string' || url === '' ) return '';

        // Host Relative URL
        if ( /^https?:\/\//i.test( path ) && /^\//.test( url ) ) {

            path = path.replace( /(^https?:\/\/[^\/]+).*/i, '$1' );

        }

        // Absolute URL http://,https://,//
        if ( /^(https?:)?\/\//i.test( url ) ) return url;

        // Data URI
        if ( /^data:.*,.*$/i.test( url ) ) return url;

        // Blob URL
        if ( /^blob:.*$/i.test( url ) ) return url;

        // Relative URL
        return path + url;

    }