
This is a collection of functions for working with URLs.
The appendSearchParamsToURL function appends the search params to a URL.
import { appendSearchParamsToURL } from '@aracna/core';
// will log "https://dummyjson.com/products?a=0"
console.log(
appendSearchParamsToURL('https://dummyjson.com/products', '?a=0')
);The removeSearchParamsFromURL functions removes the search params from an URL.
import { removeSearchParamsFromURL } from '@aracna/core';
// will log "https://dummyjson.com/products"
console.log(
removeSearchParamsFromURL('https://dummyjson.com/products?a=0')
);The concatURL function concatenates a URL with pathnames.
import { concatURL } from '@aracna/core';
// will log "https://dummyjson.com/products"
console.log(concatURL('https://dummyjson.com/', 'products'));The deserializeURLSearchParams function deserializes an array, string, plain object or URLSearchParams to an array, string or plain object.
import { deserializeURLSearchParams } from '@aracna/core';
// will log "a=0&b=1"
console.log(
deserializeURLSearchParams(
[
['a', '0'],
['b', '1']
],
'string'
)
);
// will log { a: "0", b: "1" }
console.log(deserializeURLSearchParams('?a=0&b=1'));
// will log [["a", "0"], ["b", "1"]]
console.log(deserializeURLSearchParams({ a: '0', b: '1' }, 'array'));The serializeURLSearchParams function serializes an array, string or plain object to URLSearchParams.
import { serializeURLSearchParams } from '@aracna/core';
// will log URLSearchParams
console.log(
serializeURLSearchParams([
['a', '0'],
['b', '1']
])
);
// will log URLSearchParams
console.log(serializeURLSearchParams('?a=0&b=1'));
// will log URLSearchParams
console.log(serializeURLSearchParams({ a: '0', b: '1' }));The isURL function checks if an unknown value is an URL.
import { isURL } from '@aracna/core';
// will log true
console.log(isURL('https://aracna.dariosechi.it'));