Skip to content
Snippets Groups Projects
utils.ts 601 B
Newer Older
  • Learn to ignore specific revisions
  • François Agneray's avatar
    François Agneray committed
    /**
     * Returns strict url address.
     *
     * @return string
     *
     * @example
     * const url: string = getHost() + '/following-url/';
     */
    
    export const getHost = (apiUrl: string): string => {
        if (!apiUrl.startsWith('http')) {
    
    François Agneray's avatar
    François Agneray committed
            const url = window.location;
    
            return url.protocol + '//' + url.host + apiUrl;
    
    François Agneray's avatar
    François Agneray committed
        }
    
    François Agneray's avatar
    François Agneray committed
    }
    
    
    /**
     * Sorts objects by the display property.
     *
     * @param  {number} a - The first object to sort.
     * @param  {number} b - The second object to sort.
     *
     * @example
     * [objects].sortByDisplay()
     */
    export const sortByDisplay = (a, b) => a.display - b.display;