| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- import {FileArgs, ImageArgs, ListArgs, UrlArgs} from '~/types/interfaces'
- import {QUERY_TYPE} from '~/types/enums'
- import TypesTesting from "~/services/utils/typesTesting";
- /**
- * Classe permettant de construire une URL pour l'interrogation d'une API externe
- */
- class Url {
- /**
- * Concatenate a base url and a tail
- * @param base
- * @param tails
- * @private
- */
- public static join (base: string, ...tails: string[]): string {
- let url = base
- tails.forEach((tail: string) => {
- url = url.replace(/^|\/$/g, '') + '/' + tail.replace(/^\/?|$/g, '')
- })
- return url
- }
- /**
- * Prepend the 'https://' part if neither 'http://' of 'https://' is present, else: does nothing
- *
- * @param url
- */
- public static prependHttps (url: string): string {
- if (!url.match(/^https?:\/\/.*/)) {
- url = 'https://' + url;
- }
- return url;
- }
- /**
- * Parse an URI to retrieve the page number
- *
- * @param uri
- * @param parameter
- * @param default_
- * @private
- */
- public static getParameter(
- uri: string,
- parameter: string,
- default_: string | null = null
- ): string | null {
- const urlParams = new URL(uri).searchParams;
- const res = urlParams.get('page');
- return res ?? default_
- }
- }
- export default Url
|