sussy-util
Version:
Util package made by me
147 lines (146 loc) • 6.46 kB
TypeScript
import MutableObject from '../Types/MutableObject';
declare class UrlUtils {
private static readonly instance;
private constructor();
/**
* If the URL is valid, it will return true, otherwise it will return false.
* @param {string} url - The URL to validate.
* @returns {boolean} A boolean value.
*/
isUrl(url: string): boolean;
/**
* It takes a string and returns a URL object
* @param {string} url - The URL to parse.
* @returns A new URL object.
*/
parseUrl(url: string): URL;
/**
* It takes a URL as a string, and returns the domain name as a string
* @param {string} url - The URL to get the domain name from.
* @returns The hostname of the URL.
*/
getDomainName(url: string): string;
/**
* It takes a URL and returns the pathname of the URL
* @param {string} url - The URL to parse.
* @returns The pathname of the url.
*/
getPath(url: string): string;
/**
* It takes a URL and a set of key-value pairs and returns a new URL with the key-value pairs added
* as query parameters.
* @param {string} url - string - The URL to add the query parameters to.
* @param params - MutableObject<string>
* @returns A string
*/
addQueryParams(url: string, params: MutableObject<string>): string;
/**
* It takes a URL and a query parameter name, and returns the URL with the query parameter removed.
* @param {string} url - The URL to be parsed.
* @param {string} param - The query parameter to remove
* @returns A string
*/
removeQueryParam(url: string, param: string): string;
/**
* It takes a URL and a set of key-value pairs, and returns a new URL with the query parameters
* updated to match the key-value pairs
* @param {string} url - string - The URL to edit
* @param params - MutableObject<string>
* @returns A string
*/
editQueryParams(url: string, params: MutableObject<string>): string;
/**
* It takes a URL and returns an object containing the query parameters as key-value pairs.
* @param {string} url - The URL to extract query parameters from.
* @returns {MutableObject<string>} An object containing the query parameters.
*/
getQueryParams(url: string): MutableObject<string>;
/**
* It takes a URL and a query parameter name, and returns the value of the specified query parameter.
* @param {string} url - The URL to extract the query parameter value from.
* @param {string} param - The query parameter name.
* @returns {string | null} The value of the specified query parameter, or null if it doesn't exist.
*/
getQueryParamValue(url: string, param: string): string | null;
/**
* It takes a URL and a new path, and returns a new URL with the updated path.
* @param {string} url - The URL to update the path for.
* @param {string} newPath - The new path to set.
* @returns {string} The updated URL with the new path.
*/
updatePath(url: string, newPath: string): string;
/**
* It takes a URL and returns a boolean indicating whether it has any query parameters.
* @param {string} url - The URL to check for query parameters.
* @returns {boolean} A boolean value indicating if the URL has query parameters.
*/
hasQueryParams(url: string): boolean;
/**
* Checks if the URL has a specific query parameter.
* @param {string} url - The URL to check.
* @param {string} param - The query parameter name.
* @returns {boolean} True if the parameter exists, false otherwise.
*/
hasQueryParam(url: string, param: string): boolean;
/**
* Appends or updates query parameters from an object to a URL.
* @param {string} url - The URL to update.
* @param {MutableObject<string>} params - The query parameters to append or update.
* @returns {string} The updated URL.
*/
updateQueryParams(url: string, params: MutableObject<string>): string;
/**
* Replaces specified query parameters with new values.
* @param {string} url - The URL to replace query parameters in.
* @param {MutableObject<string>} replacements - The replacements for query parameters.
* @returns {string} The URL with replaced query parameters.
*/
replaceQueryParams(url: string, replacements: MutableObject<string>): string;
/**
* Removes specified query parameters from a URL.
* @param {string} url - The URL to remove query parameters from.
* @param {string[]} paramsToRemove - The names of query parameters to remove.
* @returns {string} The URL with specified query parameters removed.
*/
removeQueryParams(url: string, paramsToRemove: string[]): string;
/**
* Merges query parameters from two URLs, prioritizing parameters from the second URL.
* @param {string} url1 - The first URL.
* @param {string} url2 - The second URL.
* @returns {string} The merged URL with query parameters.
*/
mergeQueryParams(url1: string, url2: string): string;
/**
* It takes a URL and returns the protocol (e.g., 'http:', 'https:').
* @param {string} url - The URL to extract the protocol from.
* @returns {string} The protocol of the URL.
*/
getProtocol(url: string): string;
/**
* It takes a URL and returns the port number as a string.
* @param {string} url - The URL to extract the port from.
* @returns {string} The port number of the URL.
*/
getPort(url: string): string;
/**
* It takes a URL and returns a boolean indicating whether it is an absolute URL.
* @param {string} url - The URL to check.
* @returns {boolean} A boolean value indicating if the URL is absolute.
*/
isAbsoluteUrl(url: string): boolean;
/**
* It takes a string and returns the URL-encoded version.
* @param {string} component - The string to encode.
* @returns {string} The URL-encoded string.
*/
encodeUrlComponent(component: string): string;
/**
* It takes a URL-encoded string and returns the decoded version.
* @param {string} encodedComponent - The URL-encoded string to decode.
* @returns {string} The decoded string.
*/
decodeUrlComponent(encodedComponent: string): string;
static getInstance(): UrlUtils;
}
declare const _default: UrlUtils;
export default _default;